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

Side by Side Diff: chrome/browser/prefs/incognito_mode_prefs.cc

Issue 2382023003: Optimize ShouldLaunchIncognito() since its on the startup path. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/prefs/incognito_mode_prefs.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/prefs/incognito_mode_prefs.h" 5 #include "chrome/browser/prefs/incognito_mode_prefs.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 *out_value = ENABLED; 135 *out_value = ENABLED;
136 return false; 136 return false;
137 } 137 }
138 *out_value = static_cast<Availability>(in_value); 138 *out_value = static_cast<Availability>(in_value);
139 return true; 139 return true;
140 } 140 }
141 141
142 // static 142 // static
143 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability( 143 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability(
144 const PrefService* pref_service) { 144 const PrefService* pref_service) {
145 DCHECK(pref_service); 145 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.
146 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
147 Availability result = IncognitoModePrefs::ENABLED;
148 bool valid = IntToAvailability(pref_value, &result);
149 DCHECK(valid);
150 if (ArePlatformParentalControlsEnabled()) {
151 if (result == IncognitoModePrefs::FORCED)
152 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on";
153 return IncognitoModePrefs::DISABLED;
154 }
155 return result;
156 } 146 }
157 147
158 // static 148 // static
159 void IncognitoModePrefs::SetAvailability(PrefService* prefs, 149 void IncognitoModePrefs::SetAvailability(PrefService* prefs,
160 const Availability availability) { 150 const Availability availability) {
161 prefs->SetInteger(prefs::kIncognitoModeAvailability, availability); 151 prefs->SetInteger(prefs::kIncognitoModeAvailability, availability);
162 } 152 }
163 153
164 // static 154 // static
165 void IncognitoModePrefs::RegisterProfilePrefs( 155 void IncognitoModePrefs::RegisterProfilePrefs(
166 user_prefs::PrefRegistrySyncable* registry) { 156 user_prefs::PrefRegistrySyncable* registry) {
167 registry->RegisterIntegerPref(prefs::kIncognitoModeAvailability, 157 registry->RegisterIntegerPref(prefs::kIncognitoModeAvailability,
168 IncognitoModePrefs::ENABLED); 158 IncognitoModePrefs::ENABLED);
169 } 159 }
170 160
171 // static 161 // static
172 bool IncognitoModePrefs::ShouldLaunchIncognito( 162 bool IncognitoModePrefs::ShouldLaunchIncognito(
173 const base::CommandLine& command_line, 163 const base::CommandLine& command_line,
174 const PrefService* prefs) { 164 const PrefService* prefs) {
175 Availability incognito_avail = GetAvailability(prefs); 165 // 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.
176 return incognito_avail != IncognitoModePrefs::DISABLED && 166 // parental controls on the normal code path - since querying
177 (command_line.HasSwitch(switches::kIncognito) || 167 // them is slow.
178 incognito_avail == IncognitoModePrefs::FORCED); 168 if (command_line.HasSwitch(switches::kIncognito) &&
169 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.
170 return true;
171 }
172 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.
179 } 173 }
180 174
181 // static 175 // static
182 bool IncognitoModePrefs::CanOpenBrowser(Profile* profile) { 176 bool IncognitoModePrefs::CanOpenBrowser(Profile* profile) {
183 if (profile->IsGuestSession()) 177 if (profile->IsGuestSession())
184 return true; 178 return true;
185 179
186 switch (GetAvailability(profile->GetPrefs())) { 180 switch (GetAvailability(profile->GetPrefs())) {
187 case IncognitoModePrefs::ENABLED: 181 case IncognitoModePrefs::ENABLED:
188 return true; 182 return true;
(...skipping 24 matching lines...) Expand all
213 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { 207 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
214 #if defined(OS_WIN) 208 #if defined(OS_WIN)
215 return PlatformParentalControlsValue::GetInstance()->is_enabled(); 209 return PlatformParentalControlsValue::GetInstance()->is_enabled();
216 #elif BUILDFLAG(ANDROID_JAVA_UI) 210 #elif BUILDFLAG(ANDROID_JAVA_UI)
217 return chrome::android::ChromeApplication::AreParentalControlsEnabled(); 211 return chrome::android::ChromeApplication::AreParentalControlsEnabled();
218 #else 212 #else
219 return false; 213 return false;
220 #endif 214 #endif
221 } 215 }
222 216
217 // static
218 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
219 const PrefService* pref_service,
220 bool check_parental_controls) {
221 DCHECK(pref_service);
222 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
223 Availability result = IncognitoModePrefs::ENABLED;
224 bool valid = IntToAvailability(pref_value, &result);
225 DCHECK(valid);
226 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.
227 if (result == IncognitoModePrefs::FORCED)
228 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on";
229 return IncognitoModePrefs::DISABLED;
230 }
231 return result;
232 }
OLDNEW
« 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