1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_
10 #include "base/lazy_instance.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/observer_list_threadsafe.h"
13 #include "base/timer/timer.h"
14 #include "chrome/browser/extensions/api/system_info/system_info_provider.h"
15 #include "chrome/browser/storage_monitor/removable_storage_observer.h"
16 #include "chrome/browser/storage_monitor/storage_info.h"
17 #include "chrome/common/extensions/api/system_storage.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
21 namespace extensions {
23 namespace systeminfo {
25 // Build StorageUnitInfo struct from StorageInfo instance. The |unit|
26 // parameter is the output value.
27 void BuildStorageUnitInfo(const StorageInfo& info,
28 api::system_storage::StorageUnitInfo* unit);
30 } // namespace systeminfo
32 typedef std::vector<linked_ptr<
33 api::system_storage::StorageUnitInfo> >
36 class StorageInfoProvider : public SystemInfoProvider {
38 typedef base::Callback<void(const std::string&, double)>
39 GetStorageFreeSpaceCallback;
41 // Get the single shared instance of StorageInfoProvider.
42 static StorageInfoProvider* Get();
44 // SystemInfoProvider implementations
45 virtual void PrepareQueryOnUIThread() OVERRIDE;
46 virtual void InitializeProvider(const base::Closure& do_query_info_callback)
49 virtual double GetStorageFreeSpaceFromTransientIdOnFileThread(
50 const std::string& transient_id);
52 const StorageUnitInfoList& storage_unit_info_list() const;
54 static void InitializeForTesting(scoped_refptr<StorageInfoProvider> provider);
57 StorageInfoProvider();
59 virtual ~StorageInfoProvider();
61 // Put all available storages' information into |info_|.
62 void GetAllStoragesIntoInfoList();
64 // The last information filled up by QueryInfo and is accessed on multiple
65 // threads, but the whole class is being guarded by SystemInfoProvider base
68 // |info_| is accessed on the UI thread while |is_waiting_for_completion_| is
69 // false and on the sequenced worker pool while |is_waiting_for_completion_|
71 StorageUnitInfoList info_;
74 // SystemInfoProvider implementations.
75 // Override to query the available capacity of all known storage devices on
76 // the blocking pool, including fixed and removable devices.
77 virtual bool QueryInfo() OVERRIDE;
79 static base::LazyInstance<scoped_refptr<StorageInfoProvider> > provider_;
81 DISALLOW_COPY_AND_ASSIGN(StorageInfoProvider);
84 } // namespace extensions
86 #endif // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_