Chromium Code Reviews| 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/extension_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 ExtensionDelegate* instance = NULL; | |
| 14 | |
| 15 class ShellExtensionDelegate : public ExtensionDelegate { | |
| 16 public: | |
| 17 explicit ShellExtensionDelegate(content::BrowserContext* context) | |
| 18 : context_(context), | |
| 19 extension_system_( | |
| 20 static_cast<extensions::ShellExtensionSystem*>( | |
| 21 extensions::ExtensionSystem::Get(context))) { | |
| 22 if (extension_system_->extension()) | |
|
Yoyo Zhou
2014/08/20 20:37:27
I know in the current implementation the extension
oshima
2014/08/20 21:39:21
Done.
| |
| 23 shell_extensions_.Insert(extension_system_->extension()); | |
| 24 } | |
| 25 virtual ~ShellExtensionDelegate() { | |
|
Yoyo Zhou
2014/08/20 20:37:27
nit: line breaks between function definitions
oshima
2014/08/20 21:39:21
Done.
| |
| 26 } | |
| 27 | |
| 28 private: | |
| 29 // ExtensionDelegate: | |
| 30 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { | |
| 31 return context_; | |
| 32 } | |
| 33 virtual extensions::ExtensionSet* GetExtensionSet() OVERRIDE { | |
| 34 return &shell_extensions_; | |
| 35 } | |
| 36 virtual void Launch(const std::string& 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(ShellExtensionDelegate); | |
| 45 }; | |
| 46 | |
| 47 } // namespace | |
| 48 | |
| 49 ExtensionDelegate::ExtensionDelegate() { | |
| 50 DCHECK(!instance); | |
| 51 instance = this; | |
| 52 } | |
| 53 | |
| 54 ExtensionDelegate::~ExtensionDelegate() { | |
| 55 DCHECK(instance); | |
| 56 instance = NULL; | |
| 57 } | |
| 58 | |
| 59 // static | |
| 60 ExtensionDelegate* ExtensionDelegate::Get(content::BrowserContext* context) { | |
| 61 DCHECK(instance); | |
| 62 DCHECK_EQ(context, instance->GetBrowserContext()); | |
| 63 return instance; | |
| 64 } | |
| 65 | |
| 66 // static | |
| 67 void ExtensionDelegate::Shutdown() { | |
| 68 DCHECK(instance); | |
| 69 delete instance; | |
| 70 } | |
| 71 | |
| 72 // static | |
| 73 void ExtensionDelegate::InitExtensionDelegateForShell( | |
| 74 content::BrowserContext* context) { | |
| 75 new ShellExtensionDelegate(context); | |
| 76 } | |
| 77 | |
| 78 } // namespace athena | |
| OLD | NEW |