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

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: Add a stub file to pass building on Android 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_provide r.h"
13 #include "ui/gfx/display_observer.h" 14 #include "ui/gfx/display_observer.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 namespace api { 18 namespace api {
18 19
19 namespace experimental_system_info_cpu { 20 namespace experimental_system_info_cpu {
20 21
21 struct CpuUpdateInfo; 22 struct CpuUpdateInfo;
22 23
23 } // namespace experimental_system_info_cpu 24 } // namespace experimental_system_info_cpu
24 25
25 } // namespace api 26 } // namespace api
26 27
27 // Event router for systemInfo API. It is a singleton instance shared by 28 // Event router for systemInfo API. It is a singleton instance shared by
28 // multiple profiles. 29 // multiple profiles.
29 // TODO(hongbo): It should derive from SystemMonitor::DevicesChangedObserver. 30 // TODO(hongbo): It should derive from SystemMonitor::DevicesChangedObserver.
30 // Since the system_monitor will be refactored along with media_gallery, once 31 // Since the system_monitor will be refactored along with media_gallery, once
31 // http://crbug.com/145400 is fixed, we need to update SystemInfoEventRouter 32 // http://crbug.com/145400 is fixed, we need to update SystemInfoEventRouter
32 // accordingly. 33 // accordingly.
33 class SystemInfoEventRouter: public gfx::DisplayObserver { 34 class SystemInfoEventRouter
35 : public gfx::DisplayObserver,
36 public StorageInfoObserver {
34 public: 37 public:
35 static SystemInfoEventRouter* GetInstance(); 38 static SystemInfoEventRouter* GetInstance();
36 39
37 // Add/remove event listener for the |event_name| event from |profile|. 40 // Add/remove event listener for the |event_name| event from |profile|.
38 void AddEventListener(const std::string& event_name); 41 void AddEventListener(const std::string& event_name);
39 void RemoveEventListener(const std::string& event_name); 42 void RemoveEventListener(const std::string& event_name);
40 43
41 // Return true if the |event_name| is an event from systemInfo namespace. 44 // Return true if the |event_name| is an event from systemInfo namespace.
42 static bool IsSystemInfoEvent(const std::string& event_name); 45 static bool IsSystemInfoEvent(const std::string& event_name);
43 46
47 // StorageInfoObserver implementation:
48 virtual void OnStorageFreeSpaceChanged(const std::string& id,
49 double new_value,
50 double old_value) OVERRIDE;
51
44 // TODO(hongbo): The following methods should be likely overriden from 52 // TODO(hongbo): The following methods should be likely overriden from
45 // SystemMonitor::DevicesChangedObserver once the http://crbug.com/145400 53 // SystemMonitor::DevicesChangedObserver once the http://crbug.com/145400
46 // is fixed. 54 // is fixed.
47 void OnStorageAvailableCapacityChanged(const std::string& id,
48 int64 available_capacity);
49 void OnRemovableStorageAttached(const std::string& id, 55 void OnRemovableStorageAttached(const std::string& id,
50 const string16& name, 56 const string16& name,
51 const FilePath::StringType& location); 57 const FilePath::StringType& location);
52 void OnRemovableStorageDetached(const std::string& id); 58 void OnRemovableStorageDetached(const std::string& id);
53 59
54 // gfx::DisplayObserver implementation. 60 // gfx::DisplayObserver implementation.
55 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; 61 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE;
56 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; 62 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE;
57 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; 63 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE;
58 64
59 private: 65 private:
60 friend struct DefaultSingletonTraits<SystemInfoEventRouter>; 66 friend struct DefaultSingletonTraits<SystemInfoEventRouter>;
61 67
62 SystemInfoEventRouter(); 68 SystemInfoEventRouter();
63 virtual ~SystemInfoEventRouter(); 69 virtual ~SystemInfoEventRouter();
64 70
65 // Called from any thread to dispatch the systemInfo event to all extension 71 // Called from any thread to dispatch the systemInfo event to all extension
66 // processes cross multiple profiles. 72 // processes cross multiple profiles.
67 void DispatchEvent(const std::string& event_name, 73 void DispatchEvent(const std::string& event_name,
68 scoped_ptr<base::ListValue> args); 74 scoped_ptr<base::ListValue> args);
69 75
76 // The callbacks of querying storage info to start and stop watching the
77 // storages. Called from UI thread.
78 void StartWatchingStorages(const StorageInfo& info, bool success);
79 void StopWatchingStorages(const StorageInfo& info, bool success);
80
70 // The callback for CPU sampling cycle. Called from FILE thread. 81 // The callback for CPU sampling cycle. Called from FILE thread.
71 void OnNextCpuSampling( 82 void OnNextCpuSampling(
72 scoped_ptr<api::experimental_system_info_cpu::CpuUpdateInfo> info); 83 scoped_ptr<api::experimental_system_info_cpu::CpuUpdateInfo> info);
73 84
74 // Called to dispatch the systemInfo.display.onDisplayChanged event. 85 // Called to dispatch the systemInfo.display.onDisplayChanged event.
75 void OnDisplayChanged(); 86 void OnDisplayChanged();
76 87
77 // Used to record the event names being watched. 88 // Used to record the event names being watched.
78 std::multiset<std::string> watching_event_set_; 89 std::multiset<std::string> watching_event_set_;
79 90
80 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); 91 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter);
81 }; 92 };
82 93
83 } // namespace extensions 94 } // namespace extensions
84 95
85 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_ 96 #endif // CHROME_BROWSER_EXTENSIONS_SYSTEM_INFO_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698