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