| 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 #ifndef EXTENSIONS_BROWSER_MOJO_KEEP_ALIVE_IMPL_H_ | 5 #ifndef EXTENSIONS_BROWSER_MOJO_KEEP_ALIVE_IMPL_H_ |
| 6 #define EXTENSIONS_BROWSER_MOJO_KEEP_ALIVE_IMPL_H_ | 6 #define EXTENSIONS_BROWSER_MOJO_KEEP_ALIVE_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/scoped_observer.h" | 10 #include "base/scoped_observer.h" |
| 11 #include "extensions/browser/extension_registry_observer.h" | 11 #include "extensions/browser/extension_registry_observer.h" |
| 12 #include "extensions/common/mojo/keep_alive.mojom.h" | 12 #include "extensions/common/mojo/keep_alive.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/interface_request.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 15 | 14 |
| 16 namespace content { | 15 namespace content { |
| 17 class BrowserContext; | 16 class BrowserContext; |
| 18 } | 17 } |
| 19 | 18 |
| 20 namespace extensions { | 19 namespace extensions { |
| 21 class Extension; | 20 class Extension; |
| 22 | 21 |
| 23 // An RAII mojo service implementation for extension keep alives. This adds a | 22 // An RAII mojo service implementation for extension keep alives. This adds a |
| 24 // keep alive on construction and removes it on destruction. | 23 // keep alive on construction and removes it on destruction. |
| 25 class KeepAliveImpl : public KeepAlive, public ExtensionRegistryObserver { | 24 class KeepAliveImpl : public KeepAlive, public ExtensionRegistryObserver { |
| 26 public: | 25 public: |
| 27 // Create a keep alive for |extension| running in |context| and connect it to | 26 // Create a keep alive for |extension| running in |context| and connect it to |
| 28 // |request|. When the requester closes its pipe, the keep alive ends. | 27 // |request|. When the requester closes its pipe, the keep alive ends. |
| 29 static void Create(content::BrowserContext* context, | 28 static void Create(content::BrowserContext* context, |
| 30 const Extension* extension, | 29 const Extension* extension, |
| 31 mojo::InterfaceRequest<KeepAlive> request); | 30 KeepAliveRequest request); |
| 32 | 31 |
| 33 private: | 32 private: |
| 34 KeepAliveImpl(content::BrowserContext* context, | 33 KeepAliveImpl(content::BrowserContext* context, |
| 35 const Extension* extension, | 34 const Extension* extension, |
| 36 mojo::InterfaceRequest<KeepAlive> request); | 35 KeepAliveRequest request); |
| 37 ~KeepAliveImpl() override; | 36 ~KeepAliveImpl() override; |
| 38 | 37 |
| 39 // ExtensionRegistryObserver overrides. | 38 // ExtensionRegistryObserver overrides. |
| 40 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 39 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 41 const Extension* extension, | 40 const Extension* extension, |
| 42 UnloadedExtensionInfo::Reason reason) override; | 41 UnloadedExtensionInfo::Reason reason) override; |
| 43 void OnShutdown(ExtensionRegistry* registry) override; | 42 void OnShutdown(ExtensionRegistry* registry) override; |
| 44 | 43 |
| 45 // Invoked when the mojo connection is disconnected. | 44 // Invoked when the mojo connection is disconnected. |
| 46 void OnDisconnected(); | 45 void OnDisconnected(); |
| 47 | 46 |
| 48 content::BrowserContext* context_; | 47 content::BrowserContext* context_; |
| 49 const Extension* extension_; | 48 const Extension* extension_; |
| 50 ScopedObserver<ExtensionRegistry, KeepAliveImpl> extension_registry_observer_; | 49 ScopedObserver<ExtensionRegistry, KeepAliveImpl> extension_registry_observer_; |
| 51 mojo::StrongBinding<KeepAlive> binding_; | 50 mojo::Binding<KeepAlive> binding_; |
| 52 | 51 |
| 53 DISALLOW_COPY_AND_ASSIGN(KeepAliveImpl); | 52 DISALLOW_COPY_AND_ASSIGN(KeepAliveImpl); |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 } // namespace extensions | 55 } // namespace extensions |
| 57 | 56 |
| 58 #endif // EXTENSIONS_BROWSER_MOJO_KEEP_ALIVE_IMPL_H_ | 57 #endif // EXTENSIONS_BROWSER_MOJO_KEEP_ALIVE_IMPL_H_ |
| OLD | NEW |