Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / system_storage / storage_info_provider.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_
7
8 #include <set>
9
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/common/extensions/api/system_storage.h"
16 #include "components/storage_monitor/storage_info.h"
17
18 namespace extensions {
19
20 namespace systeminfo {
21
22 // Build StorageUnitInfo struct from StorageInfo instance. The |unit|
23 // parameter is the output value.
24 void BuildStorageUnitInfo(const StorageInfo& info,
25                           api::system_storage::StorageUnitInfo* unit);
26
27 }  // namespace systeminfo
28
29 typedef std::vector<linked_ptr<
30     api::system_storage::StorageUnitInfo> >
31         StorageUnitInfoList;
32
33 class StorageInfoProvider : public SystemInfoProvider {
34  public:
35   typedef base::Callback<void(const std::string&, double)>
36       GetStorageFreeSpaceCallback;
37
38   // Get the single shared instance of StorageInfoProvider.
39   static StorageInfoProvider* Get();
40
41   // SystemInfoProvider implementations
42   virtual void PrepareQueryOnUIThread() OVERRIDE;
43   virtual void InitializeProvider(const base::Closure& do_query_info_callback)
44       OVERRIDE;
45
46   virtual double GetStorageFreeSpaceFromTransientIdOnFileThread(
47       const std::string& transient_id);
48
49   const StorageUnitInfoList& storage_unit_info_list() const;
50
51   static void InitializeForTesting(scoped_refptr<StorageInfoProvider> provider);
52
53  protected:
54   StorageInfoProvider();
55
56   virtual ~StorageInfoProvider();
57
58   // Put all available storages' information into |info_|.
59   void GetAllStoragesIntoInfoList();
60
61   // The last information filled up by QueryInfo and is accessed on multiple
62   // threads, but the whole class is being guarded by SystemInfoProvider base
63   // class.
64   //
65   // |info_| is accessed on the UI thread while |is_waiting_for_completion_| is
66   // false and on the sequenced worker pool while |is_waiting_for_completion_|
67   // is true.
68   StorageUnitInfoList info_;
69
70  private:
71   // SystemInfoProvider implementations.
72   // Override to query the available capacity of all known storage devices on
73   // the blocking pool, including fixed and removable devices.
74   virtual bool QueryInfo() OVERRIDE;
75
76   static base::LazyInstance<scoped_refptr<StorageInfoProvider> > provider_;
77
78   DISALLOW_COPY_AND_ASSIGN(StorageInfoProvider);
79 };
80
81 }  // namespace extensions
82
83 #endif  // CHROME_BROWSER_EXTENSIONS_API_SYSTEM_STORAGE_STORAGE_INFO_PROVIDER_H_