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

Side by Side Diff: chrome/browser/extensions/api/system_info/system_info_api.cc

Issue 18290002: [SystemInfo API] Finish TODOs in SystemInfoProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dev_rewrite_storage_info_api
Patch Set: Pass chromeos unit_tests Created 7 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/system_info/system_info_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/extensions/api/system_info/system_info_api.h" 5 #include "chrome/browser/extensions/api/system_info/system_info_api.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 void DispatchStorageAttachedEvent(const chrome::StorageInfo& info, 88 void DispatchStorageAttachedEvent(const chrome::StorageInfo& info,
89 int64 avail_bytes); 89 int64 avail_bytes);
90 90
91 // Called from any thread to dispatch the systemInfo event to all extension 91 // Called from any thread to dispatch the systemInfo event to all extension
92 // processes cross multiple profiles. 92 // processes cross multiple profiles.
93 void DispatchEvent(const std::string& event_name, 93 void DispatchEvent(const std::string& event_name,
94 scoped_ptr<base::ListValue> args); 94 scoped_ptr<base::ListValue> args);
95 95
96 // The callbacks of querying storage info to start and stop watching the 96 // The callbacks of querying storage info to start and stop watching the
97 // storages. Called from UI thread. 97 // storages. Called from UI thread.
98 void StartWatchingStorages(const StorageInfo& info, bool success); 98 void StartWatchingStorages(bool success);
99 void StopWatchingStorages(const StorageInfo& info, bool success); 99 void StopWatchingStorages(bool success);
100 100
101 // Called to dispatch the systemInfo.display.onDisplayChanged event. 101 // Called to dispatch the systemInfo.display.onDisplayChanged event.
102 void OnDisplayChanged(); 102 void OnDisplayChanged();
103 103
104 // Used to record the event names being watched. 104 // Used to record the event names being watched.
105 std::multiset<std::string> watching_event_set_; 105 std::multiset<std::string> watching_event_set_;
106 106
107 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter); 107 DISALLOW_COPY_AND_ASSIGN(SystemInfoEventRouter);
108 }; 108 };
109 109
(...skipping 10 matching lines...) Expand all
120 chrome::StorageMonitor::GetInstance()->AddObserver(this); 120 chrome::StorageMonitor::GetInstance()->AddObserver(this);
121 } 121 }
122 122
123 SystemInfoEventRouter::~SystemInfoEventRouter() { 123 SystemInfoEventRouter::~SystemInfoEventRouter() {
124 StorageInfoProvider::Get()->RemoveObserver(this); 124 StorageInfoProvider::Get()->RemoveObserver(this);
125 if (chrome::StorageMonitor* storage_monitor = 125 if (chrome::StorageMonitor* storage_monitor =
126 chrome::StorageMonitor::GetInstance()) 126 chrome::StorageMonitor::GetInstance())
127 storage_monitor->RemoveObserver(this); 127 storage_monitor->RemoveObserver(this);
128 } 128 }
129 129
130 void SystemInfoEventRouter::StartWatchingStorages( 130 void SystemInfoEventRouter::StartWatchingStorages(bool success) {
131 const StorageInfo& info, bool success) {
132 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
133 if (!success) 132 if (!success)
134 return; 133 return;
135 134
136 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { 135 StorageInfoProvider::Get()->StartWatchingAllStorages();
137 StorageInfoProvider::Get()->StartWatching((*it)->id);
138 }
139 } 136 }
140 137
141 void SystemInfoEventRouter::StopWatchingStorages( 138 void SystemInfoEventRouter::StopWatchingStorages(bool success) {
142 const StorageInfo& info, bool success) {
143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
144 if (!success) 140 if (!success)
145 return; 141 return;
146 142
147 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { 143 StorageInfoProvider::Get()->StopWatchingAllStorages();
148 StorageInfoProvider::Get()->StopWatching((*it)->id);
149 }
150 } 144 }
151 145
152 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { 146 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) {
153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
154 148
155 watching_event_set_.insert(event_name); 149 watching_event_set_.insert(event_name);
156 if (watching_event_set_.count(event_name) > 1) 150 if (watching_event_set_.count(event_name) > 1)
157 return; 151 return;
158 152
159 // Start watching the |event_name| event if the first event listener arrives. 153 // Start watching the |event_name| event if the first event listener arrives.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 306
313 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) { 307 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) {
314 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name); 308 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name);
315 } 309 }
316 310
317 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { 311 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) {
318 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name); 312 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name);
319 } 313 }
320 314
321 } // namespace extensions 315 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/system_info/system_info_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698