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

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: Schema file synced with docs, some minor cleanup. 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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 const std::string& extension_id) { 125 const std::string& extension_id) {
126 ListenerProcess listener(process, extension_id); 126 ListenerProcess listener(process, extension_id);
127 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name; 127 DCHECK_EQ(listeners_[event_name].count(listener), 0u) << event_name;
128 listeners_[event_name].insert(listener); 128 listeners_[event_name].insert(listener);
129 129
130 if (extension_devtools_manager_.get()) 130 if (extension_devtools_manager_.get())
131 extension_devtools_manager_->AddEventListener(event_name, 131 extension_devtools_manager_->AddEventListener(event_name,
132 process->GetID()); 132 process->GetID());
133 133
134 // We lazily tell the TaskManager to start updating when listeners to the 134 // We lazily tell the TaskManager to start updating when listeners to the
135 // processes.onUpdated event arrive. 135 // processes.onUpdated or processes.onUpdatedWithMemory events arrive.
136 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) 136 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0 ||
137 event_name.compare(
138 extension_processes_api_constants::kOnUpdatedWithMemory) == 0)
137 ExtensionProcessesEventRouter::GetInstance()->ListenerAdded(); 139 ExtensionProcessesEventRouter::GetInstance()->ListenerAdded();
138 } 140 }
139 141
140 void ExtensionEventRouter::RemoveEventListener( 142 void ExtensionEventRouter::RemoveEventListener(
141 const std::string& event_name, 143 const std::string& event_name,
142 content::RenderProcessHost* process, 144 content::RenderProcessHost* process,
143 const std::string& extension_id) { 145 const std::string& extension_id) {
144 ListenerProcess listener(process, extension_id); 146 ListenerProcess listener(process, extension_id);
145 DCHECK_EQ(listeners_[event_name].count(listener), 1u) << 147 DCHECK_EQ(listeners_[event_name].count(listener), 1u) <<
146 " PID=" << process->GetID() << " extension=" << extension_id << 148 " PID=" << process->GetID() << " extension=" << extension_id <<
147 " event=" << event_name; 149 " event=" << event_name;
148 listeners_[event_name].erase(listener); 150 listeners_[event_name].erase(listener);
149 // Note: extension_id may point to data in the now-deleted listeners_ object. 151 // Note: extension_id may point to data in the now-deleted listeners_ object.
150 // Do not use. 152 // Do not use.
151 153
152 if (extension_devtools_manager_.get()) 154 if (extension_devtools_manager_.get())
153 extension_devtools_manager_->RemoveEventListener(event_name, 155 extension_devtools_manager_->RemoveEventListener(event_name,
154 process->GetID()); 156 process->GetID());
155 157
156 // If a processes.onUpdated event listener is removed (or a process with one 158 // If a processes.onUpdated or processes.onUpdatedWithMemory event listener
157 // exits), then we let the TaskManager know that it has one fewer listener. 159 // is removed (or a process with one exits), then we let the extension API
158 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0) 160 // know that it has one fewer listener.
161 if (event_name.compare(extension_processes_api_constants::kOnUpdated) == 0 ||
162 event_name.compare(
163 extension_processes_api_constants::kOnUpdatedWithMemory) == 0)
159 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved(); 164 ExtensionProcessesEventRouter::GetInstance()->ListenerRemoved();
160 165
161 BrowserThread::PostTask( 166 BrowserThread::PostTask(
162 BrowserThread::IO, FROM_HERE, 167 BrowserThread::IO, FROM_HERE,
163 base::Bind( 168 base::Bind(
164 &NotifyEventListenerRemovedOnIOThread, 169 &NotifyEventListenerRemovedOnIOThread,
165 profile_, listener.extension_id, event_name)); 170 profile_, listener.extension_id, event_name));
166 } 171 }
167 172
168 void ExtensionEventRouter::AddLazyEventListener( 173 void ExtensionEventRouter::AddLazyEventListener(
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 MessageLoop::current()->PostTask(FROM_HERE, 503 MessageLoop::current()->PostTask(FROM_HERE,
499 base::Bind(&extensions::RuntimeEventRouter::DispatchOnInstalledEvent, 504 base::Bind(&extensions::RuntimeEventRouter::DispatchOnInstalledEvent,
500 profile_, extension->id())); 505 profile_, extension->id()));
501 break; 506 break;
502 } 507 }
503 default: 508 default:
504 NOTREACHED(); 509 NOTREACHED();
505 return; 510 return;
506 } 511 }
507 } 512 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698