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 virtual ~ShellExtensionsDelegate() {} | |
23 | |
24 private: | |
25 // ExtensionsDelegate: | |
26 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { | |
27 return context_; | |
28 } | |
29 virtual const extensions::ExtensionSet& GetInstalledExtensions() OVERRIDE { | |
30 shell_extensions_.Clear(); | |
31 if (extension_system_->extension()) | |
32 shell_extensions_.Insert(extension_system_->extension()); | |
33 return shell_extensions_; | |
34 } | |
35 virtual void LaunchApp(const std::string& app_id) OVERRIDE { | |
36 extension_system_->LaunchApp(); | |
37 } | |
38 | |
39 content::BrowserContext* context_; | |
40 extensions::ShellExtensionSystem* extension_system_; | |
41 extensions::ExtensionSet shell_extensions_; | |
42 | |
43 DISALLOW_COPY_AND_ASSIGN(ShellExtensionsDelegate); | |
44 }; | |
45 | |
46 } // namespace | |
47 | |
48 ExtensionsDelegate::ExtensionsDelegate() { | |
49 DCHECK(!instance); | |
50 instance = this; | |
51 } | |
52 | |
53 ExtensionsDelegate::~ExtensionsDelegate() { | |
54 DCHECK(instance); | |
55 instance = NULL; | |
56 } | |
57 | |
58 // static | |
59 ExtensionsDelegate* ExtensionsDelegate::Get(content::BrowserContext* context) { | |
60 DCHECK(instance); | |
61 DCHECK_EQ(context, instance->GetBrowserContext()); | |
62 return instance; | |
63 } | |
64 | |
65 // static | |
66 void ExtensionsDelegate::CreateExtensionsDelegateForShell( | |
67 content::BrowserContext* context) { | |
68 new ShellExtensionsDelegate(context); | |
69 } | |
70 | |
71 // static | |
72 void ExtensionsDelegate::Shutdown() { | |
73 DCHECK(instance); | |
74 delete instance; | |
75 } | |
76 | |
77 } // namespace athena | |
OLD | NEW |