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

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: 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
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
110 static base::LazyInstance<SystemInfoEventRouter>::Leaky 110 static base::LazyInstance<SystemInfoEventRouter>::Leaky
111 g_system_info_event_router = LAZY_INSTANCE_INITIALIZER; 111 g_system_info_event_router = LAZY_INSTANCE_INITIALIZER;
112 112
113 // static 113 // static
114 SystemInfoEventRouter* SystemInfoEventRouter::GetInstance() { 114 SystemInfoEventRouter* SystemInfoEventRouter::GetInstance() {
115 return g_system_info_event_router.Pointer(); 115 return g_system_info_event_router.Pointer();
116 } 116 }
117 117
118 SystemInfoEventRouter::SystemInfoEventRouter() { 118 SystemInfoEventRouter::SystemInfoEventRouter() {
119 StorageInfoProvider::Get()->AddObserver(this); 119 StorageInfoProvider::Get()->AddObserver(this);
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::GetInstance()) 125 if (chrome::StorageMonitor::GetInstance())
126 chrome::StorageMonitor::GetInstance()->RemoveObserver(this); 126 chrome::StorageMonitor::GetInstance()->RemoveObserver(this);
127 } 127 }
128 128
129 void SystemInfoEventRouter::StartWatchingStorages( 129 void SystemInfoEventRouter::StartWatchingStorages(bool success) {
130 const StorageInfo& info, bool success) {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
132 if (!success) 131 if (!success)
133 return; 132 return;
134 133
135 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { 134 const StorageInfo* info = StorageInfoProvider::Get()->storage_info();
135 for (StorageInfo::const_iterator it = info->begin();
136 it != info->end(); ++it) {
136 StorageInfoProvider::Get()->StartWatching((*it)->id); 137 StorageInfoProvider::Get()->StartWatching((*it)->id);
137 } 138 }
138 } 139 }
139 140
140 void SystemInfoEventRouter::StopWatchingStorages( 141 void SystemInfoEventRouter::StopWatchingStorages(bool success) {
141 const StorageInfo& info, bool success) {
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
143 if (!success) 143 if (!success)
144 return; 144 return;
145 145
146 for (StorageInfo::const_iterator it = info.begin(); it != info.end(); ++it) { 146 const StorageInfo* info = StorageInfoProvider::Get()->storage_info();
147 for (StorageInfo::const_iterator it = info->begin();
148 it != info->end(); ++it) {
147 StorageInfoProvider::Get()->StopWatching((*it)->id); 149 StorageInfoProvider::Get()->StopWatching((*it)->id);
148 } 150 }
149 } 151 }
150 152
151 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) { 153 void SystemInfoEventRouter::AddEventListener(const std::string& event_name) {
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
153 155
154 watching_event_set_.insert(event_name); 156 watching_event_set_.insert(event_name);
155 if (watching_event_set_.count(event_name) > 1) 157 if (watching_event_set_.count(event_name) > 1)
156 return; 158 return;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 310
309 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) { 311 void SystemInfoAPI::OnListenerAdded(const EventListenerInfo& details) {
310 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name); 312 SystemInfoEventRouter::GetInstance()->AddEventListener(details.event_name);
311 } 313 }
312 314
313 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { 315 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) {
314 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name); 316 SystemInfoEventRouter::GetInstance()->RemoveEventListener(details.event_name);
315 } 317 }
316 318
317 } // namespace extensions 319 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698