Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / browser / mojo / keep_alive_impl.cc
blobadfccaa3b141a4fb0b8ee58c65c3edf873310d88
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"
7 #include "base/bind.h"
8 #include "extensions/browser/extension_registry.h"
9 #include "extensions/browser/process_manager.h"
11 namespace extensions {
13 // static
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)
23 : context_(context),
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_)
40 delete this;
43 void KeepAliveImpl::OnShutdown(ExtensionRegistry* registry) {
44 delete this;
47 void KeepAliveImpl::OnDisconnected() {
48 ProcessManager::Get(context_)->DecrementLazyKeepaliveCount(extension_);
51 } // namespace extensions