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

Unified Diff: chrome/browser/prefs/incognito_mode_prefs.cc

Issue 2382023003: Optimize ShouldLaunchIncognito() since its on the startup path. (Closed)
Patch Set: Address gab's comments. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/prefs/incognito_mode_prefs.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/incognito_mode_prefs.cc
diff --git a/chrome/browser/prefs/incognito_mode_prefs.cc b/chrome/browser/prefs/incognito_mode_prefs.cc
index 2e20d04d8d1230f2863471a010289aefa901f704..8d62abaadd245f88ef5e54f031714e68845fc86e 100644
--- a/chrome/browser/prefs/incognito_mode_prefs.cc
+++ b/chrome/browser/prefs/incognito_mode_prefs.cc
@@ -142,17 +142,7 @@ bool IncognitoModePrefs::IntToAvailability(int in_value,
// static
IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability(
const PrefService* pref_service) {
- DCHECK(pref_service);
- int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
- Availability result = IncognitoModePrefs::ENABLED;
- bool valid = IntToAvailability(pref_value, &result);
- DCHECK(valid);
- if (ArePlatformParentalControlsEnabled()) {
- if (result == IncognitoModePrefs::FORCED)
- LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on";
- return IncognitoModePrefs::DISABLED;
- }
- return result;
+ return GetAvailabilityInternal(pref_service, CHECK_PARENTAL_CONTROLS);
}
// static
@@ -172,10 +162,17 @@ void IncognitoModePrefs::RegisterProfilePrefs(
bool IncognitoModePrefs::ShouldLaunchIncognito(
const base::CommandLine& command_line,
const PrefService* prefs) {
- Availability incognito_avail = GetAvailability(prefs);
- return incognito_avail != IncognitoModePrefs::DISABLED &&
- (command_line.HasSwitch(switches::kIncognito) ||
- incognito_avail == IncognitoModePrefs::FORCED);
+ // Note: This code only checks parental controls if the user requested
+ // to launch in incognito mode or if it was forced via prefs. This way,
+ // the parental controls check (which can be quite slow) can be avoided
+ // most of the time.
+ const bool should_use_incognito =
+ command_line.HasSwitch(switches::kIncognito) ||
+ GetAvailabilityInternal(prefs, DONT_CHECK_PARENTAL_CONTROLS) ==
+ IncognitoModePrefs::FORCED;
+ return should_use_incognito &&
+ GetAvailabilityInternal(prefs, CHECK_PARENTAL_CONTROLS) !=
+ IncognitoModePrefs::DISABLED;
}
// static
@@ -220,3 +217,20 @@ bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
#endif
}
+// static
+IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailabilityInternal(
+ const PrefService* pref_service,
+ GetAvailabilityMode mode) {
+ DCHECK(pref_service);
+ int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
+ Availability result = IncognitoModePrefs::ENABLED;
+ bool valid = IntToAvailability(pref_value, &result);
+ DCHECK(valid);
+ if (result != IncognitoModePrefs::DISABLED &&
+ mode == CHECK_PARENTAL_CONTROLS && ArePlatformParentalControlsEnabled()) {
+ if (result == IncognitoModePrefs::FORCED)
+ LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on";
+ return IncognitoModePrefs::DISABLED;
+ }
+ return result;
+}
« no previous file with comments | « chrome/browser/prefs/incognito_mode_prefs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698