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

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

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing memory leak in a test. Created 8 years, 4 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 | Annotate | Revision Log
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_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 "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/event_router.h" 10 #include "chrome/browser/extensions/event_router.h"
10 #include "chrome/browser/profiles/profile_manager.h" 11 #include "chrome/browser/profiles/profile_manager.h"
11 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
12 13
13 using content::BrowserThread; 14 using content::BrowserThread;
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 EventRouterForwarder::EventRouterForwarder() { 18 EventRouterForwarder::EventRouterForwarder() {
18 } 19 }
19 20
20 EventRouterForwarder::~EventRouterForwarder() { 21 EventRouterForwarder::~EventRouterForwarder() {
21 } 22 }
22 23
23 void EventRouterForwarder::BroadcastEventToRenderers( 24 void EventRouterForwarder::BroadcastEventToRenderers(
24 const std::string& event_name, 25 const std::string& event_name,
25 const std::string& event_args, 26 scoped_ptr<base::ListValue> event_args,
26 const GURL& event_url) { 27 const GURL& event_url) {
27 HandleEvent("", event_name, event_args, 0, true, event_url); 28 HandleEvent("", event_name, event_args.Pass(), 0, true, event_url);
28 } 29 }
29 30
30 void EventRouterForwarder::DispatchEventToRenderers( 31 void EventRouterForwarder::DispatchEventToRenderers(
31 const std::string& event_name, 32 const std::string& event_name,
32 const std::string& event_args, 33 scoped_ptr<base::ListValue> event_args,
33 void* profile, 34 void* profile,
34 bool use_profile_to_restrict_events, 35 bool use_profile_to_restrict_events,
35 const GURL& event_url) { 36 const GURL& event_url) {
36 if (!profile) 37 if (!profile)
37 return; 38 return;
38 HandleEvent("", event_name, event_args, profile, 39 HandleEvent("", event_name, event_args.Pass(), profile,
39 use_profile_to_restrict_events, event_url); 40 use_profile_to_restrict_events, event_url);
40 } 41 }
41 42
42 void EventRouterForwarder::BroadcastEventToExtension( 43 void EventRouterForwarder::BroadcastEventToExtension(
43 const std::string& extension_id, 44 const std::string& extension_id,
44 const std::string& event_name, 45 const std::string& event_name,
45 const std::string& event_args, 46 scoped_ptr<base::ListValue> event_args,
46 const GURL& event_url) { 47 const GURL& event_url) {
47 HandleEvent(extension_id, event_name, event_args, 0, true, event_url); 48 HandleEvent(extension_id, event_name, event_args.Pass(), 0, true, event_url);
48 } 49 }
49 50
50 void EventRouterForwarder::DispatchEventToExtension( 51 void EventRouterForwarder::DispatchEventToExtension(
51 const std::string& extension_id, 52 const std::string& extension_id,
52 const std::string& event_name, 53 const std::string& event_name,
53 const std::string& event_args, 54 scoped_ptr<base::ListValue> event_args,
54 void* profile, 55 void* profile,
55 bool use_profile_to_restrict_events, 56 bool use_profile_to_restrict_events,
56 const GURL& event_url) { 57 const GURL& event_url) {
57 if (!profile) 58 if (!profile)
58 return; 59 return;
59 HandleEvent(extension_id, event_name, event_args, profile, 60 HandleEvent(extension_id, event_name, event_args.Pass(), profile,
60 use_profile_to_restrict_events, event_url); 61 use_profile_to_restrict_events, event_url);
61 } 62 }
62 63
63 void EventRouterForwarder::HandleEvent(const std::string& extension_id, 64 void EventRouterForwarder::HandleEvent(const std::string& extension_id,
64 const std::string& event_name, 65 const std::string& event_name,
65 const std::string& event_args, 66 scoped_ptr<ListValue> event_args,
66 void* profile_ptr, 67 void* profile_ptr,
67 bool use_profile_to_restrict_events, 68 bool use_profile_to_restrict_events,
68 const GURL& event_url) { 69 const GURL& event_url) {
69 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 70 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
70 BrowserThread::PostTask( 71 BrowserThread::PostTask(
71 BrowserThread::UI, FROM_HERE, 72 BrowserThread::UI, FROM_HERE,
72 base::Bind(&EventRouterForwarder::HandleEvent, this, 73 base::Bind(&EventRouterForwarder::HandleEvent, this,
73 extension_id, event_name, event_args, profile_ptr, 74 extension_id, event_name, Passed(&event_args), profile_ptr,
74 use_profile_to_restrict_events, event_url)); 75 use_profile_to_restrict_events, event_url));
75 return; 76 return;
76 } 77 }
77 78
78 if (!g_browser_process || !g_browser_process->profile_manager()) 79 if (!g_browser_process || !g_browser_process->profile_manager())
79 return; 80 return;
80 81
81 ProfileManager* profile_manager = g_browser_process->profile_manager(); 82 ProfileManager* profile_manager = g_browser_process->profile_manager();
82 Profile* profile = NULL; 83 Profile* profile = NULL;
83 if (profile_ptr) { 84 if (profile_ptr) {
84 profile = reinterpret_cast<Profile*>(profile_ptr); 85 profile = reinterpret_cast<Profile*>(profile_ptr);
85 if (!profile_manager->IsValidProfile(profile)) 86 if (!profile_manager->IsValidProfile(profile))
86 return; 87 return;
87 } 88 }
88 if (profile) { 89 if (profile) {
89 CallEventRouter(profile, extension_id, event_name, event_args, 90 CallEventRouter(profile, extension_id, event_name, event_args.Pass(),
90 use_profile_to_restrict_events ? profile : NULL, event_url); 91 use_profile_to_restrict_events ? profile : NULL, event_url);
91 } else { 92 } else {
92 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles()); 93 std::vector<Profile*> profiles(profile_manager->GetLoadedProfiles());
93 for (size_t i = 0; i < profiles.size(); ++i) { 94 for (size_t i = 0; i < profiles.size(); ++i) {
94 CallEventRouter( 95 CallEventRouter(
95 profiles[i], extension_id, event_name, event_args, 96 profiles[i], extension_id, event_name, event_args.Pass(),
96 use_profile_to_restrict_events ? profiles[i] : NULL, event_url); 97 use_profile_to_restrict_events ? profiles[i] : NULL, event_url);
97 } 98 }
98 } 99 }
99 } 100 }
100 101
101 void EventRouterForwarder::CallEventRouter(Profile* profile, 102 void EventRouterForwarder::CallEventRouter(Profile* profile,
102 const std::string& extension_id, 103 const std::string& extension_id,
103 const std::string& event_name, 104 const std::string& event_name,
104 const std::string& event_args, 105 scoped_ptr<ListValue> event_args,
105 Profile* restrict_to_profile, 106 Profile* restrict_to_profile,
106 const GURL& event_url) { 107 const GURL& event_url) {
107 // We may not have an extension in cases like chromeos login 108 // We may not have an extension in cases like chromeos login
108 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome 109 // (crosbug.com/12856), chrome_frame_net_tests.exe which reuses the chrome
109 // browser single process framework. 110 // browser single process framework.
110 if (!profile->GetExtensionEventRouter()) 111 if (!profile->GetExtensionEventRouter())
111 return; 112 return;
112 113
113 if (extension_id.empty()) { 114 if (extension_id.empty()) {
114 profile->GetExtensionEventRouter()-> 115 profile->GetExtensionEventRouter()->
115 DispatchEventToRenderers( 116 DispatchEventToRenderers(
116 event_name, event_args, restrict_to_profile, event_url, 117 event_name, event_args.Pass(), restrict_to_profile, event_url,
117 EventFilteringInfo()); 118 EventFilteringInfo());
118 } else { 119 } else {
119 profile->GetExtensionEventRouter()-> 120 profile->GetExtensionEventRouter()->
120 DispatchEventToExtension( 121 DispatchEventToExtension(
121 extension_id, 122 extension_id,
122 event_name, event_args, restrict_to_profile, event_url); 123 event_name, event_args.Pass(), restrict_to_profile, event_url);
123 } 124 }
124 } 125 }
125 126
126 } // namespace extensions 127 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/event_router_forwarder.h ('k') | chrome/browser/extensions/event_router_forwarder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698