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/extensions/event_router.h" | 10 #include "chrome/browser/extensions/event_router.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 bool use_profile_to_restrict_events, | 62 bool use_profile_to_restrict_events, |
63 const GURL& event_url) { | 63 const GURL& event_url) { |
64 if (!profile) | 64 if (!profile) |
65 return; | 65 return; |
66 HandleEvent(extension_id, event_name, event_args.Pass(), profile, | 66 HandleEvent(extension_id, event_name, event_args.Pass(), profile, |
67 use_profile_to_restrict_events, event_url); | 67 use_profile_to_restrict_events, event_url); |
68 } | 68 } |
69 | 69 |
70 void EventRouterForwarder::HandleEvent(const std::string& extension_id, | 70 void EventRouterForwarder::HandleEvent(const std::string& extension_id, |
71 const std::string& event_name, | 71 const std::string& event_name, |
72 scoped_ptr<ListValue> event_args, | 72 scoped_ptr<base::ListValue> event_args, |
73 void* profile_ptr, | 73 void* profile_ptr, |
74 bool use_profile_to_restrict_events, | 74 bool use_profile_to_restrict_events, |
75 const GURL& event_url) { | 75 const GURL& event_url) { |
76 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 76 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
77 BrowserThread::PostTask( | 77 BrowserThread::PostTask( |
78 BrowserThread::UI, FROM_HERE, | 78 BrowserThread::UI, FROM_HERE, |
79 base::Bind(&EventRouterForwarder::HandleEvent, this, | 79 base::Bind(&EventRouterForwarder::HandleEvent, this, |
80 extension_id, event_name, base::Passed(&event_args), | 80 extension_id, event_name, base::Passed(&event_args), |
81 profile_ptr, use_profile_to_restrict_events, event_url)); | 81 profile_ptr, use_profile_to_restrict_events, event_url)); |
82 return; | 82 return; |
83 } | 83 } |
84 | 84 |
85 if (!g_browser_process || !g_browser_process->profile_manager()) | 85 if (!g_browser_process || !g_browser_process->profile_manager()) |
86 return; | 86 return; |
87 | 87 |
88 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 88 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
89 Profile* profile = NULL; | 89 Profile* profile = NULL; |
90 if (profile_ptr) { | 90 if (profile_ptr) { |
91 profile = reinterpret_cast<Profile*>(profile_ptr); | 91 profile = reinterpret_cast<Profile*>(profile_ptr); |
92 if (!profile_manager->IsValidProfile(profile)) | 92 if (!profile_manager->IsValidProfile(profile)) |
93 return; | 93 return; |
94 } | 94 } |
95 if (profile) { | 95 if (profile) { |
96 CallEventRouter(profile, extension_id, event_name, event_args.Pass(), | 96 CallEventRouter(profile, extension_id, event_name, event_args.Pass(), |
97 use_profile_to_restrict_events ? profile : NULL, event_url); | 97 use_profile_to_restrict_events ? profile : NULL, event_url); |
98 } else { | 98 } else { |
99 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); | 99 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); |
100 for (size_t i = 0; i < profiles.size(); ++i) { | 100 for (size_t i = 0; i < profiles.size(); ++i) { |
101 scoped_ptr<ListValue> per_profile_event_args(event_args->DeepCopy()); | 101 scoped_ptr<base::ListValue> per_profile_event_args( |
| 102 event_args->DeepCopy()); |
102 CallEventRouter( | 103 CallEventRouter( |
103 profiles[i], extension_id, event_name, per_profile_event_args.Pass(), | 104 profiles[i], extension_id, event_name, per_profile_event_args.Pass(), |
104 use_profile_to_restrict_events ? profiles[i] : NULL, event_url); | 105 use_profile_to_restrict_events ? profiles[i] : NULL, event_url); |
105 } | 106 } |
106 } | 107 } |
107 } | 108 } |
108 | 109 |
109 void EventRouterForwarder::CallEventRouter(Profile* profile, | 110 void EventRouterForwarder::CallEventRouter( |
110 const std::string& extension_id, | 111 Profile* profile, |
111 const std::string& event_name, | 112 const std::string& extension_id, |
112 scoped_ptr<ListValue> event_args, | 113 const std::string& event_name, |
113 Profile* restrict_to_profile, | 114 scoped_ptr<base::ListValue> event_args, |
114 const GURL& event_url) { | 115 Profile* restrict_to_profile, |
| 116 const GURL& event_url) { |
115 // We may not have an extension in cases like chromeos login | 117 // We may not have an extension in cases like chromeos login |
116 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome | 118 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome |
117 // browser single process framework. | 119 // browser single process framework. |
118 if (!extensions::ExtensionSystem::Get(profile)->event_router()) | 120 if (!extensions::ExtensionSystem::Get(profile)->event_router()) |
119 return; | 121 return; |
120 | 122 |
121 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); | 123 scoped_ptr<Event> event(new Event(event_name, event_args.Pass())); |
122 event->restrict_to_profile = restrict_to_profile; | 124 event->restrict_to_profile = restrict_to_profile; |
123 event->event_url = event_url; | 125 event->event_url = event_url; |
124 if (extension_id.empty()) { | 126 if (extension_id.empty()) { |
125 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 127 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
126 } else { | 128 } else { |
127 ExtensionSystem::Get(profile)->event_router()-> | 129 ExtensionSystem::Get(profile)->event_router()-> |
128 DispatchEventToExtension(extension_id, event.Pass()); | 130 DispatchEventToExtension(extension_id, event.Pass()); |
129 } | 131 } |
130 } | 132 } |
131 | 133 |
132 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |