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

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

Issue 306032: Simplify threading in browser thread by making only ChromeThread deal with di... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a few more simplifications Created 11 years, 2 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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_message_service.h" 5 #include "chrome/browser/extensions/extension_message_service.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/singleton.h" 8 #include "base/singleton.h"
9 #include "base/stl_util-inl.h" 9 #include "base/stl_util-inl.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 DCHECK(GET_CHANNEL_RECEIVERS_ID(channel_id) == port2_id); 191 DCHECK(GET_CHANNEL_RECEIVERS_ID(channel_id) == port2_id);
192 192
193 *port1 = port1_id; 193 *port1 = port1_id;
194 *port2 = port2_id; 194 *port2 = port2_id;
195 } 195 }
196 196
197 int ExtensionMessageService::OpenChannelToExtension( 197 int ExtensionMessageService::OpenChannelToExtension(
198 int routing_id, const std::string& source_extension_id, 198 int routing_id, const std::string& source_extension_id,
199 const std::string& target_extension_id, 199 const std::string& target_extension_id,
200 const std::string& channel_name, ResourceMessageFilter* source) { 200 const std::string& channel_name, ResourceMessageFilter* source) {
201 DCHECK_EQ(MessageLoop::current(), 201 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
202 ChromeThread::GetMessageLoop(ChromeThread::IO));
203 202
204 // Create a channel ID for both sides of the channel. 203 // Create a channel ID for both sides of the channel.
205 int port1_id = -1; 204 int port1_id = -1;
206 int port2_id = -1; 205 int port2_id = -1;
207 AllocatePortIdPair(&port1_id, &port2_id); 206 AllocatePortIdPair(&port1_id, &port2_id);
208 207
209 // Each side of the port is given his own port ID. When they send messages, 208 // Each side of the port is given his own port ID. When they send messages,
210 // we convert to the opposite port ID. See PostMessageFromRenderer. 209 // we convert to the opposite port ID. See PostMessageFromRenderer.
211 ui_loop_->PostTask(FROM_HERE, 210 ui_loop_->PostTask(FROM_HERE,
212 NewRunnableMethod(this, 211 NewRunnableMethod(this,
213 &ExtensionMessageService::OpenChannelToExtensionOnUIThread, 212 &ExtensionMessageService::OpenChannelToExtensionOnUIThread,
214 source->id(), routing_id, port2_id, source_extension_id, 213 source->id(), routing_id, port2_id, source_extension_id,
215 target_extension_id, channel_name)); 214 target_extension_id, channel_name));
216 215
217 return port1_id; 216 return port1_id;
218 } 217 }
219 218
220 int ExtensionMessageService::OpenChannelToTab(int routing_id, 219 int ExtensionMessageService::OpenChannelToTab(int routing_id,
221 int tab_id, 220 int tab_id,
222 const std::string& extension_id, 221 const std::string& extension_id,
223 const std::string& channel_name, 222 const std::string& channel_name,
224 ResourceMessageFilter* source) { 223 ResourceMessageFilter* source) {
225 DCHECK_EQ(MessageLoop::current(), 224 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
226 ChromeThread::GetMessageLoop(ChromeThread::IO));
227 225
228 // Create a channel ID for both sides of the channel. 226 // Create a channel ID for both sides of the channel.
229 int port1_id = -1; 227 int port1_id = -1;
230 int port2_id = -1; 228 int port2_id = -1;
231 AllocatePortIdPair(&port1_id, &port2_id); 229 AllocatePortIdPair(&port1_id, &port2_id);
232 230
233 // Each side of the port is given his own port ID. When they send messages, 231 // Each side of the port is given his own port ID. When they send messages,
234 // we convert to the opposite port ID. See PostMessageFromRenderer. 232 // we convert to the opposite port ID. See PostMessageFromRenderer.
235 ui_loop_->PostTask(FROM_HERE, 233 ui_loop_->PostTask(FROM_HERE,
236 NewRunnableMethod(this, 234 NewRunnableMethod(this,
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 506
509 if (current->second->opener.sender == sender) { 507 if (current->second->opener.sender == sender) {
510 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first), 508 CloseChannelImpl(current, GET_CHANNEL_OPENER_ID(current->first),
511 notify_other_port); 509 notify_other_port);
512 } else if (current->second->receiver.sender == sender) { 510 } else if (current->second->receiver.sender == sender) {
513 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first), 511 CloseChannelImpl(current, GET_CHANNEL_RECEIVERS_ID(current->first),
514 notify_other_port); 512 notify_other_port);
515 } 513 }
516 } 514 }
517 } 515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698