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
3 // found in the LICENSE file.
5 #include "extensions/browser/mojo/keep_alive_impl.h"
8 #include "extensions/browser/extension_registry.h"
9 #include "extensions/browser/process_manager.h"
11 namespace extensions
{
14 void KeepAliveImpl::Create(content::BrowserContext
* context
,
15 const Extension
* extension
,
16 mojo::InterfaceRequest
<KeepAlive
> request
) {
17 new KeepAliveImpl(context
, extension
, request
.Pass());
20 KeepAliveImpl::KeepAliveImpl(content::BrowserContext
* context
,
21 const Extension
* extension
,
22 mojo::InterfaceRequest
<KeepAlive
> request
)
24 extension_(extension
),
25 extension_registry_observer_(this),
26 binding_(this, request
.Pass()) {
27 ProcessManager::Get(context_
)->IncrementLazyKeepaliveCount(extension_
);
28 binding_
.set_connection_error_handler(
29 base::Bind(&KeepAliveImpl::OnDisconnected
, base::Unretained(this)));
30 extension_registry_observer_
.Add(ExtensionRegistry::Get(context_
));
33 KeepAliveImpl::~KeepAliveImpl() = default;
35 void KeepAliveImpl::OnExtensionUnloaded(
36 content::BrowserContext
* browser_context
,
37 const Extension
* extension
,
38 UnloadedExtensionInfo::Reason reason
) {
39 if (browser_context
== context_
&& extension
== extension_
)
43 void KeepAliveImpl::OnShutdown(ExtensionRegistry
* registry
) {
47 void KeepAliveImpl::OnDisconnected() {
48 ProcessManager::Get(context_
)->DecrementLazyKeepaliveCount(extension_
);
51 } // namespace extensions