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

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

Issue 381283002: Refactor code that defers extension background page loading (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase on top of chrome_browser_extensions.gypi GN changes Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chrome_notification_observer.h" 5 #include "chrome/browser/extensions/chrome_notification_observer.h"
6 6
7 #include "base/logging.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/extensions/features/feature_channel.h" 7 #include "chrome/common/extensions/features/feature_channel.h"
12 #include "content/public/browser/notification_service.h" 8 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h" 9 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/render_process_host.h" 10 #include "content/public/browser/render_process_host.h"
15 #include "extensions/browser/extension_system.h"
16 #include "extensions/browser/process_manager.h"
17 #include "extensions/common/extension_messages.h" 11 #include "extensions/common/extension_messages.h"
18 12
19 namespace extensions { 13 namespace extensions {
20 14
21 ChromeNotificationObserver::ChromeNotificationObserver() { 15 ChromeNotificationObserver::ChromeNotificationObserver() {
22 registrar_.Add(this, 16 registrar_.Add(this,
23 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
24 content::NotificationService::AllSources());
25 registrar_.Add(this,
26 content::NOTIFICATION_RENDERER_PROCESS_CREATED, 17 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
27 content::NotificationService::AllBrowserContextsAndSources()); 18 content::NotificationService::AllBrowserContextsAndSources());
28 } 19 }
29 20
30 ChromeNotificationObserver::~ChromeNotificationObserver() {} 21 ChromeNotificationObserver::~ChromeNotificationObserver() {}
31 22
32 void ChromeNotificationObserver::OnBrowserWindowReady(Browser* browser) {
33 Profile* profile = browser->profile();
34 DCHECK(profile);
35
36 // Inform the process manager for this profile that the window is ready.
37 // We continue to observe the notification in case browser windows open for
38 // a related incognito profile or other regular profiles.
39 extensions::ProcessManager* manager =
40 ExtensionSystem::Get(profile)->process_manager();
41 if (!manager) // Tests may not have a process manager.
42 return;
43 DCHECK_EQ(profile, manager->GetBrowserContext());
44 manager->OnBrowserWindowReady();
45
46 // For incognito profiles also inform the original profile's process manager
47 // that the window is ready. This will usually be a no-op because the
48 // original profile's process manager should have been informed when the
49 // non-incognito window opened.
50 if (profile->IsOffTheRecord()) {
51 Profile* original_profile = profile->GetOriginalProfile();
52 extensions::ProcessManager* original_manager =
53 ExtensionSystem::Get(original_profile)->process_manager();
54 DCHECK(original_manager);
55 DCHECK_EQ(original_profile, original_manager->GetBrowserContext());
56 original_manager->OnBrowserWindowReady();
57 }
58 }
59
60 void ChromeNotificationObserver::OnRendererProcessCreated( 23 void ChromeNotificationObserver::OnRendererProcessCreated(
61 content::RenderProcessHost* process) { 24 content::RenderProcessHost* process) {
62 // Extensions need to know the channel for API restrictions. Send the channel 25 // Extensions need to know the channel for API restrictions. Send the channel
63 // to all renderers, as the non-extension renderers may have content scripts. 26 // to all renderers, as the non-extension renderers may have content scripts.
64 process->Send(new ExtensionMsg_SetChannel(GetCurrentChannel())); 27 process->Send(new ExtensionMsg_SetChannel(GetCurrentChannel()));
65 } 28 }
66 29
67 void ChromeNotificationObserver::Observe(int type, 30 void ChromeNotificationObserver::Observe(int type,
68 const content::NotificationSource& source, 31 const content::NotificationSource& source,
69 const content::NotificationDetails& details) { 32 const content::NotificationDetails& details) {
70 switch (type) { 33 switch (type) {
71 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: {
72 Browser* browser = content::Source<Browser>(source).ptr();
73 OnBrowserWindowReady(browser);
74 break;
75 }
76
77 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: { 34 case content::NOTIFICATION_RENDERER_PROCESS_CREATED: {
78 content::RenderProcessHost* process = 35 content::RenderProcessHost* process =
79 content::Source<content::RenderProcessHost>(source).ptr(); 36 content::Source<content::RenderProcessHost>(source).ptr();
80 OnRendererProcessCreated(process); 37 OnRendererProcessCreated(process);
81 break; 38 break;
82 } 39 }
83 40
84 default: 41 default:
85 NOTREACHED(); 42 NOTREACHED();
86 } 43 }
87 } 44 }
88 45
89 } // namespace extensions 46 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/chrome_notification_observer.h ('k') | chrome/browser/extensions/chrome_process_manager_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698