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 EXTENSIONS_BROWSER_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_
6 #define EXTENSIONS_BROWSER_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 "extensions/browser/api/system_info/system_info_provider.h"
15 #include "extensions/common/api/system_storage.h"
17 namespace storage_monitor {
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 storage_monitor::StorageInfo& info,
28 core_api::system_storage::StorageUnitInfo* unit);
30 } // namespace systeminfo
32 typedef std::vector<linked_ptr<core_api::system_storage::StorageUnitInfo> >
35 class StorageInfoProvider : public SystemInfoProvider {
37 typedef base::Callback<void(const std::string&, double)>
38 GetStorageFreeSpaceCallback;
40 // Get the single shared instance of StorageInfoProvider.
41 static StorageInfoProvider* Get();
43 // SystemInfoProvider implementations
44 virtual void PrepareQueryOnUIThread() OVERRIDE;
45 virtual void InitializeProvider(
46 const base::Closure& do_query_info_callback) OVERRIDE;
48 virtual double GetStorageFreeSpaceFromTransientIdOnFileThread(
49 const std::string& transient_id);
51 const StorageUnitInfoList& storage_unit_info_list() const;
53 static void InitializeForTesting(scoped_refptr<StorageInfoProvider> provider);
56 StorageInfoProvider();
58 virtual ~StorageInfoProvider();
60 // Put all available storages' information into |info_|.
61 void GetAllStoragesIntoInfoList();
63 // The last information filled up by QueryInfo and is accessed on multiple
64 // threads, but the whole class is being guarded by SystemInfoProvider base
67 // |info_| is accessed on the UI thread while |is_waiting_for_completion_| is
68 // false and on the sequenced worker pool while |is_waiting_for_completion_|
70 StorageUnitInfoList info_;
73 // SystemInfoProvider implementations.
74 // Override to query the available capacity of all known storage devices on
75 // the blocking pool, including fixed and removable devices.
76 virtual bool QueryInfo() OVERRIDE;
78 static base::LazyInstance<scoped_refptr<StorageInfoProvider> > provider_;
80 DISALLOW_COPY_AND_ASSIGN(StorageInfoProvider);
83 } // namespace extensions
85 #endif // EXTENSIONS_BROWSER_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_