OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/mojo/keep_alive_impl.h" | 5 #include "extensions/browser/mojo/keep_alive_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "extensions/browser/extension_registry.h" | 10 #include "extensions/browser/extension_registry.h" |
11 #include "extensions/browser/process_manager.h" | 11 #include "extensions/browser/process_manager.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 // static | 15 // static |
16 void KeepAliveImpl::Create(content::BrowserContext* context, | 16 void KeepAliveImpl::Create(content::BrowserContext* context, |
17 const Extension* extension, | 17 const Extension* extension, |
18 mojo::InterfaceRequest<KeepAlive> request) { | 18 KeepAliveRequest request) { |
| 19 // Owns itself. |
19 new KeepAliveImpl(context, extension, std::move(request)); | 20 new KeepAliveImpl(context, extension, std::move(request)); |
20 } | 21 } |
21 | 22 |
22 KeepAliveImpl::KeepAliveImpl(content::BrowserContext* context, | 23 KeepAliveImpl::KeepAliveImpl(content::BrowserContext* context, |
23 const Extension* extension, | 24 const Extension* extension, |
24 mojo::InterfaceRequest<KeepAlive> request) | 25 KeepAliveRequest request) |
25 : context_(context), | 26 : context_(context), |
26 extension_(extension), | 27 extension_(extension), |
27 extension_registry_observer_(this), | 28 extension_registry_observer_(this), |
28 binding_(this, std::move(request)) { | 29 binding_(this, std::move(request)) { |
29 ProcessManager::Get(context_)->IncrementLazyKeepaliveCount(extension_); | 30 ProcessManager::Get(context_)->IncrementLazyKeepaliveCount(extension_); |
30 binding_.set_connection_error_handler( | 31 binding_.set_connection_error_handler( |
31 base::Bind(&KeepAliveImpl::OnDisconnected, base::Unretained(this))); | 32 base::Bind(&KeepAliveImpl::OnDisconnected, base::Unretained(this))); |
32 extension_registry_observer_.Add(ExtensionRegistry::Get(context_)); | 33 extension_registry_observer_.Add(ExtensionRegistry::Get(context_)); |
33 } | 34 } |
34 | 35 |
35 KeepAliveImpl::~KeepAliveImpl() = default; | 36 KeepAliveImpl::~KeepAliveImpl() = default; |
36 | 37 |
37 void KeepAliveImpl::OnExtensionUnloaded( | 38 void KeepAliveImpl::OnExtensionUnloaded( |
38 content::BrowserContext* browser_context, | 39 content::BrowserContext* browser_context, |
39 const Extension* extension, | 40 const Extension* extension, |
40 UnloadedExtensionInfo::Reason reason) { | 41 UnloadedExtensionInfo::Reason reason) { |
41 if (browser_context == context_ && extension == extension_) | 42 if (browser_context == context_ && extension == extension_) |
42 delete this; | 43 delete this; |
43 } | 44 } |
44 | 45 |
45 void KeepAliveImpl::OnShutdown(ExtensionRegistry* registry) { | 46 void KeepAliveImpl::OnShutdown(ExtensionRegistry* registry) { |
46 delete this; | 47 delete this; |
47 } | 48 } |
48 | 49 |
49 void KeepAliveImpl::OnDisconnected() { | 50 void KeepAliveImpl::OnDisconnected() { |
50 ProcessManager::Get(context_)->DecrementLazyKeepaliveCount(extension_); | 51 ProcessManager::Get(context_)->DecrementLazyKeepaliveCount(extension_); |
| 52 delete this; |
51 } | 53 } |
52 | 54 |
53 } // namespace extensions | 55 } // namespace extensions |
OLD | NEW |