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

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

Issue 381283002: Refactor code that defers extension background page loading (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: larger DeferLoadingBackgroundHosts 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_extensions_browser_client.h" 5 #include "chrome/browser/extensions/chrome_extensions_browser_client.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/version.h" 9 #include "base/version.h"
10 #include "chrome/browser/app_mode/app_mode_utils.h" 10 #include "chrome/browser/app_mode/app_mode_utils.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 std::vector<ExtensionPrefsObserver*>* observers) const { 155 std::vector<ExtensionPrefsObserver*>* observers) const {
156 #if defined(ENABLE_EXTENSIONS) 156 #if defined(ENABLE_EXTENSIONS)
157 observers->push_back(ContentSettingsService::Get(context)); 157 observers->push_back(ContentSettingsService::Get(context));
158 #endif 158 #endif
159 } 159 }
160 160
161 bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts( 161 bool ChromeExtensionsBrowserClient::DeferLoadingBackgroundHosts(
162 content::BrowserContext* context) const { 162 content::BrowserContext* context) const {
163 Profile* profile = static_cast<Profile*>(context); 163 Profile* profile = static_cast<Profile*>(context);
164 164
165 // Defer forever if current session is a Guest mode session and current
166 // browser context is *not* off-the-record. Such context is artificial and
167 // background page shouldn't be created in it.
168 if (profile->IsGuestSession() && !profile->IsOffTheRecord())
169 return true;
170
165 // The profile may not be valid yet if it is still being initialized. 171 // The profile may not be valid yet if it is still being initialized.
166 // In that case, defer loading, since it depends on an initialized profile. 172 // In that case, defer loading, since it depends on an initialized profile.
173 // Background hosts will be loaded later via NOTIFICATION_PROFILE_CREATED
174 // in ChromeNotificationObserver.
167 // http://crbug.com/222473 175 // http://crbug.com/222473
168 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 176 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
169 return true; 177 return true;
170 178
171 #if defined(OS_ANDROID) 179 #if defined(OS_ANDROID)
172 return false; 180 return false;
173 #else 181 #else
174 // There are no browser windows open and the browser process was 182 // There are no browser windows open and the browser process was
175 // started to show the app launcher. 183 // started to show the app launcher. Background hosts will be loaded later
184 // via NOTIFICATION_BROWSER_WINDOW_READY in ChromeNotificationObserver.
176 return chrome::GetTotalBrowserCountForProfile(profile) == 0 && 185 return chrome::GetTotalBrowserCountForProfile(profile) == 0 &&
177 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList); 186 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowAppList);
178 #endif 187 #endif
179 } 188 }
180 189
181 bool ChromeExtensionsBrowserClient::IsBackgroundPageAllowed( 190 bool ChromeExtensionsBrowserClient::IsBackgroundPageAllowed(
182 content::BrowserContext* context) const { 191 content::BrowserContext* context) const {
183 // Returns true if current session is Guest mode session and current 192 //JAMES remove me
184 // browser context is *not* off-the-record. Such context is artificial and 193 return true;
185 // background page shouldn't be created in it.
186 return !static_cast<Profile*>(context)->IsGuestSession() ||
187 context->IsOffTheRecord();
188 } 194 }
189 195
190 scoped_ptr<ExtensionHostDelegate> 196 scoped_ptr<ExtensionHostDelegate>
191 ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() { 197 ChromeExtensionsBrowserClient::CreateExtensionHostDelegate() {
192 return scoped_ptr<ExtensionHostDelegate>(new ChromeExtensionHostDelegate); 198 return scoped_ptr<ExtensionHostDelegate>(new ChromeExtensionHostDelegate);
193 } 199 }
194 200
195 bool ChromeExtensionsBrowserClient::DidVersionUpdate( 201 bool ChromeExtensionsBrowserClient::DidVersionUpdate(
196 content::BrowserContext* context) { 202 content::BrowserContext* context) {
197 Profile* profile = static_cast<Profile*>(context); 203 Profile* profile = static_cast<Profile*>(context);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 content::BrowserContext* context) const { 293 content::BrowserContext* context) const {
288 #if defined(ENABLE_EXTENSIONS) 294 #if defined(ENABLE_EXTENSIONS)
289 return scoped_ptr<extensions::RuntimeAPIDelegate>( 295 return scoped_ptr<extensions::RuntimeAPIDelegate>(
290 new ChromeRuntimeAPIDelegate(context)); 296 new ChromeRuntimeAPIDelegate(context));
291 #else 297 #else
292 return scoped_ptr<extensions::RuntimeAPIDelegate>(); 298 return scoped_ptr<extensions::RuntimeAPIDelegate>();
293 #endif 299 #endif
294 } 300 }
295 301
296 } // namespace extensions 302 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/chrome_notification_observer.h » ('j') | extensions/DEPS » ('J')

Powered by Google App Engine
This is Rietveld 408576698