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

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

Issue 1236493004: Final batch adding real histogram values for extension events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments, rebase, dcheck, etc Created 5 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 "extensions/browser/api/system_info/system_info_api.h" 5 #include "extensions/browser/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/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 uint32_t metrics) override; 66 uint32_t metrics) override;
67 67
68 // RemovableStorageObserver implementation. 68 // RemovableStorageObserver implementation.
69 void OnRemovableStorageAttached( 69 void OnRemovableStorageAttached(
70 const storage_monitor::StorageInfo& info) override; 70 const storage_monitor::StorageInfo& info) override;
71 void OnRemovableStorageDetached( 71 void OnRemovableStorageDetached(
72 const storage_monitor::StorageInfo& info) override; 72 const storage_monitor::StorageInfo& info) override;
73 73
74 // Called from any thread to dispatch the systemInfo event to all extension 74 // Called from any thread to dispatch the systemInfo event to all extension
75 // processes cross multiple profiles. 75 // processes cross multiple profiles.
76 void DispatchEvent(const std::string& event_name, 76 void DispatchEvent(events::HistogramValue histogram_value,
77 const std::string& event_name,
77 scoped_ptr<base::ListValue> args); 78 scoped_ptr<base::ListValue> args);
78 79
79 // Called to dispatch the systemInfo.display.onDisplayChanged event. 80 // Called to dispatch the systemInfo.display.onDisplayChanged event.
80 void OnDisplayChanged(); 81 void OnDisplayChanged();
81 82
82 // Used to record the event names being watched. 83 // Used to record the event names being watched.
83 std::multiset<std::string> watching_event_set_; 84 std::multiset<std::string> watching_event_set_;
84 85
85 bool has_storage_monitor_observer_; 86 bool has_storage_monitor_observer_;
86 87
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 158 }
158 } 159 }
159 } 160 }
160 161
161 void SystemInfoEventRouter::OnRemovableStorageAttached( 162 void SystemInfoEventRouter::OnRemovableStorageAttached(
162 const storage_monitor::StorageInfo& info) { 163 const storage_monitor::StorageInfo& info) {
163 StorageUnitInfo unit; 164 StorageUnitInfo unit;
164 systeminfo::BuildStorageUnitInfo(info, &unit); 165 systeminfo::BuildStorageUnitInfo(info, &unit);
165 scoped_ptr<base::ListValue> args(new base::ListValue); 166 scoped_ptr<base::ListValue> args(new base::ListValue);
166 args->Append(unit.ToValue().release()); 167 args->Append(unit.ToValue().release());
167 DispatchEvent(system_storage::OnAttached::kEventName, args.Pass()); 168 DispatchEvent(events::SYSTEM_STORAGE_ON_ATTACHED,
169 system_storage::OnAttached::kEventName, args.Pass());
168 } 170 }
169 171
170 void SystemInfoEventRouter::OnRemovableStorageDetached( 172 void SystemInfoEventRouter::OnRemovableStorageDetached(
171 const storage_monitor::StorageInfo& info) { 173 const storage_monitor::StorageInfo& info) {
172 scoped_ptr<base::ListValue> args(new base::ListValue); 174 scoped_ptr<base::ListValue> args(new base::ListValue);
173 std::string transient_id = 175 std::string transient_id =
174 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( 176 StorageMonitor::GetInstance()->GetTransientIdForDeviceId(
175 info.device_id()); 177 info.device_id());
176 args->AppendString(transient_id); 178 args->AppendString(transient_id);
177 179
178 DispatchEvent(system_storage::OnDetached::kEventName, args.Pass()); 180 DispatchEvent(events::SYSTEM_STORAGE_ON_DETACHED,
181 system_storage::OnDetached::kEventName, args.Pass());
179 } 182 }
180 183
181 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) { 184 void SystemInfoEventRouter::OnDisplayAdded(const gfx::Display& new_display) {
182 OnDisplayChanged(); 185 OnDisplayChanged();
183 } 186 }
184 187
185 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) { 188 void SystemInfoEventRouter::OnDisplayRemoved(const gfx::Display& old_display) {
186 OnDisplayChanged(); 189 OnDisplayChanged();
187 } 190 }
188 191
189 void SystemInfoEventRouter::OnDisplayMetricsChanged(const gfx::Display& display, 192 void SystemInfoEventRouter::OnDisplayMetricsChanged(const gfx::Display& display,
190 uint32_t metrics) { 193 uint32_t metrics) {
191 OnDisplayChanged(); 194 OnDisplayChanged();
192 } 195 }
193 196
194 void SystemInfoEventRouter::OnDisplayChanged() { 197 void SystemInfoEventRouter::OnDisplayChanged() {
195 scoped_ptr<base::ListValue> args(new base::ListValue()); 198 scoped_ptr<base::ListValue> args(new base::ListValue());
196 DispatchEvent(system_display::OnDisplayChanged::kEventName, args.Pass()); 199 DispatchEvent(events::SYSTEM_DISPLAY_ON_DISPLAY_CHANGED,
200 system_display::OnDisplayChanged::kEventName, args.Pass());
197 } 201 }
198 202
199 void SystemInfoEventRouter::DispatchEvent(const std::string& event_name, 203 void SystemInfoEventRouter::DispatchEvent(
200 scoped_ptr<base::ListValue> args) { 204 events::HistogramValue histogram_value,
201 ExtensionsBrowserClient::Get()->BroadcastEventToRenderers(event_name, 205 const std::string& event_name,
202 args.Pass()); 206 scoped_ptr<base::ListValue> args) {
207 ExtensionsBrowserClient::Get()->BroadcastEventToRenderers(
208 histogram_value, event_name, args.Pass());
203 } 209 }
204 210
205 void AddEventListener(const std::string& event_name) { 211 void AddEventListener(const std::string& event_name) {
206 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name); 212 SystemInfoEventRouter::GetInstance()->AddEventListener(event_name);
207 } 213 }
208 214
209 void RemoveEventListener(const std::string& event_name) { 215 void RemoveEventListener(const std::string& event_name) {
210 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name); 216 SystemInfoEventRouter::GetInstance()->RemoveEventListener(event_name);
211 } 217 }
212 218
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) { 254 void SystemInfoAPI::OnListenerRemoved(const EventListenerInfo& details) {
249 if (IsSystemStorageEvent(details.event_name)) { 255 if (IsSystemStorageEvent(details.event_name)) {
250 StorageMonitor::GetInstance()->EnsureInitialized( 256 StorageMonitor::GetInstance()->EnsureInitialized(
251 base::Bind(&RemoveEventListener, details.event_name)); 257 base::Bind(&RemoveEventListener, details.event_name));
252 } else { 258 } else {
253 RemoveEventListener(details.event_name); 259 RemoveEventListener(details.event_name);
254 } 260 }
255 } 261 }
256 262
257 } // namespace extensions 263 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698