Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: chrome/browser/extensions/api/runtime/runtime_api.cc

Issue 147923005: Split ExtensionSystem interface from ExtensionSystemImpl implementation, part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/runtime/runtime_api.h" 5 #include "chrome/browser/extensions/api/runtime/runtime_api.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/extension_host.h" 14 #include "chrome/browser/extensions/extension_host.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_system.h"
17 #include "chrome/browser/extensions/updater/extension_updater.h" 16 #include "chrome/browser/extensions/updater/extension_updater.h"
18 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/browser_navigator.h" 20 #include "chrome/browser/ui/browser_navigator.h"
22 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/common/extensions/api/runtime.h" 22 #include "chrome/common/extensions/api/runtime.h"
24 #include "chrome/common/omaha_query_params/omaha_query_params.h" 23 #include "chrome/common/omaha_query_params/omaha_query_params.h"
25 #include "content/public/browser/child_process_security_policy.h" 24 #include "content/public/browser/child_process_security_policy.h"
26 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
28 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
29 #include "extensions/browser/event_router.h" 28 #include "extensions/browser/event_router.h"
30 #include "extensions/browser/extension_registry.h" 29 #include "extensions/browser/extension_registry.h"
30 #include "extensions/browser/extension_system.h"
31 #include "extensions/browser/extensions_browser_client.h" 31 #include "extensions/browser/extensions_browser_client.h"
32 #include "extensions/browser/lazy_background_task_queue.h" 32 #include "extensions/browser/lazy_background_task_queue.h"
33 #include "extensions/browser/process_manager.h" 33 #include "extensions/browser/process_manager.h"
34 #include "extensions/common/error_utils.h" 34 #include "extensions/common/error_utils.h"
35 #include "extensions/common/extension.h" 35 #include "extensions/common/extension.h"
36 #include "extensions/common/manifest_handlers/background_info.h" 36 #include "extensions/common/manifest_handlers/background_info.h"
37 #include "url/gurl.h" 37 #include "url/gurl.h"
38 #include "webkit/browser/fileapi/isolated_context.h" 38 #include "webkit/browser/fileapi/isolated_context.h"
39 39
40 #if defined(OS_CHROMEOS) 40 #if defined(OS_CHROMEOS)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 return; 84 return;
85 85
86 // Don't send onStartup events to incognito browser contexts. 86 // Don't send onStartup events to incognito browser contexts.
87 if (browser_context->IsOffTheRecord()) 87 if (browser_context->IsOffTheRecord())
88 return; 88 return;
89 89
90 if (ExtensionsBrowserClient::Get()->IsShuttingDown() || 90 if (ExtensionsBrowserClient::Get()->IsShuttingDown() ||
91 !ExtensionsBrowserClient::Get()->IsValidContext(browser_context)) 91 !ExtensionsBrowserClient::Get()->IsValidContext(browser_context))
92 return; 92 return;
93 ExtensionSystem* system = 93 ExtensionSystem* system =
94 ExtensionSystem::GetForBrowserContext(browser_context); 94 ExtensionSystem::Get(browser_context);
95 if (!system) 95 if (!system)
96 return; 96 return;
97 97
98 // If this is a persistent background page, we want to wait for it to load 98 // If this is a persistent background page, we want to wait for it to load
99 // (it might not be ready, since this is startup). But only enqueue once. 99 // (it might not be ready, since this is startup). But only enqueue once.
100 // If it fails to load the first time, don't bother trying again. 100 // If it fails to load the first time, don't bother trying again.
101 const Extension* extension = 101 const Extension* extension =
102 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID( 102 ExtensionRegistry::Get(browser_context)->enabled_extensions().GetByID(
103 extension_id); 103 extension_id);
104 if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) && 104 if (extension && BackgroundInfo::HasPersistentBackgroundPage(extension) &&
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 content::Source<BrowserContext>(context)); 153 content::Source<BrowserContext>(context));
154 154
155 // Check if registered events are up-to-date. We can only do this once 155 // Check if registered events are up-to-date. We can only do this once
156 // per browser context, since it updates internal state when called. 156 // per browser context, since it updates internal state when called.
157 dispatch_chrome_updated_event_ = 157 dispatch_chrome_updated_event_ =
158 ExtensionsBrowserClient::Get()->DidVersionUpdate(browser_context_); 158 ExtensionsBrowserClient::Get()->DidVersionUpdate(browser_context_);
159 } 159 }
160 160
161 RuntimeAPI::~RuntimeAPI() { 161 RuntimeAPI::~RuntimeAPI() {
162 if (registered_for_updates_) { 162 if (registered_for_updates_) {
163 ExtensionSystem::GetForBrowserContext(browser_context_)-> 163 ExtensionSystem::Get(browser_context_)->
164 extension_service()->RemoveUpdateObserver(this); 164 extension_service()->RemoveUpdateObserver(this);
165 } 165 }
166 } 166 }
167 167
168 void RuntimeAPI::Observe(int type, 168 void RuntimeAPI::Observe(int type,
169 const content::NotificationSource& source, 169 const content::NotificationSource& source,
170 const content::NotificationDetails& details) { 170 const content::NotificationDetails& details) {
171 switch (type) { 171 switch (type) {
172 case chrome::NOTIFICATION_EXTENSIONS_READY: { 172 case chrome::NOTIFICATION_EXTENSIONS_READY: {
173 OnExtensionsReady(); 173 OnExtensionsReady();
(...skipping 22 matching lines...) Expand all
196 break; 196 break;
197 } 197 }
198 } 198 }
199 199
200 void RuntimeAPI::OnExtensionsReady() { 200 void RuntimeAPI::OnExtensionsReady() {
201 // We're done restarting Chrome after an update. 201 // We're done restarting Chrome after an update.
202 dispatch_chrome_updated_event_ = false; 202 dispatch_chrome_updated_event_ = false;
203 203
204 registered_for_updates_ = true; 204 registered_for_updates_ = true;
205 205
206 ExtensionSystem::GetForBrowserContext(browser_context_)->extension_service()-> 206 ExtensionSystem::Get(browser_context_)->extension_service()->
207 AddUpdateObserver(this); 207 AddUpdateObserver(this);
208 } 208 }
209 209
210 void RuntimeAPI::OnExtensionLoaded(const Extension* extension) { 210 void RuntimeAPI::OnExtensionLoaded(const Extension* extension) {
211 if (!dispatch_chrome_updated_event_) 211 if (!dispatch_chrome_updated_event_)
212 return; 212 return;
213 213
214 // Dispatch the onInstalled event with reason "chrome_update". 214 // Dispatch the onInstalled event with reason "chrome_update".
215 base::MessageLoop::current()->PostTask( 215 base::MessageLoop::current()->PostTask(
216 FROM_HERE, 216 FROM_HERE,
217 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, 217 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent,
218 browser_context_, 218 browser_context_,
219 extension->id(), 219 extension->id(),
220 Version(), 220 Version(),
221 true)); 221 true));
222 } 222 }
223 223
224 void RuntimeAPI::OnExtensionInstalled(const Extension* extension) { 224 void RuntimeAPI::OnExtensionInstalled(const Extension* extension) {
225 // Ephemeral apps are not considered to be installed and do not receive 225 // Ephemeral apps are not considered to be installed and do not receive
226 // the onInstalled() event. 226 // the onInstalled() event.
227 if (extension->is_ephemeral()) 227 if (extension->is_ephemeral())
228 return; 228 return;
229 229
230 // Get the previous version to check if this is an upgrade. 230 // Get the previous version to check if this is an upgrade.
231 ExtensionService* service = ExtensionSystem::GetForBrowserContext( 231 ExtensionService* service = ExtensionSystem::Get(
232 browser_context_)->extension_service(); 232 browser_context_)->extension_service();
233 const Extension* old = service->GetExtensionById(extension->id(), true); 233 const Extension* old = service->GetExtensionById(extension->id(), true);
234 Version old_version; 234 Version old_version;
235 if (old) 235 if (old)
236 old_version = *old->version(); 236 old_version = *old->version();
237 237
238 // Dispatch the onInstalled event. 238 // Dispatch the onInstalled event.
239 base::MessageLoop::current()->PostTask( 239 base::MessageLoop::current()->PostTask(
240 FROM_HERE, 240 FROM_HERE,
241 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, 241 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 276 }
277 277
278 // static 278 // static
279 void RuntimeEventRouter::DispatchOnInstalledEvent( 279 void RuntimeEventRouter::DispatchOnInstalledEvent(
280 content::BrowserContext* context, 280 content::BrowserContext* context,
281 const std::string& extension_id, 281 const std::string& extension_id,
282 const Version& old_version, 282 const Version& old_version,
283 bool chrome_updated) { 283 bool chrome_updated) {
284 if (!ExtensionsBrowserClient::Get()->IsValidContext(context)) 284 if (!ExtensionsBrowserClient::Get()->IsValidContext(context))
285 return; 285 return;
286 ExtensionSystem* system = ExtensionSystem::GetForBrowserContext(context); 286 ExtensionSystem* system = ExtensionSystem::Get(context);
287 if (!system) 287 if (!system)
288 return; 288 return;
289 289
290 scoped_ptr<base::ListValue> event_args(new base::ListValue()); 290 scoped_ptr<base::ListValue> event_args(new base::ListValue());
291 base::DictionaryValue* info = new base::DictionaryValue(); 291 base::DictionaryValue* info = new base::DictionaryValue();
292 event_args->Append(info); 292 event_args->Append(info);
293 if (old_version.IsValid()) { 293 if (old_version.IsValid()) {
294 info->SetString(kInstallReason, kInstallReasonUpdate); 294 info->SetString(kInstallReason, kInstallReasonUpdate);
295 info->SetString(kInstallPreviousVersion, old_version.GetString()); 295 info->SetString(kInstallPreviousVersion, old_version.GetString());
296 } else if (chrome_updated) { 296 } else if (chrome_updated) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 content::ChildProcessSecurityPolicy::GetInstance(); 583 content::ChildProcessSecurityPolicy::GetInstance();
584 policy->GrantReadFileSystem(renderer_id, filesystem_id); 584 policy->GrantReadFileSystem(renderer_id, filesystem_id);
585 base::DictionaryValue* dict = new base::DictionaryValue(); 585 base::DictionaryValue* dict = new base::DictionaryValue();
586 SetResult(dict); 586 SetResult(dict);
587 dict->SetString("fileSystemId", filesystem_id); 587 dict->SetString("fileSystemId", filesystem_id);
588 dict->SetString("baseName", relative_path); 588 dict->SetString("baseName", relative_path);
589 return true; 589 return true;
590 } 590 }
591 591
592 } // namespace extensions 592 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698