cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / extensions / shell / browser / shell_extension_system.cc
blob70314524772dbd1895849a104af7ca2918d9c42a
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/null_app_sorting.h"
22 #include "extensions/browser/quota_service.h"
23 #include "extensions/browser/runtime_data.h"
24 #include "extensions/common/constants.h"
25 #include "extensions/common/file_util.h"
27 using content::BrowserContext;
28 using content::BrowserThread;
30 namespace extensions {
32 ShellExtensionSystem::ShellExtensionSystem(BrowserContext* browser_context)
33 : browser_context_(browser_context), weak_factory_(this) {}
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(
63 extension.get(),
64 base::Bind(
65 &ShellExtensionSystem::OnExtensionRegisteredWithRequestContexts,
66 weak_factory_.GetWeakPtr(), extension));
68 content::NotificationService::current()->Notify(
69 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED,
70 content::Source<BrowserContext>(browser_context_),
71 content::Details<const Extension>(extension.get()));
73 return extension.get();
76 void ShellExtensionSystem::Init() {
77 // Inform the rest of the extensions system to start.
78 ready_.Signal();
79 content::NotificationService::current()->Notify(
80 extensions::NOTIFICATION_EXTENSIONS_READY_DEPRECATED,
81 content::Source<BrowserContext>(browser_context_),
82 content::NotificationService::NoDetails());
85 void ShellExtensionSystem::LaunchApp(const ExtensionId& extension_id) {
86 // Send the onLaunched event.
87 DCHECK(ExtensionRegistry::Get(browser_context_)
88 ->enabled_extensions()
89 .Contains(extension_id));
90 const Extension* extension = ExtensionRegistry::Get(browser_context_)
91 ->enabled_extensions()
92 .GetByID(extension_id);
93 AppRuntimeEventRouter::DispatchOnLaunchedEvent(
94 browser_context_, extension, extensions::SOURCE_UNTRACKED);
97 void ShellExtensionSystem::Shutdown() {
100 void ShellExtensionSystem::InitForRegularProfile(bool extensions_enabled) {
101 runtime_data_.reset(
102 new RuntimeData(ExtensionRegistry::Get(browser_context_)));
103 quota_service_.reset(new QuotaService);
104 app_sorting_.reset(new NullAppSorting);
107 ExtensionService* ShellExtensionSystem::extension_service() {
108 return nullptr;
111 RuntimeData* ShellExtensionSystem::runtime_data() {
112 return runtime_data_.get();
115 ManagementPolicy* ShellExtensionSystem::management_policy() {
116 return nullptr;
119 SharedUserScriptMaster* ShellExtensionSystem::shared_user_script_master() {
120 return nullptr;
123 StateStore* ShellExtensionSystem::state_store() {
124 return nullptr;
127 StateStore* ShellExtensionSystem::rules_store() {
128 return nullptr;
131 InfoMap* ShellExtensionSystem::info_map() {
132 if (!info_map_.get())
133 info_map_ = new InfoMap;
134 return info_map_.get();
137 QuotaService* ShellExtensionSystem::quota_service() {
138 return quota_service_.get();
141 AppSorting* ShellExtensionSystem::app_sorting() {
142 return app_sorting_.get();
145 void ShellExtensionSystem::RegisterExtensionWithRequestContexts(
146 const Extension* extension,
147 const base::Closure& callback) {
148 BrowserThread::PostTaskAndReply(BrowserThread::IO, FROM_HERE,
149 base::Bind(&InfoMap::AddExtension, info_map(),
150 make_scoped_refptr(extension),
151 base::Time::Now(), false, false),
152 callback);
155 void ShellExtensionSystem::UnregisterExtensionWithRequestContexts(
156 const std::string& extension_id,
157 const UnloadedExtensionInfo::Reason reason) {
160 const OneShotEvent& ShellExtensionSystem::ready() const {
161 return ready_;
164 ContentVerifier* ShellExtensionSystem::content_verifier() {
165 return nullptr;
168 scoped_ptr<ExtensionSet> ShellExtensionSystem::GetDependentExtensions(
169 const Extension* extension) {
170 return make_scoped_ptr(new ExtensionSet());
173 void ShellExtensionSystem::OnExtensionRegisteredWithRequestContexts(
174 scoped_refptr<Extension> extension) {
175 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context_);
176 registry->AddReady(extension);
177 registry->TriggerOnReady(extension.get());
180 } // namespace extensions