| 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/extension_message_port.h" | 5 #include "chrome/browser/extensions/api/messaging/extension_message_port.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "content/public/browser/render_process_host.h" | 8 #include "content/public/browser/render_process_host.h" |
| 9 #include "extensions/browser/extension_host.h" | 9 #include "extensions/browser/extension_host.h" |
| 10 #include "extensions/browser/extension_system.h" | |
| 11 #include "extensions/browser/process_manager.h" | 10 #include "extensions/browser/process_manager.h" |
| 12 #include "extensions/common/extension_messages.h" | 11 #include "extensions/common/extension_messages.h" |
| 13 #include "extensions/common/manifest_handlers/background_info.h" | 12 #include "extensions/common/manifest_handlers/background_info.h" |
| 14 | 13 |
| 15 namespace extensions { | 14 namespace extensions { |
| 16 | 15 |
| 17 ExtensionMessagePort::ExtensionMessagePort(content::RenderProcessHost* process, | 16 ExtensionMessagePort::ExtensionMessagePort(content::RenderProcessHost* process, |
| 18 int routing_id, | 17 int routing_id, |
| 19 const std::string& extension_id) | 18 const std::string& extension_id) |
| 20 : process_(process), | 19 : process_(process), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 49 | 48 |
| 50 void ExtensionMessagePort::DispatchOnMessage(const Message& message, | 49 void ExtensionMessagePort::DispatchOnMessage(const Message& message, |
| 51 int target_port_id) { | 50 int target_port_id) { |
| 52 process_->Send(new ExtensionMsg_DeliverMessage( | 51 process_->Send(new ExtensionMsg_DeliverMessage( |
| 53 routing_id_, target_port_id, message)); | 52 routing_id_, target_port_id, message)); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void ExtensionMessagePort::IncrementLazyKeepaliveCount() { | 55 void ExtensionMessagePort::IncrementLazyKeepaliveCount() { |
| 57 Profile* profile = | 56 Profile* profile = |
| 58 Profile::FromBrowserContext(process_->GetBrowserContext()); | 57 Profile::FromBrowserContext(process_->GetBrowserContext()); |
| 59 extensions::ProcessManager* pm = | 58 extensions::ProcessManager* pm = ProcessManager::Get(profile); |
| 60 ExtensionSystem::Get(profile)->process_manager(); | |
| 61 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); | 59 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); |
| 62 if (host && BackgroundInfo::HasLazyBackgroundPage(host->extension())) | 60 if (host && BackgroundInfo::HasLazyBackgroundPage(host->extension())) |
| 63 pm->IncrementLazyKeepaliveCount(host->extension()); | 61 pm->IncrementLazyKeepaliveCount(host->extension()); |
| 64 | 62 |
| 65 // Keep track of the background host, so when we decrement, we only do so if | 63 // Keep track of the background host, so when we decrement, we only do so if |
| 66 // the host hasn't reloaded. | 64 // the host hasn't reloaded. |
| 67 background_host_ptr_ = host; | 65 background_host_ptr_ = host; |
| 68 } | 66 } |
| 69 | 67 |
| 70 void ExtensionMessagePort::DecrementLazyKeepaliveCount() { | 68 void ExtensionMessagePort::DecrementLazyKeepaliveCount() { |
| 71 Profile* profile = | 69 Profile* profile = |
| 72 Profile::FromBrowserContext(process_->GetBrowserContext()); | 70 Profile::FromBrowserContext(process_->GetBrowserContext()); |
| 73 extensions::ProcessManager* pm = | 71 extensions::ProcessManager* pm = ProcessManager::Get(profile); |
| 74 ExtensionSystem::Get(profile)->process_manager(); | |
| 75 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); | 72 ExtensionHost* host = pm->GetBackgroundHostForExtension(extension_id_); |
| 76 if (host && host == background_host_ptr_) | 73 if (host && host == background_host_ptr_) |
| 77 pm->DecrementLazyKeepaliveCount(host->extension()); | 74 pm->DecrementLazyKeepaliveCount(host->extension()); |
| 78 } | 75 } |
| 79 | 76 |
| 80 content::RenderProcessHost* ExtensionMessagePort::GetRenderProcessHost() { | 77 content::RenderProcessHost* ExtensionMessagePort::GetRenderProcessHost() { |
| 81 return process_; | 78 return process_; |
| 82 } | 79 } |
| 83 | 80 |
| 84 } // namespace extensions | 81 } // namespace extensions |
| OLD | NEW |