Chromium Code Reviews| 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..5f47eb967ff8fce2b5fc243e09e63c9f9b332714 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, true); |
|
robliao
2016/09/30 17:43:46
Nit: true -> enum. Something like CHECK_PARENTAL_C
Alexei Svitkine (slow)
2016/09/30 20:16:16
Done.
|
| } |
| // static |
| @@ -172,10 +162,14 @@ 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: The following code structure ensures we don't query |
|
robliao
2016/09/30 18:26:13
I would make this more explicit:
We only absolutel
Alexei Svitkine (slow)
2016/09/30 20:16:16
Done.
|
| + // parental controls on the normal code path - since querying |
| + // them is slow. |
| + if (command_line.HasSwitch(switches::kIncognito) && |
| + GetAvailability(prefs) != IncognitoModePrefs::DISABLED) { |
|
robliao
2016/09/30 18:26:13
This is also used here:
https://cs.chromium.org/ch
gab
2016/09/30 18:47:20
I think this would be more readable as GetAvailabi
Alexei Svitkine (slow)
2016/09/30 20:16:16
Done.
|
| + return true; |
| + } |
| + return GetAvailabilityInternal(prefs, false) == IncognitoModePrefs::FORCED; |
|
gab
2016/09/30 18:47:20
Won't this launch incognito if the pref is set to
Alexei Svitkine (slow)
2016/09/30 18:55:08
You're right - good catch. Let me re-work the logi
Alexei Svitkine (slow)
2016/09/30 20:16:16
Done.
|
| } |
| // static |
| @@ -220,3 +214,19 @@ bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { |
| #endif |
| } |
| +// static |
| +IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailabilityInternal( |
|
robliao
2016/09/30 18:26:13
This can be part of the anonymous namespace, right
Alexei Svitkine (slow)
2016/09/30 20:16:16
I tried it this way, but it was referencing too ma
gab
2016/10/03 17:08:11
Since it's already a class with only static method
|
| + const PrefService* pref_service, |
| + bool check_parental_controls) { |
| + DCHECK(pref_service); |
| + int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); |
| + Availability result = IncognitoModePrefs::ENABLED; |
| + bool valid = IntToAvailability(pref_value, &result); |
| + DCHECK(valid); |
| + if (check_parental_controls && ArePlatformParentalControlsEnabled()) { |
|
gab
2016/09/30 18:47:20
Also only need to check if |result != IncognitoMod
Alexei Svitkine (slow)
2016/09/30 20:16:16
Done.
|
| + if (result == IncognitoModePrefs::FORCED) |
| + LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on"; |
| + return IncognitoModePrefs::DISABLED; |
| + } |
| + return result; |
| +} |