Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/extensions/system_info_event_router.h

Issue 12084017: [SystemInfo API] Implement systemInfo.storage.onAvailableCapacityChanged event (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
6 #define CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ 6 #define CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
7 7
8 #include <set> 8 #include <set>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/api/system_info_storage/storage_info_observe r.h"
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 namespace api { 17 namespace api {
17 18
18 namespace experimental_system_info_cpu { 19 namespace experimental_system_info_cpu {
19 20
20 struct CpuUpdateInfo; 21 struct CpuUpdateInfo;
21 22
22 } // namespace experimental_system_info_cpu 23 } // namespace experimental_system_info_cpu
23 24
24 } // namespace api 25 } // namespace api
25 26
26 // Event router for systemInfo API. It is a singleton instance shared by 27 // Event router for systemInfo API. It is a singleton instance shared by
27 // multiple profiles. 28 // multiple profiles.
28 // TODO(hongbo): It should derive from SystemMonitor::DevicesChangedObserver. 29 // TODO(hongbo): It should derive from SystemMonitor::DevicesChangedObserver.
29 // Since the system_monitor will be refactored along with media_gallery, once 30 // Since the system_monitor will be refactored along with media_gallery, once
30 // http://crbug.com/145400 is fixed, we need to update SystemInfoEventRouter 31 // http://crbug.com/145400 is fixed, we need to update SystemInfoEventRouter
31 // accordingly. 32 // accordingly.
32 class SystemInfoEventRouter { 33 class SystemInfoEventRouter : public StorageInfoObserver {
33 public: 34 public:
34 static SystemInfoEventRouter* GetInstance(); 35 static SystemInfoEventRouter* GetInstance();
35 36
36 // Add/remove event listener for the |event_name| event from |profile|. 37 // Add/remove event listener for the |event_name| event from |profile|.
37 void AddEventListener(const std::string& event_name); 38 void AddEventListener(const std::string& event_name);
38 void RemoveEventListener(const std::string& event_name); 39 void RemoveEventListener(const std::string& event_name);
39 40
40 // Return true if the |event_name| is an event from systemInfo namespace. 41 // Return true if the |event_name| is an event from systemInfo namespace.
41 static bool IsSystemInfoEvent(const std::string& event_name); 42 static bool IsSystemInfoEvent(const std::string& event_name);
42 43
44 // StorageInfoObserver implementation:
45 virtual void OnStorageFreeSpaceChanged(const std::string& id,
46 double new_value,
47 double old_value);
48
43 // TODO(hongbo): The following methods should be likely overriden from 49 // TODO(hongbo): The following methods should be likely overriden from
44 // SystemMonitor::DevicesChangedObserver once the http://crbug.com/145400 50 // SystemMonitor::DevicesChangedObserver once the http://crbug.com/145400
45 // is fixed. 51 // is fixed.
46 void OnStorageAvailableCapacityChanged(const std::string& id,
47 int64 available_capacity);
48 void OnRemovableStorageAttached(const std::string& id, 52 void OnRemovableStorageAttached(const std::string& id,
49 const string16& name, 53 const string16& name,
50 const FilePath::StringType& location); 54 const FilePath::StringType& location);
51 void OnRemovableStorageDetached(const std::string& id); 55 void OnRemovableStorageDetached(const std::string& id);
52 56
53 private: 57 private:
54 friend struct DefaultSingletonTraits<SystemInfoEventRouter>; 58 friend struct DefaultSingletonTraits<SystemInfoEventRouter>;
55 59
56 SystemInfoEventRouter(); 60 SystemInfoEventRouter();
57 virtual ~SystemInfoEventRouter(); 61 virtual ~SystemInfoEventRouter();
58 62
59 // Called from any thread to dispatch the systemInfo event to all extension 63 // Called from any thread to dispatch the systemInfo event to all extension
60 // processes cross multiple profiles. 64 // processes cross multiple profiles.
61 void DispatchEvent(const std::string& event_name, 65 void DispatchEvent(const std::string& event_name,
62 scoped_ptr<base::ListValue> args); 66 scoped_ptr<base::ListValue> args);
63 67
64 // The callback for CPU sampling cycle. Called from FILE thread. 68 // The callback for CPU sampling cycle. Called from FILE thread.
65 void OnNextCpuSampling( 69 void OnNextCpuSampling(
66 scoped_ptr<api::experimental_system_info_cpu::CpuUpdateInfo> info); 70 scoped_ptr<api::experimental_system_info_cpu::CpuUpdateInfo> info);
67 71
68 // Used to record the event names being watched. 72 // Used to record the event names being watched.
69 std::multiset<std::string> watching_event_set_; 73 std::multiset<std::string> watching_event_set_;
70 74
71 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); 75 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter);
72 }; 76 };
73 77
74 } // namespace extensions 78 } // namespace extensions
75 79
76 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ 80 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698