OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "athena/extensions/public/extensions_delegate.h" |
| 6 #include "base/macros.h" |
| 7 #include "extensions/common/extension_set.h" |
| 8 #include "extensions/shell/browser/shell_extension_system.h" |
| 9 |
| 10 namespace athena { |
| 11 namespace { |
| 12 |
| 13 ExtensionsDelegate* instance = NULL; |
| 14 |
| 15 class ShellExtensionsDelegate : public ExtensionsDelegate { |
| 16 public: |
| 17 explicit ShellExtensionsDelegate(content::BrowserContext* context) |
| 18 : context_(context), |
| 19 extension_system_(static_cast<extensions::ShellExtensionSystem*>( |
| 20 extensions::ExtensionSystem::Get(context))) { |
| 21 } |
| 22 |
| 23 virtual ~ShellExtensionsDelegate() {} |
| 24 |
| 25 private: |
| 26 // ExtensionsDelegate: |
| 27 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { |
| 28 return context_; |
| 29 } |
| 30 virtual extensions::ExtensionSet* GetInstalledExtensions() OVERRIDE { |
| 31 shell_extensions_.Clear(); |
| 32 if (extension_system_->extension()) |
| 33 shell_extensions_.Insert(extension_system_->extension()); |
| 34 return &shell_extensions_; |
| 35 } |
| 36 virtual void LaunchApp(const std::string& app_id) OVERRIDE { |
| 37 extension_system_->LaunchApp(); |
| 38 } |
| 39 |
| 40 content::BrowserContext* context_; |
| 41 extensions::ShellExtensionSystem* extension_system_; |
| 42 extensions::ExtensionSet shell_extensions_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(ShellExtensionsDelegate); |
| 45 }; |
| 46 |
| 47 } // namespace |
| 48 |
| 49 ExtensionsDelegate::ExtensionsDelegate() { |
| 50 DCHECK(!instance); |
| 51 instance = this; |
| 52 } |
| 53 |
| 54 ExtensionsDelegate::~ExtensionsDelegate() { |
| 55 DCHECK(instance); |
| 56 instance = NULL; |
| 57 } |
| 58 |
| 59 // static |
| 60 ExtensionsDelegate* ExtensionsDelegate::Get(content::BrowserContext* context) { |
| 61 DCHECK(instance); |
| 62 DCHECK_EQ(context, instance->GetBrowserContext()); |
| 63 return instance; |
| 64 } |
| 65 |
| 66 // static |
| 67 void ExtensionsDelegate::InitExtensionsDelegateForShell( |
| 68 content::BrowserContext* context) { |
| 69 new ShellExtensionsDelegate(context); |
| 70 } |
| 71 |
| 72 // static |
| 73 void ExtensionsDelegate::Shutdown() { |
| 74 DCHECK(instance); |
| 75 delete instance; |
| 76 } |
| 77 |
| 78 } // namespace athena |
OLD | NEW |