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), |
| 147 : lazy_background_task_queue_(queue), | |
| 148 weak_factory_(this) { | 148 weak_factory_(this) { |
| 149 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 149 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 150 content::NotificationService::AllBrowserContextsAndSources()); | 150 content::NotificationService::AllBrowserContextsAndSources()); |
| 151 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 151 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 152 content::NotificationService::AllBrowserContextsAndSources()); | 152 content::NotificationService::AllBrowserContextsAndSources()); |
| 153 lazy_background_task_queue_ = | |
|
Devlin
2013/04/26 01:21:25
nit: You could initialize this right below profile
Patrick Riordan
2013/04/26 02:18:45
Done.
| |
| 154 ExtensionSystem::Get(profile_)->lazy_background_task_queue(); | |
| 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 | |
| 160 void MessageService::OpenChannelToExtension( | 170 void MessageService::OpenChannelToExtension( |
| 161 int source_process_id, int source_routing_id, int receiver_port_id, | 171 int source_process_id, int source_routing_id, int receiver_port_id, |
| 162 const std::string& source_extension_id, | 172 const std::string& source_extension_id, |
| 163 const std::string& target_extension_id, | 173 const std::string& target_extension_id, |
| 164 const GURL& source_url, | 174 const GURL& source_url, |
| 165 const std::string& channel_name) { | 175 const std::string& channel_name) { |
| 166 content::RenderProcessHost* source = | 176 content::RenderProcessHost* source = |
| 167 content::RenderProcessHost::FromID(source_process_id); | 177 content::RenderProcessHost::FromID(source_process_id); |
| 168 if (!source) | 178 if (!source) |
| 169 return; | 179 return; |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 return; | 536 return; |
| 527 | 537 |
| 528 params->source = source; | 538 params->source = source; |
| 529 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), | 539 params->receiver.reset(new ExtensionMessagePort(host->render_process_host(), |
| 530 MSG_ROUTING_CONTROL, | 540 MSG_ROUTING_CONTROL, |
| 531 params->target_extension_id)); | 541 params->target_extension_id)); |
| 532 OpenChannelImpl(params.Pass()); | 542 OpenChannelImpl(params.Pass()); |
| 533 } | 543 } |
| 534 | 544 |
| 535 } // namespace extensions | 545 } // namespace extensions |
| OLD | NEW |