Chromium Code Reviews| 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/api/messaging/message_service.h" | 5 #include "chrome/browser/extensions/api/messaging/message_service.h" |
| 6 | 6 |
| 7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/lazy_instance.h" | |
| 11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" | 14 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" |
| 14 #include "chrome/browser/extensions/api/messaging/native_message_port.h" | 15 #include "chrome/browser/extensions/api/messaging/native_message_port.h" |
| 15 #include "chrome/browser/extensions/extension_host.h" | 16 #include "chrome/browser/extensions/extension_host.h" |
| 16 #include "chrome/browser/extensions/extension_process_manager.h" | 17 #include "chrome/browser/extensions/extension_process_manager.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 19 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
| 20 #include "chrome/browser/extensions/lazy_background_task_queue.h" | 21 #include "chrome/browser/extensions/lazy_background_task_queue.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 DCHECK(GET_OPPOSITE_PORT_ID(port2_id) == port1_id); | 136 DCHECK(GET_OPPOSITE_PORT_ID(port2_id) == port1_id); |
| 136 DCHECK(GET_CHANNEL_ID(port1_id) == GET_CHANNEL_ID(port2_id)); | 137 DCHECK(GET_CHANNEL_ID(port1_id) == GET_CHANNEL_ID(port2_id)); |
| 137 DCHECK(GET_CHANNEL_ID(port1_id) == channel_id); | 138 DCHECK(GET_CHANNEL_ID(port1_id) == channel_id); |
| 138 DCHECK(GET_CHANNEL_OPENER_ID(channel_id) == port1_id); | 139 DCHECK(GET_CHANNEL_OPENER_ID(channel_id) == port1_id); |
| 139 DCHECK(GET_CHANNEL_RECEIVERS_ID(channel_id) == port2_id); | 140 DCHECK(GET_CHANNEL_RECEIVERS_ID(channel_id) == port2_id); |
| 140 | 141 |
| 141 *port1 = port1_id; | 142 *port1 = port1_id; |
| 142 *port2 = port2_id; | 143 *port2 = port2_id; |
| 143 } | 144 } |
| 144 | 145 |
| 145 MessageService::MessageService( | 146 MessageService::MessageService(Profile* profile) |
| 146 LazyBackgroundTaskQueue* queue) | 147 : profile_(profile), |
|
Yoyo Zhou
2013/04/30 22:33:04
Note you don't actually use profile_ anywhere so y
Patrick Riordan
2013/05/01 01:54:44
Done.
| |
| 147 : lazy_background_task_queue_(queue), | 148 lazy_background_task_queue_( |
| 149 ExtensionSystem::Get(profile_)->lazy_background_task_queue()), | |
| 148 weak_factory_(this) { | 150 weak_factory_(this) { |
| 149 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 151 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 150 content::NotificationService::AllBrowserContextsAndSources()); | 152 content::NotificationService::AllBrowserContextsAndSources()); |
| 151 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 153 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 152 content::NotificationService::AllBrowserContextsAndSources()); | 154 content::NotificationService::AllBrowserContextsAndSources()); |
| 153 } | 155 } |
| 154 | 156 |
| 155 MessageService::~MessageService() { | 157 MessageService::~MessageService() { |
| 156 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end()); | 158 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end()); |
| 157 channels_.clear(); | 159 channels_.clear(); |
| 158 } | 160 } |
| 159 | 161 |
| 162 static base::LazyInstance<ProfileKeyedAPIFactory<MessageService> > | |
| 163 g_factory = LAZY_INSTANCE_INITIALIZER; | |
| 164 | |
| 165 // static | |
| 166 ProfileKeyedAPIFactory<MessageService>* MessageService::GetFactoryInstance() { | |
| 167 return &g_factory.Get(); | |
| 168 } | |
| 169 | |
| 170 // static | |
| 171 MessageService* MessageService::Get(Profile* profile) { | |
| 172 return ProfileKeyedAPIFactory<MessageService>::GetForProfile(profile); | |
| 173 } | |
| 174 | |
| 160 void MessageService::OpenChannelToExtension( | 175 void MessageService::OpenChannelToExtension( |
| 161 int source_process_id, int source_routing_id, int receiver_port_id, | 176 int source_process_id, int source_routing_id, int receiver_port_id, |
| 162 const std::string& source_extension_id, | 177 const std::string& source_extension_id, |
| 163 const std::string& target_extension_id, | 178 const std::string& target_extension_id, |
| 164 const GURL& source_url, | 179 const GURL& source_url, |
| 165 const std::string& channel_name) { | 180 const std::string& channel_name) { |
| 166 content::RenderProcessHost* source = | 181 content::RenderProcessHost* source = |
| 167 content::RenderProcessHost::FromID(source_process_id); | 182 content::RenderProcessHost::FromID(source_process_id); |
| 168 if (!source) | 183 if (!source) |
| 169 return; | 184 return; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 return; | 541 return; |
| 527 | 542 |
| 528 params->source = source; | 543 params->source = source; |
| 529 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 544 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
| 530 MSG_ROUTING_CONTROL, | 545 MSG_ROUTING_CONTROL, |
| 531 params->target_extension_id)); | 546 params->target_extension_id)); |
| 532 OpenChannelImpl(params.Pass()); | 547 OpenChannelImpl(params.Pass()); |
| 533 } | 548 } |
| 534 | 549 |
| 535 } // namespace extensions | 550 } // namespace extensions |
| OLD | NEW |