Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / shell / browser / shell_extension_system.cc
blobe5f5a52472b07da6d4efa5b00af78f29678fe126
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/shell/browser/shell_extension_system.h"
7 #include <string>
9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_source.h"
16 #include "extensions/browser/api/app_runtime/app_runtime_api.h"
17 #include "extensions/browser/extension_prefs.h"
18 #include "extensions/browser/extension_registry.h"
19 #include "extensions/browser/info_map.h"
20 #include "extensions/browser/notification_types.h"
21 #include "extensions/browser/quota_service.h"
22 #include "extensions/browser/runtime_data.h"
23 #include "extensions/common/constants.h"
24 #include "extensions/common/file_util.h"
26 using content::BrowserContext;
27 using content::BrowserThread;
29 namespace extensions {
31 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context)
32 : browser_context_(browser_context) {
35 ShellExtensionSystem::~ShellExtensionSystem() {
38 const Extension* ShellExtensionSystem::LoadApp(const base::FilePath& app_dir) {
39 // app_shell only supports unpacked extensions.
40 // NOTE: If you add packed extension support consider removing the flag
41 // FOLLOW_SYMLINKS_ANYWHERE below. Packed extensions should not have symlinks.
42 CHECK(base::DirectoryExists(app_dir)) << app_dir.AsUTF8Unsafe();
43 int load_flags = Extension::FOLLOW_SYMLINKS_ANYWHERE;
44 std::string load_error;
45 scoped_refptr<Extension> extension = file_util::LoadExtension(
46 app_dir, Manifest::COMMAND_LINE, load_flags, &load_error);
47 if (!extension.get()) {
48 LOG(ERROR) << "Loading extension at " << app_dir.value()
49 << " failed with: " << load_error;
50 return nullptr;
53 // TODO(jamescook): We may want to do some of these things here:
54 // * Create a PermissionsUpdater.
55 // * Call PermissionsUpdater::GrantActivePermissions().
56 // * Call ExtensionService::SatisfyImports().
57 // * Call ExtensionPrefs::OnExtensionInstalled().
58 // * Send NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED.
60 ExtensionRegistry::Get(browser_context_)->AddEnabled(extension.get());
62 RegisterExtensionWithRequestContexts(extension.get());
64 content::NotificationService::current()->Notify(
65 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
66 content::Source<BrowserContext>(browser_context_),
67 content::Details<const Extension>(extension.get()));
69 return extension.get();
72 void ShellExtensionSystem::Init() {
73 // Inform the rest of the extensions system to start.
74 ready_.Signal();
75 content::NotificationService::current()->Notify(
76 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
77 content::Source<BrowserContext>(browser_context_),
78 content::NotificationService::NoDetails());
81 void ShellExtensionSystem::LaunchApp(const ExtensionId& extension_id) {
82 // Send the onLaunched event.
83 DCHECK(ExtensionRegistry::Get(browser_context_)
84 ->enabled_extensions()
85 .Contains(extension_id));
86 const Extension* extension = ExtensionRegistry::Get(browser_context_)
87 ->enabled_extensions()
88 .GetByID(extension_id);
89 AppRuntimeEventRouter::DispatchOnLaunchedEvent(
90 browser_context_, extension, extensions::SOURCE_UNTRACKED);
93 void ShellExtensionSystem::Shutdown() {
96 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
97 runtime_data_.reset(
98 new RuntimeData(ExtensionRegistry::Get(browser_context_)));
99 quota_service_.reset(new QuotaService);
102 ExtensionService* ShellExtensionSystem::extension_service() {
103 return nullptr;
106 RuntimeData* ShellExtensionSystem::runtime_data() {
107 return runtime_data_.get();
110 ManagementPolicy* ShellExtensionSystem::management_policy() {
111 return nullptr;
114 SharedUserScriptMaster* ShellExtensionSystem::shared_user_script_master() {
115 return nullptr;
118 StateStore* ShellExtensionSystem::state_store() {
119 return nullptr;
122 StateStore* ShellExtensionSystem::rules_store() {
123 return nullptr;
126 InfoMap* ShellExtensionSystem::info_map() {
127 if (!info_map_.get())
128 info_map_ = new InfoMap;
129 return info_map_.get();
132 QuotaService* ShellExtensionSystem::quota_service() {
133 return quota_service_.get();
136 void ShellExtensionSystem::RegisterExtensionWithRequestContexts(
137 const Extension* extension) {
138 BrowserThread::PostTask(BrowserThread::IO,
139 FROM_HERE,
140 base::Bind(&InfoMap::AddExtension,
141 info_map(),
142 make_scoped_refptr(extension),
143 base::Time::Now(),
144 false,
145 false));
148 void ShellExtensionSystem::UnregisterExtensionWithRequestContexts(
149 const std::string& extension_id,
150 const UnloadedExtensionInfo::Reason reason) {
153 const OneShotEvent& ShellExtensionSystem::ready() const {
154 return ready_;
157 ContentVerifier* ShellExtensionSystem::content_verifier() {
158 return nullptr;
161 scoped_ptr<ExtensionSet> ShellExtensionSystem::GetDependentExtensions(
162 const Extension* extension) {
163 return make_scoped_ptr(new ExtensionSet());
166 } // namespace extensions