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

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

Issue 671763002: Extract ProcessManager from ExtensionSystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 6 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_process_manager_delegate.h" 5 #include "chrome/browser/extensions/chrome_process_manager_delegate.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
17 #include "extensions/browser/extension_system.h" 17 #include "extensions/browser/extension_system.h"
18 #include "extensions/browser/process_manager.h" 18 #include "extensions/browser/process_manager.h"
19 #include "extensions/browser/process_manager_factory.h"
19 #include "extensions/common/one_shot_event.h" 20 #include "extensions/common/one_shot_event.h"
20 21
21 namespace extensions { 22 namespace extensions {
22 23
23 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() { 24 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() {
24 registrar_.Add(this, 25 registrar_.Add(this,
25 chrome::NOTIFICATION_BROWSER_WINDOW_READY, 26 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
26 content::NotificationService::AllSources()); 27 content::NotificationService::AllSources());
27 registrar_.Add(this, 28 registrar_.Add(this,
28 chrome::NOTIFICATION_PROFILE_CREATED, 29 chrome::NOTIFICATION_PROFILE_CREATED,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 // If the extension system isn't ready yet the background hosts will be 97 // If the extension system isn't ready yet the background hosts will be
97 // created automatically when it is. 98 // created automatically when it is.
98 ExtensionSystem* system = ExtensionSystem::Get(profile); 99 ExtensionSystem* system = ExtensionSystem::Get(profile);
99 if (!system->ready().is_signaled()) 100 if (!system->ready().is_signaled())
100 return; 101 return;
101 102
102 // Inform the process manager for this profile that the window is ready. 103 // Inform the process manager for this profile that the window is ready.
103 // We continue to observe the notification in case browser windows open for 104 // We continue to observe the notification in case browser windows open for
104 // a related incognito profile or other regular profiles. 105 // a related incognito profile or other regular profiles.
105 ProcessManager* manager = system->process_manager(); 106 ProcessManager* manager = ProcessManager::Get(profile);
106 if (!manager) // Tests may not have a process manager. 107 DCHECK(manager);
107 return;
108 DCHECK_EQ(profile, manager->GetBrowserContext()); 108 DCHECK_EQ(profile, manager->GetBrowserContext());
109 manager->MaybeCreateStartupBackgroundHosts(); 109 manager->MaybeCreateStartupBackgroundHosts();
110 110
111 // For incognito profiles also inform the original profile's process manager 111 // For incognito profiles also inform the original profile's process manager
112 // that the window is ready. This will usually be a no-op because the 112 // that the window is ready. This will usually be a no-op because the
113 // original profile's process manager should have been informed when the 113 // original profile's process manager should have been informed when the
114 // non-incognito window opened. 114 // non-incognito window opened.
115 if (profile->IsOffTheRecord()) { 115 if (profile->IsOffTheRecord()) {
116 Profile* original_profile = profile->GetOriginalProfile(); 116 Profile* original_profile = profile->GetOriginalProfile();
117 ProcessManager* original_manager = 117 ProcessManager* original_manager = ProcessManager::Get(original_profile);
118 ExtensionSystem::Get(original_profile)->process_manager();
119 DCHECK(original_manager); 118 DCHECK(original_manager);
120 DCHECK_EQ(original_profile, original_manager->GetBrowserContext()); 119 DCHECK_EQ(original_profile, original_manager->GetBrowserContext());
121 original_manager->MaybeCreateStartupBackgroundHosts(); 120 original_manager->MaybeCreateStartupBackgroundHosts();
122 } 121 }
123 } 122 }
124 123
125 void ChromeProcessManagerDelegate::OnProfileCreated(Profile* profile) { 124 void ChromeProcessManagerDelegate::OnProfileCreated(Profile* profile) {
126 // Incognito profiles are handled by their original profile. 125 // Incognito profiles are handled by their original profile.
127 if (profile->IsOffTheRecord()) 126 if (profile->IsOffTheRecord())
128 return; 127 return;
129 128
130 // The profile can be created before the extension system is ready. 129 // The profile can be created before the extension system is ready.
131 ProcessManager* manager = ExtensionSystem::Get(profile)->process_manager(); 130 if (!ExtensionSystem::Get(profile)->ready().is_signaled())
132 if (!manager)
133 return; 131 return;
134 132
135 // The profile might have been initialized asynchronously (in parallel with 133 // The profile might have been initialized asynchronously (in parallel with
136 // extension system startup). Now that initialization is complete the 134 // extension system startup). Now that initialization is complete the
137 // ProcessManager can load deferred background pages. 135 // ProcessManager can load deferred background pages.
138 manager->MaybeCreateStartupBackgroundHosts(); 136 ProcessManager::Get(profile)->MaybeCreateStartupBackgroundHosts();
139 } 137 }
140 138
141 void ChromeProcessManagerDelegate::OnProfileDestroyed(Profile* profile) { 139 void ChromeProcessManagerDelegate::OnProfileDestroyed(Profile* profile) {
142 // Close background hosts when the last profile is closed so that they 140 // Close background hosts when the last profile is closed so that they
143 // have time to shutdown various objects on different threads. The 141 // have time to shutdown various objects on different threads. The
144 // ProfileManager destructor is called too late in the shutdown sequence. 142 // ProfileManager destructor is called too late in the shutdown sequence.
145 // http://crbug.com/15708 143 // http://crbug.com/15708
146 ProcessManager* manager = ExtensionSystem::Get(profile)->process_manager(); 144 ProcessManager* manager =
147 if (manager) 145 ProcessManagerFactory::GetForBrowserContextIfExists(profile);
146 if (manager) {
148 manager->CloseBackgroundHosts(); 147 manager->CloseBackgroundHosts();
148 }
149 149
150 // If this profile owns an incognito profile, but it is destroyed before the 150 // If this profile owns an incognito profile, but it is destroyed before the
151 // incognito profile is destroyed, then close the incognito background hosts 151 // incognito profile is destroyed, then close the incognito background hosts
152 // as well. This happens in a few tests. http://crbug.com/138843 152 // as well. This happens in a few tests. http://crbug.com/138843
153 if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile()) { 153 if (!profile->IsOffTheRecord() && profile->HasOffTheRecordProfile()) {
154 ProcessManager* incognito_manager = 154 ProcessManager* incognito_manager =
155 ExtensionSystem::Get(profile->GetOffTheRecordProfile()) 155 ProcessManagerFactory::GetForBrowserContextIfExists(
156 ->process_manager(); 156 profile->GetOffTheRecordProfile());
157 if (incognito_manager) 157 if (incognito_manager) {
158 incognito_manager->CloseBackgroundHosts(); 158 incognito_manager->CloseBackgroundHosts();
159 }
159 } 160 }
160 } 161 }
161 162
162 } // namespace extensions 163 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/chrome_content_browser_client_extensions_part.cc ('k') | chrome/browser/extensions/devtools_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698