OLD | NEW |
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_forwarder.h" | 5 #include "chrome/browser/extensions/event_router_forwarder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "extensions/browser/event_router.h" | 12 #include "extensions/browser/event_router.h" |
13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
14 | 14 |
15 using content::BrowserThread; | 15 using content::BrowserThread; |
16 | 16 |
17 namespace extensions { | 17 namespace extensions { |
18 | 18 |
19 EventRouterForwarder::EventRouterForwarder() { | 19 EventRouterForwarder::EventRouterForwarder() { |
20 } | 20 } |
21 | 21 |
22 EventRouterForwarder::~EventRouterForwarder() { | 22 EventRouterForwarder::~EventRouterForwarder() { |
23 } | 23 } |
24 | 24 |
25 void EventRouterForwarder::BroadcastEventToRenderers( | 25 void EventRouterForwarder::BroadcastEventToRenderers( |
| 26 events::HistogramValue histogram_value, |
26 const std::string& event_name, | 27 const std::string& event_name, |
27 scoped_ptr<base::ListValue> event_args, | 28 scoped_ptr<base::ListValue> event_args, |
28 const GURL& event_url) { | 29 const GURL& event_url) { |
29 HandleEvent(std::string(), event_name, event_args.Pass(), 0, true, event_url); | 30 HandleEvent(std::string(), histogram_value, event_name, event_args.Pass(), 0, |
| 31 true, event_url); |
30 } | 32 } |
31 | 33 |
32 void EventRouterForwarder::DispatchEventToRenderers( | 34 void EventRouterForwarder::DispatchEventToRenderers( |
| 35 events::HistogramValue histogram_value, |
33 const std::string& event_name, | 36 const std::string& event_name, |
34 scoped_ptr<base::ListValue> event_args, | 37 scoped_ptr<base::ListValue> event_args, |
35 void* profile, | 38 void* profile, |
36 bool use_profile_to_restrict_events, | 39 bool use_profile_to_restrict_events, |
37 const GURL& event_url) { | 40 const GURL& event_url) { |
38 if (!profile) | 41 if (!profile) |
39 return; | 42 return; |
40 HandleEvent(std::string(), | 43 HandleEvent(std::string(), histogram_value, event_name, event_args.Pass(), |
41 event_name, | 44 profile, use_profile_to_restrict_events, event_url); |
42 event_args.Pass(), | |
43 profile, | |
44 use_profile_to_restrict_events, | |
45 event_url); | |
46 } | 45 } |
47 | 46 |
48 void EventRouterForwarder::BroadcastEventToExtension( | 47 void EventRouterForwarder::BroadcastEventToExtension( |
49 const std::string& extension_id, | 48 const std::string& extension_id, |
| 49 events::HistogramValue histogram_value, |
50 const std::string& event_name, | 50 const std::string& event_name, |
51 scoped_ptr<base::ListValue> event_args, | 51 scoped_ptr<base::ListValue> event_args, |
52 const GURL& event_url) { | 52 const GURL& event_url) { |
53 HandleEvent(extension_id, event_name, event_args.Pass(), 0, true, event_url); | 53 HandleEvent(extension_id, histogram_value, event_name, event_args.Pass(), 0, |
| 54 true, event_url); |
54 } | 55 } |
55 | 56 |
56 void EventRouterForwarder::DispatchEventToExtension( | 57 void EventRouterForwarder::DispatchEventToExtension( |
57 const std::string& extension_id, | 58 const std::string& extension_id, |
| 59 events::HistogramValue histogram_value, |
58 const std::string& event_name, | 60 const std::string& event_name, |
59 scoped_ptr<base::ListValue> event_args, | 61 scoped_ptr<base::ListValue> event_args, |
60 void* profile, | 62 void* profile, |
61 bool use_profile_to_restrict_events, | 63 bool use_profile_to_restrict_events, |
62 const GURL& event_url) { | 64 const GURL& event_url) { |
63 if (!profile) | 65 if (!profile) |
64 return; | 66 return; |
65 HandleEvent(extension_id, event_name, event_args.Pass(), profile, | 67 HandleEvent(extension_id, histogram_value, event_name, event_args.Pass(), |
66 use_profile_to_restrict_events, event_url); | 68 profile, use_profile_to_restrict_events, event_url); |
67 } | 69 } |
68 | 70 |
69 void EventRouterForwarder::HandleEvent(const std::string& extension_id, | 71 void EventRouterForwarder::HandleEvent(const std::string& extension_id, |
| 72 events::HistogramValue histogram_value, |
70 const std::string& event_name, | 73 const std::string& event_name, |
71 scoped_ptr<base::ListValue> event_args, | 74 scoped_ptr<base::ListValue> event_args, |
72 void* profile_ptr, | 75 void* profile_ptr, |
73 bool use_profile_to_restrict_events, | 76 bool use_profile_to_restrict_events, |
74 const GURL& event_url) { | 77 const GURL& event_url) { |
75 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 78 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
76 BrowserThread::PostTask( | 79 BrowserThread::PostTask( |
77 BrowserThread::UI, FROM_HERE, | 80 BrowserThread::UI, FROM_HERE, |
78 base::Bind(&EventRouterForwarder::HandleEvent, this, | 81 base::Bind(&EventRouterForwarder::HandleEvent, this, extension_id, |
79 extension_id, event_name, base::Passed(&event_args), | 82 histogram_value, event_name, base::Passed(&event_args), |
80 profile_ptr, use_profile_to_restrict_events, event_url)); | 83 profile_ptr, use_profile_to_restrict_events, event_url)); |
81 return; | 84 return; |
82 } | 85 } |
83 | 86 |
84 if (!g_browser_process || !g_browser_process->profile_manager()) | 87 if (!g_browser_process || !g_browser_process->profile_manager()) |
85 return; | 88 return; |
86 | 89 |
87 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 90 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
88 Profile* profile = NULL; | 91 Profile* profile = NULL; |
89 if (profile_ptr) { | 92 if (profile_ptr) { |
90 profile = reinterpret_cast<Profile*>(profile_ptr); | 93 profile = reinterpret_cast<Profile*>(profile_ptr); |
91 if (!profile_manager->IsValidProfile(profile)) | 94 if (!profile_manager->IsValidProfile(profile)) |
92 return; | 95 return; |
93 } | 96 } |
94 if (profile) { | 97 if (profile) { |
95 CallEventRouter(profile, extension_id, event_name, event_args.Pass(), | 98 CallEventRouter(profile, extension_id, histogram_value, event_name, |
| 99 event_args.Pass(), |
96 use_profile_to_restrict_events ? profile : NULL, event_url); | 100 use_profile_to_restrict_events ? profile : NULL, event_url); |
97 } else { | 101 } else { |
98 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 102 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
99 for (size_t i = 0; i < profiles.size(); ++i) { | 103 for (size_t i = 0; i < profiles.size(); ++i) { |
100 scoped_ptr<base::ListValue> per_profile_event_args( | 104 scoped_ptr<base::ListValue> per_profile_event_args( |
101 event_args->DeepCopy()); | 105 event_args->DeepCopy()); |
102 CallEventRouter( | 106 CallEventRouter(profiles[i], extension_id, histogram_value, event_name, |
103 profiles[i], extension_id, event_name, per_profile_event_args.Pass(), | 107 per_profile_event_args.Pass(), |
104 use_profile_to_restrict_events ? profiles[i] : NULL, event_url); | 108 use_profile_to_restrict_events ? profiles[i] : NULL, |
| 109 event_url); |
105 } | 110 } |
106 } | 111 } |
107 } | 112 } |
108 | 113 |
109 void EventRouterForwarder::CallEventRouter( | 114 void EventRouterForwarder::CallEventRouter( |
110 Profile* profile, | 115 Profile* profile, |
111 const std::string& extension_id, | 116 const std::string& extension_id, |
| 117 events::HistogramValue histogram_value, |
112 const std::string& event_name, | 118 const std::string& event_name, |
113 scoped_ptr<base::ListValue> event_args, | 119 scoped_ptr<base::ListValue> event_args, |
114 Profile* restrict_to_profile, | 120 Profile* restrict_to_profile, |
115 const GURL& event_url) { | 121 const GURL& event_url) { |
116 #if defined(OS_CHROMEOS) | 122 #if defined(OS_CHROMEOS) |
117 // Extension does not exist for chromeos login. This needs to be | 123 // Extension does not exist for chromeos login. This needs to be |
118 // removed once we have an extension service for login screen. | 124 // removed once we have an extension service for login screen. |
119 // crosbug.com/12856. | 125 // crosbug.com/12856. |
120 if (!extensions::EventRouter::Get(profile)) | 126 if (!extensions::EventRouter::Get(profile)) |
121 return; | 127 return; |
122 #endif | 128 #endif |
123 | 129 |
124 scoped_ptr<Event> event( | 130 scoped_ptr<Event> event( |
125 new Event(events::UNKNOWN, event_name, event_args.Pass())); | 131 new Event(histogram_value, event_name, event_args.Pass())); |
126 event->restrict_to_browser_context = restrict_to_profile; | 132 event->restrict_to_browser_context = restrict_to_profile; |
127 event->event_url = event_url; | 133 event->event_url = event_url; |
128 if (extension_id.empty()) { | 134 if (extension_id.empty()) { |
129 extensions::EventRouter::Get(profile)->BroadcastEvent(event.Pass()); | 135 extensions::EventRouter::Get(profile)->BroadcastEvent(event.Pass()); |
130 } else { | 136 } else { |
131 extensions::EventRouter::Get(profile) | 137 extensions::EventRouter::Get(profile) |
132 ->DispatchEventToExtension(extension_id, event.Pass()); | 138 ->DispatchEventToExtension(extension_id, event.Pass()); |
133 } | 139 } |
134 } | 140 } |
135 | 141 |
136 } // namespace extensions | 142 } // namespace extensions |
OLD | NEW |