| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" | |
| 6 | |
| 7 #include "chrome/browser/extensions/extension_host.h" | |
| 8 #include "chrome/browser/extensions/extension_process_manager.h" | |
| 9 #include "chrome/browser/extensions/extension_system.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/common/extensions/extension_messages.h" | |
| 12 #include "content/public/browser/render_process_host.h" | |
| 13 | |
| 14 namespace extensions { | |
| 15 | |
| 16 ExtensionMessagePort::ExtensionMessagePort(content::RenderProcessHost* process, | |
| 17 int routing_id, | |
| 18 const std::string& extension_id) | |
| 19 : process_(process), | |
| 20 routing_id_(routing_id), | |
| 21 extension_id_(extension_id), | |
| 22 background_host_ptr_(NULL) { | |
| 23 } | |
| 24 | |
| 25 void ExtensionMessagePort::DispatchOnConnect( | |
| 26 int dest_port_id, | |
| 27 const std::string& channel_name, | |
| 28 const std::string& tab_json, | |
| 29 const std::string& source_extension_id, | |
| 30 const std::string& target_extension_id) { | |
| 31 process_->Send(new ExtensionMsg_DispatchOnConnect( | |
| 32 routing_id_, dest_port_id, channel_name, | |
| 33 tab_json, source_extension_id, target_extension_id)); | |
| 34 } | |
| 35 | |
| 36 void ExtensionMessagePort::DispatchOnDisconnect(int source_port_id, | |
| 37 bool connection_error) { | |
| 38 process_->Send(new ExtensionMsg_DispatchOnDisconnect( | |
| 39 routing_id_, source_port_id, connection_error)); | |
| 40 } | |
| 41 | |
| 42 void ExtensionMessagePort::DispatchOnMessage(const std::string& message, | |
| 43 int target_port_id) { | |
| 44 process_->Send(new ExtensionMsg_DeliverMessage( | |
| 45 routing_id_, target_port_id, message)); | |
| 46 } | |
| 47 | |
| 48 void ExtensionMessagePort::IncrementLazyKeepaliveCount() { | |
| 49 Profile* profile = | |
| 50 Profile::FromBrowserContext(process_->GetBrowserContext()); | |
| 51 ExtensionProcessManager* pm = | |
| 52 ExtensionSystem::Get(profile)->process_manager(); | |
| 53 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); | |
| 54 if (host && host->extension()->has_lazy_background_page()) | |
| 55 pm->IncrementLazyKeepaliveCount(host->extension()); | |
| 56 | |
| 57 // Keep track of the background host, so when we decrement, we only do so if | |
| 58 // the host hasn't reloaded. | |
| 59 background_host_ptr_ = host; | |
| 60 } | |
| 61 | |
| 62 void ExtensionMessagePort::DecrementLazyKeepaliveCount() { | |
| 63 Profile* profile = | |
| 64 Profile::FromBrowserContext(process_->GetBrowserContext()); | |
| 65 ExtensionProcessManager* pm = | |
| 66 ExtensionSystem::Get(profile)->process_manager(); | |
| 67 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); | |
| 68 if (host && host == background_host_ptr_) | |
| 69 pm->DecrementLazyKeepaliveCount(host->extension()); | |
| 70 } | |
| 71 | |
| 72 content::RenderProcessHost* ExtensionMessagePort::GetRenderProcessHost() { | |
| 73 return process_; | |
| 74 } | |
| 75 | |
| 76 } // namespace extensions | |
| OLD | NEW |