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

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

Issue 10175008: Improving the process model extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved to async extension functions and generated docs. Created 8 years, 7 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/extension_event_router.h" 5 #include "chrome/browser/extensions/extension_event_router.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 10 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 const std::string& extension_id) { 124 const std::string& extension_id) {
125 ListenerProcess listener(process, extension_id); 125 ListenerProcess listener(process, extension_id);
126 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name; 126 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name;
127 listeners_[event_name].insert(listener); 127 listeners_[event_name].insert(listener);
128 128
129 if (extension_devtools_manager_.get()) 129 if (extension_devtools_manager_.get())
130 extension_devtools_manager_->AddEventListener(event_name, 130 extension_devtools_manager_->AddEventListener(event_name,
131 process->GetID()); 131 process->GetID());
132 132
133 // We lazily tell the TaskManager to start updating when listeners to the 133 // We lazily tell the TaskManager to start updating when listeners to the
134 // processes.onUpdated event arrive. 134 // processes.onUpdated or processes.onUpdatedWithMemory events arrive.
135 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) 135 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0 ||
136 event_name.compare(
137 extension_processes_api_constants::kOnUpdatedWithMemory) == 0)
136 ExtensionProcessesEventRouter::GetInstance()->ListenerAdded(); 138 ExtensionProcessesEventRouter::GetInstance()->ListenerAdded();
137 } 139 }
138 140
139 void ExtensionEventRouter::RemoveEventListener( 141 void ExtensionEventRouter::RemoveEventListener(
140 const std::string& event_name, 142 const std::string& event_name,
141 content::RenderProcessHost* process, 143 content::RenderProcessHost* process,
142 const std::string& extension_id) { 144 const std::string& extension_id) {
143 ListenerProcess listener(process, extension_id); 145 ListenerProcess listener(process, extension_id);
144 DCHECK_EQ(listeners_[event_name].count(listener), 1u) << 146 DCHECK_EQ(listeners_[event_name].count(listener), 1u) <<
145 " PID=" << process->GetID() << " extension=" << extension_id << 147 " PID=" << process->GetID() << " extension=" << extension_id <<
146 " event=" << event_name; 148 " event=" << event_name;
147 listeners_[event_name].erase(listener); 149 listeners_[event_name].erase(listener);
148 // Note: extension_id may point to data in the now-deleted listeners_ object. 150 // Note: extension_id may point to data in the now-deleted listeners_ object.
149 // Do not use. 151 // Do not use.
150 152
151 if (extension_devtools_manager_.get()) 153 if (extension_devtools_manager_.get())
152 extension_devtools_manager_->RemoveEventListener(event_name, 154 extension_devtools_manager_->RemoveEventListener(event_name,
153 process->GetID()); 155 process->GetID());
154 156
155 // If a processes.onUpdated event listener is removed (or a process with one 157 // If a processes.onUpdated or processes.onUpdatedWithMemory event listener
156 // exits), then we let the TaskManager know that it has one fewer listener. 158 // is removed (or a process with one exits), then we let the extension API
157 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) 159 // know that it has one fewer listener.
160 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0 ||
161 event_name.compare(
162 extension_processes_api_constants::kOnUpdatedWithMemory) == 0)
158 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved(); 163 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved();
159 164
160 BrowserThread::PostTask( 165 BrowserThread::PostTask(
161 BrowserThread::IO, FROM_HERE, 166 BrowserThread::IO, FROM_HERE,
162 base::Bind( 167 base::Bind(
163 &NotifyEventListenerRemovedOnIOThread, 168 &NotifyEventListenerRemovedOnIOThread,
164 profile_, listener.extension_id, event_name)); 169 profile_, listener.extension_id, event_name));
165 } 170 }
166 171
167 void ExtensionEventRouter::AddLazyEventListener( 172 void ExtensionEventRouter::AddLazyEventListener(
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 content::Details<const Extension>(details).ptr(); 501 content::Details<const Extension>(details).ptr();
497 extensions::RuntimeEventRouter::DispatchOnInstalledEvent( 502 extensions::RuntimeEventRouter::DispatchOnInstalledEvent(
498 profile_, extension); 503 profile_, extension);
499 break; 504 break;
500 } 505 }
501 default: 506 default:
502 NOTREACHED(); 507 NOTREACHED();
503 return; 508 return;
504 } 509 }
505 } 510 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698