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

Side by Side Diff: chrome/browser/extensions/event_router.cc

Issue 12375006: Added UMA stats for extensions events on addListener. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 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 #include "chrome/browser/extensions/event_router.h" 5 #include "chrome/browser/extensions/event_router.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/metrics/histogram.h"
12 #include "base/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "base/version.h" 15 #include "base/version.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/extensions/activity_log.h" 17 #include "chrome/browser/extensions/activity_log.h"
17 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 18 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
18 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 19 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
19 #include "chrome/browser/extensions/event_names.h" 20 #include "chrome/browser/extensions/event_names.h"
20 #include "chrome/browser/extensions/extension_host.h" 21 #include "chrome/browser/extensions/extension_host.h"
21 #include "chrome/browser/extensions/extension_prefs.h" 22 #include "chrome/browser/extensions/extension_prefs.h"
22 #include "chrome/browser/extensions/extension_process_manager.h" 23 #include "chrome/browser/extensions/extension_process_manager.h"
23 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/extensions/extension_system.h" 25 #include "chrome/browser/extensions/extension_system.h"
25 #include "chrome/browser/extensions/lazy_background_task_queue.h" 26 #include "chrome/browser/extensions/lazy_background_task_queue.h"
26 #include "chrome/browser/extensions/process_map.h" 27 #include "chrome/browser/extensions/process_map.h"
27 #include "chrome/browser/extensions/system_info_event_router.h" 28 #include "chrome/browser/extensions/system_info_event_router.h"
28 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/profiles/profile_manager.h" 30 #include "chrome/browser/profiles/profile_manager.h"
30 #include "chrome/common/chrome_notification_types.h" 31 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/extensions/api/extension_api.h" 33 #include "chrome/common/extensions/api/extension_api.h"
34 #include "chrome/common/extensions/api/generated_api.h"
33 #include "chrome/common/extensions/extension.h" 35 #include "chrome/common/extensions/extension.h"
34 #include "chrome/common/extensions/extension_messages.h" 36 #include "chrome/common/extensions/extension_messages.h"
35 #include "chrome/common/view_type.h" 37 #include "chrome/common/view_type.h"
36 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
37 #include "content/public/browser/render_process_host.h" 39 #include "content/public/browser/render_process_host.h"
38 40
39 using base::Value; 41 using base::Value;
40 using content::BrowserThread; 42 using content::BrowserThread;
41 43
42 namespace extensions { 44 namespace extensions {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 content::Source<Profile>(profile_)); 181 content::Source<Profile>(profile_));
180 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED, 182 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_ENABLED,
181 content::Source<Profile>(profile_)); 183 content::Source<Profile>(profile_));
182 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 184 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
183 content::Source<Profile>(profile_)); 185 content::Source<Profile>(profile_));
184 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 186 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
185 content::Source<Profile>(profile_)); 187 content::Source<Profile>(profile_));
186 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, 188 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED,
187 content::Source<Profile>(profile_)); 189 content::Source<Profile>(profile_));
188 190
191 extensions::api::GeneratedEventHistogramMap::
192 AddAll(histogram_values_);
193
189 // NULL in unit_tests. 194 // NULL in unit_tests.
190 if (extension_prefs) { 195 if (extension_prefs) {
191 // Check if registered events are up-to-date. We need to do this before 196 // Check if registered events are up-to-date. We need to do this before
192 // reading the registered events, because it deletes them if they're out of 197 // reading the registered events, because it deletes them if they're out of
193 // date. 198 // date.
194 dispatch_chrome_updated_event_ = 199 dispatch_chrome_updated_event_ =
195 !extension_prefs->CheckRegisteredEventsUpToDate(); 200 !extension_prefs->CheckRegisteredEventsUpToDate();
196 } 201 }
197 } 202 }
198 203
199 EventRouter::~EventRouter() {} 204 EventRouter::~EventRouter() {}
200 205
201 void EventRouter::AddEventListener(const std::string& event_name, 206 void EventRouter::AddEventListener(const std::string& event_name,
202 content::RenderProcessHost* process, 207 content::RenderProcessHost* process,
203 const std::string& extension_id) { 208 const std::string& extension_id) {
204 listeners_.AddListener(scoped_ptr<EventListener>(new EventListener( 209 listeners_.AddListener(scoped_ptr<EventListener>(new EventListener(
205 event_name, extension_id, process, scoped_ptr<DictionaryValue>()))); 210 event_name, extension_id, process, scoped_ptr<DictionaryValue>())));
211 RecordEventListenerAdded(event_name);
koz (OOO until 15th September) 2013/03/13 01:00:27 This might be trickier than it seems. Extensions /
206 } 212 }
207 213
208 void EventRouter::RemoveEventListener(const std::string& event_name, 214 void EventRouter::RemoveEventListener(const std::string& event_name,
209 content::RenderProcessHost* process, 215 content::RenderProcessHost* process,
210 const std::string& extension_id) { 216 const std::string& extension_id) {
211 EventListener listener(event_name, extension_id, process, 217 EventListener listener(event_name, extension_id, process,
212 scoped_ptr<DictionaryValue>()); 218 scoped_ptr<DictionaryValue>());
213 listeners_.RemoveListener(&listener); 219 listeners_.RemoveListener(&listener);
214 } 220 }
215 221
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 if (did_exist) { 311 if (did_exist) {
306 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)-> 312 ExtensionPrefs* prefs = extensions::ExtensionSystem::Get(profile_)->
307 extension_service()->extension_prefs(); 313 extension_service()->extension_prefs();
308 std::set<std::string> events = prefs->GetRegisteredEvents(extension_id); 314 std::set<std::string> events = prefs->GetRegisteredEvents(extension_id);
309 bool prefs_did_exist = events.erase(event_name) > 0; 315 bool prefs_did_exist = events.erase(event_name) > 0;
310 DCHECK(prefs_did_exist); 316 DCHECK(prefs_did_exist);
311 prefs->SetRegisteredEvents(extension_id, events); 317 prefs->SetRegisteredEvents(extension_id, events);
312 } 318 }
313 } 319 }
314 320
315 void EventRouter::AddFilteredEventListener(const std::string& event_name, 321 void EventRouter::AddFilteredEventListener(const std::string& event_name,
koz (OOO until 15th September) 2013/03/13 01:00:27 You'll need to record filtered event listeners bei
316 content::RenderProcessHost* process, 322 content::RenderProcessHost* process,
317 const std::string& extension_id, 323 const std::string& extension_id,
318 const base::DictionaryValue& filter, 324 const base::DictionaryValue& filter,
319 bool add_lazy_listener) { 325 bool add_lazy_listener) {
320 listeners_.AddListener(scoped_ptr<EventListener>(new EventListener( 326 listeners_.AddListener(scoped_ptr<EventListener>(new EventListener(
321 event_name, extension_id, process, 327 event_name, extension_id, process,
322 scoped_ptr<DictionaryValue>(filter.DeepCopy())))); 328 scoped_ptr<DictionaryValue>(filter.DeepCopy()))));
323 329
324 if (add_lazy_listener) { 330 if (add_lazy_listener) {
325 bool added = listeners_.AddListener(scoped_ptr<EventListener>( 331 bool added = listeners_.AddListener(scoped_ptr<EventListener>(
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 if (!host) 591 if (!host)
586 return; 592 return;
587 593
588 if (listeners_.HasProcessListener(host->render_process_host(), 594 if (listeners_.HasProcessListener(host->render_process_host(),
589 host->extension()->id())) { 595 host->extension()->id())) {
590 DispatchEventToProcess(host->extension()->id(), 596 DispatchEventToProcess(host->extension()->id(),
591 host->render_process_host(), event); 597 host->render_process_host(), event);
592 } 598 }
593 } 599 }
594 600
601 void EventRouter::RecordEventListenerAdded(const std::string& event_name) {
602 UMA_HISTOGRAM_ENUMERATION("Extensions.AddEventListener",
603 histogram_values_[event_name], extensions::events::ENUM_BOUNDARY);
604 }
605
595 void EventRouter::Observe(int type, 606 void EventRouter::Observe(int type,
596 const content::NotificationSource& source, 607 const content::NotificationSource& source,
597 const content::NotificationDetails& details) { 608 const content::NotificationDetails& details) {
598 switch (type) { 609 switch (type) {
599 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: 610 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
600 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: { 611 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
601 content::RenderProcessHost* renderer = 612 content::RenderProcessHost* renderer =
602 content::Source<content::RenderProcessHost>(source).ptr(); 613 content::Source<content::RenderProcessHost>(source).ptr();
603 // Remove all event listeners associated with this renderer. 614 // Remove all event listeners associated with this renderer.
604 listeners_.RemoveListenersForProcess(renderer); 615 listeners_.RemoveListenersForProcess(renderer);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 copy->will_dispatch_callback = will_dispatch_callback; 731 copy->will_dispatch_callback = will_dispatch_callback;
721 return copy; 732 return copy;
722 } 733 }
723 734
724 EventListenerInfo::EventListenerInfo(const std::string& event_name, 735 EventListenerInfo::EventListenerInfo(const std::string& event_name,
725 const std::string& extension_id) 736 const std::string& extension_id)
726 : event_name(event_name), 737 : event_name(event_name),
727 extension_id(extension_id) {} 738 extension_id(extension_id) {}
728 739
729 } // namespace extensions 740 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/event_router.h ('k') | chrome/browser/extensions/extension_event_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698