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

Side by Side Diff: chrome/browser/extensions/extension_process_manager.cc

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_process_manager.h" 5 #include "chrome/browser/extensions/extension_process_manager.h"
6 6
7 #include "chrome/browser/ui/browser_window.h" 7 #include "chrome/browser/ui/browser_window.h"
8 #include "content/browser/browsing_instance.h" 8 #include "content/browser/browsing_instance.h"
9 #if defined(OS_MACOSX) 9 #if defined(OS_MACOSX)
10 #include "chrome/browser/extensions/extension_host_mac.h" 10 #include "chrome/browser/extensions/extension_host_mac.h"
11 #endif 11 #endif
12 #include "chrome/browser/extensions/extension_host.h" 12 #include "chrome/browser/extensions/extension_host.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/extensions/extension.h" 17 #include "chrome/common/extensions/extension.h"
17 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
18 #include "content/browser/site_instance.h" 19 #include "content/browser/site_instance.h"
19 #include "content/browser/tab_contents/tab_contents.h" 20 #include "content/browser/tab_contents/tab_contents.h"
20 #include "content/common/notification_service.h" 21 #include "content/common/notification_service.h"
21 #include "content/common/notification_type.h"
22 22
23 namespace { 23 namespace {
24 24
25 // Incognito profiles use this process manager. It is mostly a shim that decides 25 // Incognito profiles use this process manager. It is mostly a shim that decides
26 // whether to fall back on the original profile's ExtensionProcessManager based 26 // whether to fall back on the original profile's ExtensionProcessManager based
27 // on whether a given extension uses "split" or "spanning" incognito behavior. 27 // on whether a given extension uses "split" or "spanning" incognito behavior.
28 class IncognitoExtensionProcessManager : public ExtensionProcessManager { 28 class IncognitoExtensionProcessManager : public ExtensionProcessManager {
29 public: 29 public:
30 explicit IncognitoExtensionProcessManager(Profile* profile); 30 explicit IncognitoExtensionProcessManager(Profile* profile);
31 virtual ~IncognitoExtensionProcessManager() {} 31 virtual ~IncognitoExtensionProcessManager() {}
32 virtual ExtensionHost* CreateViewHost(const Extension* extension, 32 virtual ExtensionHost* CreateViewHost(const Extension* extension,
33 const GURL& url, 33 const GURL& url,
34 Browser* browser, 34 Browser* browser,
35 ViewType::Type view_type) OVERRIDE; 35 ViewType::Type view_type) OVERRIDE;
36 virtual void CreateBackgroundHost(const Extension* extension, 36 virtual void CreateBackgroundHost(const Extension* extension,
37 const GURL& url); 37 const GURL& url);
38 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url); 38 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url);
39 virtual RenderProcessHost* GetExtensionProcess(const GURL& url); 39 virtual RenderProcessHost* GetExtensionProcess(const GURL& url);
40 40
41 private: 41 private:
42 // NotificationObserver: 42 // NotificationObserver:
43 virtual void Observe(NotificationType type, 43 virtual void Observe(int type,
44 const NotificationSource& source, 44 const NotificationSource& source,
45 const NotificationDetails& details); 45 const NotificationDetails& details);
46 46
47 // Returns the extension for an URL, which can either be a chrome-extension 47 // Returns the extension for an URL, which can either be a chrome-extension
48 // URL or a web app URL. 48 // URL or a web app URL.
49 const Extension* GetExtensionOrAppByURL(const GURL& url); 49 const Extension* GetExtensionOrAppByURL(const GURL& url);
50 50
51 // Returns true if the extension is allowed to run in incognito mode. 51 // Returns true if the extension is allowed to run in incognito mode.
52 bool IsIncognitoEnabled(const Extension* extension); 52 bool IsIncognitoEnabled(const Extension* extension);
53 53
(...skipping 26 matching lines...) Expand all
80 // static 80 // static
81 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { 81 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) {
82 return (profile->IsOffTheRecord()) ? 82 return (profile->IsOffTheRecord()) ?
83 new IncognitoExtensionProcessManager(profile) : 83 new IncognitoExtensionProcessManager(profile) :
84 new ExtensionProcessManager(profile); 84 new ExtensionProcessManager(profile);
85 } 85 }
86 86
87 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) 87 ExtensionProcessManager::ExtensionProcessManager(Profile* profile)
88 : browsing_instance_(new BrowsingInstance(profile)) { 88 : browsing_instance_(new BrowsingInstance(profile)) {
89 Profile* original_profile = profile->GetOriginalProfile(); 89 Profile* original_profile = profile->GetOriginalProfile();
90 registrar_.Add(this, NotificationType::EXTENSIONS_READY, 90 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY,
91 Source<Profile>(original_profile)); 91 Source<Profile>(original_profile));
92 registrar_.Add(this, NotificationType::EXTENSION_LOADED, 92 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
93 Source<Profile>(original_profile)); 93 Source<Profile>(original_profile));
94 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 94 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
95 Source<Profile>(original_profile)); 95 Source<Profile>(original_profile));
96 registrar_.Add(this, NotificationType::EXTENSION_HOST_DESTROYED, 96 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
97 Source<Profile>(profile)); 97 Source<Profile>(profile));
98 registrar_.Add(this, NotificationType::RENDERER_PROCESS_TERMINATED, 98 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
99 NotificationService::AllSources()); 99 NotificationService::AllSources());
100 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CLOSED, 100 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
101 NotificationService::AllSources()); 101 NotificationService::AllSources());
102 registrar_.Add(this, NotificationType::APP_TERMINATING, 102 registrar_.Add(this, content::NOTIFICATION_APP_TERMINATING,
103 NotificationService::AllSources()); 103 NotificationService::AllSources());
104 } 104 }
105 105
106 ExtensionProcessManager::~ExtensionProcessManager() { 106 ExtensionProcessManager::~ExtensionProcessManager() {
107 VLOG_IF(1, g_log_bug53991) << "~ExtensionProcessManager: " << this; 107 VLOG_IF(1, g_log_bug53991) << "~ExtensionProcessManager: " << this;
108 CloseBackgroundHosts(); 108 CloseBackgroundHosts();
109 DCHECK(background_hosts_.empty()); 109 DCHECK(background_hosts_.empty());
110 } 110 }
111 111
112 ExtensionHost* ExtensionProcessManager::CreateViewHost( 112 ExtensionHost* ExtensionProcessManager::CreateViewHost(
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 } 262 }
263 263
264 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { 264 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) {
265 return browsing_instance_->GetSiteInstanceForURL(url); 265 return browsing_instance_->GetSiteInstanceForURL(url);
266 } 266 }
267 267
268 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { 268 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const {
269 return all_hosts_.find(host) != all_hosts_.end(); 269 return all_hosts_.find(host) != all_hosts_.end();
270 } 270 }
271 271
272 void ExtensionProcessManager::Observe(NotificationType type, 272 void ExtensionProcessManager::Observe(int type,
273 const NotificationSource& source, 273 const NotificationSource& source,
274 const NotificationDetails& details) { 274 const NotificationDetails& details) {
275 switch (type.value) { 275 switch (type) {
276 case NotificationType::EXTENSIONS_READY: { 276 case chrome::NOTIFICATION_EXTENSIONS_READY: {
277 CreateBackgroundHosts(this, 277 CreateBackgroundHosts(this,
278 Source<Profile>(source).ptr()->GetExtensionService()->extensions()); 278 Source<Profile>(source).ptr()->GetExtensionService()->extensions());
279 break; 279 break;
280 } 280 }
281 281
282 case NotificationType::EXTENSION_LOADED: { 282 case chrome::NOTIFICATION_EXTENSION_LOADED: {
283 ExtensionService* service = 283 ExtensionService* service =
284 Source<Profile>(source).ptr()->GetExtensionService(); 284 Source<Profile>(source).ptr()->GetExtensionService();
285 if (service->is_ready()) { 285 if (service->is_ready()) {
286 const Extension* extension = Details<const Extension>(details).ptr(); 286 const Extension* extension = Details<const Extension>(details).ptr();
287 ::CreateBackgroundHost(this, extension); 287 ::CreateBackgroundHost(this, extension);
288 } 288 }
289 break; 289 break;
290 } 290 }
291 291
292 case NotificationType::EXTENSION_UNLOADED: { 292 case chrome::NOTIFICATION_EXTENSION_UNLOADED: {
293 const Extension* extension = 293 const Extension* extension =
294 Details<UnloadedExtensionInfo>(details)->extension; 294 Details<UnloadedExtensionInfo>(details)->extension;
295 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); 295 for (ExtensionHostSet::iterator iter = background_hosts_.begin();
296 iter != background_hosts_.end(); ++iter) { 296 iter != background_hosts_.end(); ++iter) {
297 ExtensionHost* host = *iter; 297 ExtensionHost* host = *iter;
298 if (host->extension_id() == extension->id()) { 298 if (host->extension_id() == extension->id()) {
299 delete host; 299 delete host;
300 // |host| should deregister itself from our structures. 300 // |host| should deregister itself from our structures.
301 DCHECK(background_hosts_.find(host) == background_hosts_.end()); 301 DCHECK(background_hosts_.find(host) == background_hosts_.end());
302 break; 302 break;
303 } 303 }
304 } 304 }
305 break; 305 break;
306 } 306 }
307 307
308 case NotificationType::EXTENSION_HOST_DESTROYED: { 308 case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
309 ExtensionHost* host = Details<ExtensionHost>(details).ptr(); 309 ExtensionHost* host = Details<ExtensionHost>(details).ptr();
310 all_hosts_.erase(host); 310 all_hosts_.erase(host);
311 background_hosts_.erase(host); 311 background_hosts_.erase(host);
312 break; 312 break;
313 } 313 }
314 314
315 case NotificationType::RENDERER_PROCESS_TERMINATED: 315 case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED:
316 case NotificationType::RENDERER_PROCESS_CLOSED: { 316 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED: {
317 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr(); 317 RenderProcessHost* host = Source<RenderProcessHost>(source).ptr();
318 UnregisterExtensionProcess(host->id()); 318 UnregisterExtensionProcess(host->id());
319 break; 319 break;
320 } 320 }
321 321
322 case NotificationType::APP_TERMINATING: { 322 case content::NOTIFICATION_APP_TERMINATING: {
323 // Close background hosts when the last browser is closed so that they 323 // Close background hosts when the last browser is closed so that they
324 // have time to shutdown various objects on different threads. Our 324 // have time to shutdown various objects on different threads. Our
325 // destructor is called too late in the shutdown sequence. 325 // destructor is called too late in the shutdown sequence.
326 CloseBackgroundHosts(); 326 CloseBackgroundHosts();
327 break; 327 break;
328 } 328 }
329 329
330 default: 330 default:
331 NOTREACHED(); 331 NOTREACHED();
332 } 332 }
333 } 333 }
334 334
335 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, 335 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host,
336 bool is_background) { 336 bool is_background) {
337 DCHECK_EQ(browsing_instance_->profile(), host->profile()); 337 DCHECK_EQ(browsing_instance_->profile(), host->profile());
338 338
339 all_hosts_.insert(host); 339 all_hosts_.insert(host);
340 if (is_background) 340 if (is_background)
341 background_hosts_.insert(host); 341 background_hosts_.insert(host);
342 NotificationService::current()->Notify( 342 NotificationService::current()->Notify(
343 NotificationType::EXTENSION_HOST_CREATED, 343 chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
344 Source<ExtensionProcessManager>(this), 344 Source<ExtensionProcessManager>(this),
345 Details<ExtensionHost>(host)); 345 Details<ExtensionHost>(host));
346 } 346 }
347 347
348 void ExtensionProcessManager::CloseBackgroundHosts() { 348 void ExtensionProcessManager::CloseBackgroundHosts() {
349 VLOG_IF(1, g_log_bug53991) << "CloseBackgroundHosts: " << this; 349 VLOG_IF(1, g_log_bug53991) << "CloseBackgroundHosts: " << this;
350 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); 350 for (ExtensionHostSet::iterator iter = background_hosts_.begin();
351 iter != background_hosts_.end(); ) { 351 iter != background_hosts_.end(); ) {
352 ExtensionHostSet::iterator current = iter++; 352 ExtensionHostSet::iterator current = iter++;
353 delete *current; 353 delete *current;
354 } 354 }
355 } 355 }
356 356
357 // 357 //
358 // IncognitoExtensionProcessManager 358 // IncognitoExtensionProcessManager
359 // 359 //
360 360
361 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( 361 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager(
362 Profile* profile) 362 Profile* profile)
363 : ExtensionProcessManager(profile), 363 : ExtensionProcessManager(profile),
364 original_manager_(profile->GetOriginalProfile()-> 364 original_manager_(profile->GetOriginalProfile()->
365 GetExtensionProcessManager()) { 365 GetExtensionProcessManager()) {
366 DCHECK(profile->IsOffTheRecord()); 366 DCHECK(profile->IsOffTheRecord());
367 367
368 registrar_.Add(this, NotificationType::BROWSER_WINDOW_READY, 368 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
369 NotificationService::AllSources()); 369 NotificationService::AllSources());
370 } 370 }
371 371
372 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost( 372 ExtensionHost* IncognitoExtensionProcessManager::CreateViewHost(
373 const Extension* extension, 373 const Extension* extension,
374 const GURL& url, 374 const GURL& url,
375 Browser* browser, 375 Browser* browser,
376 ViewType::Type view_type) { 376 ViewType::Type view_type) {
377 if (extension->incognito_split_mode()) { 377 if (extension->incognito_split_mode()) {
378 if (IsIncognitoEnabled(extension)) { 378 if (IsIncognitoEnabled(extension)) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 432 }
433 433
434 bool IncognitoExtensionProcessManager::IsIncognitoEnabled( 434 bool IncognitoExtensionProcessManager::IsIncognitoEnabled(
435 const Extension* extension) { 435 const Extension* extension) {
436 ExtensionService* service = 436 ExtensionService* service =
437 browsing_instance_->profile()->GetExtensionService(); 437 browsing_instance_->profile()->GetExtensionService();
438 return service && service->IsIncognitoEnabled(extension->id()); 438 return service && service->IsIncognitoEnabled(extension->id());
439 } 439 }
440 440
441 void IncognitoExtensionProcessManager::Observe( 441 void IncognitoExtensionProcessManager::Observe(
442 NotificationType type, 442 int type,
443 const NotificationSource& source, 443 const NotificationSource& source,
444 const NotificationDetails& details) { 444 const NotificationDetails& details) {
445 switch (type.value) { 445 switch (type) {
446 case NotificationType::BROWSER_WINDOW_READY: { 446 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
447 // We want to spawn our background hosts as soon as the user opens an 447 // We want to spawn our background hosts as soon as the user opens an
448 // incognito window. Watch for new browsers and create the hosts if 448 // incognito window. Watch for new browsers and create the hosts if
449 // it matches our profile. 449 // it matches our profile.
450 Browser* browser = Source<Browser>(source).ptr(); 450 Browser* browser = Source<Browser>(source).ptr();
451 if (browser->profile() == browsing_instance_->profile()) { 451 if (browser->profile() == browsing_instance_->profile()) {
452 // On Chrome OS, a login screen is implemented as a browser. 452 // On Chrome OS, a login screen is implemented as a browser.
453 // This browser has no extension service. In this case, 453 // This browser has no extension service. In this case,
454 // service will be NULL. 454 // service will be NULL.
455 ExtensionService* service = 455 ExtensionService* service =
456 browsing_instance_->profile()->GetExtensionService(); 456 browsing_instance_->profile()->GetExtensionService();
457 if (service && service->is_ready()) 457 if (service && service->is_ready())
458 CreateBackgroundHosts(this, service->extensions()); 458 CreateBackgroundHosts(this, service->extensions());
459 } 459 }
460 break; 460 break;
461 } 461 }
462 default: 462 default:
463 ExtensionProcessManager::Observe(type, source, details); 463 ExtensionProcessManager::Observe(type, source, details);
464 break; 464 break;
465 } 465 }
466 } 466 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_process_manager.h ('k') | chrome/browser/extensions/extension_processes_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698