OLD | NEW |
---|---|
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 Loading... | |
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, CHECK_PARENTAL_CONTROLS); |
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: We only absolutely need to check for parental controls in the |
176 return incognito_avail != IncognitoModePrefs::DISABLED && | 166 // startup path if the user requested to launch in incognito mode or |
177 (command_line.HasSwitch(switches::kIncognito) || | 167 // it was forced via prefs, since computing parental controls can be |
gab
2016/10/03 17:08:12
We need to check parental controls (...) since par
Alexei Svitkine (slow)
2016/10/03 18:57:39
I think the comment wording did work - "we only do
| |
178 incognito_avail == IncognitoModePrefs::FORCED); | 168 // slow. Otherwise, we can check later. |
169 bool should_use_incognito = | |
gab
2016/10/03 17:08:12
const
Alexei Svitkine (slow)
2016/10/03 18:57:39
Done.
| |
170 command_line.HasSwitch(switches::kIncognito) || | |
171 GetAvailabilityInternal(prefs, DONT_CHECK_PARENTAL_CONTROLS) == | |
172 IncognitoModePrefs::FORCED; | |
173 // Only check parental controls only if |should_use_incognito| is true. | |
gab
2016/10/03 17:08:12
double "only"
This comment is also probably redun
Alexei Svitkine (slow)
2016/10/03 18:57:39
Done. After re-wording the comment above, I'm OK w
| |
174 return should_use_incognito && | |
175 GetAvailabilityInternal(prefs, CHECK_PARENTAL_CONTROLS) != | |
176 IncognitoModePrefs::DISABLED; | |
179 } | 177 } |
180 | 178 |
181 // static | 179 // static |
182 bool IncognitoModePrefs::CanOpenBrowser(Profile* profile) { | 180 bool IncognitoModePrefs::CanOpenBrowser(Profile* profile) { |
183 if (profile->IsGuestSession()) | 181 if (profile->IsGuestSession()) |
184 return true; | 182 return true; |
185 | 183 |
186 switch (GetAvailability(profile->GetPrefs())) { | 184 switch (GetAvailability(profile->GetPrefs())) { |
187 case IncognitoModePrefs::ENABLED: | 185 case IncognitoModePrefs::ENABLED: |
188 return true; | 186 return true; |
(...skipping 24 matching lines...) Expand all Loading... | |
213 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { | 211 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { |
214 #if defined(OS_WIN) | 212 #if defined(OS_WIN) |
215 return PlatformParentalControlsValue::GetInstance()->is_enabled(); | 213 return PlatformParentalControlsValue::GetInstance()->is_enabled(); |
216 #elif BUILDFLAG(ANDROID_JAVA_UI) | 214 #elif BUILDFLAG(ANDROID_JAVA_UI) |
217 return chrome::android::ChromeApplication::AreParentalControlsEnabled(); | 215 return chrome::android::ChromeApplication::AreParentalControlsEnabled(); |
218 #else | 216 #else |
219 return false; | 217 return false; |
220 #endif | 218 #endif |
221 } | 219 } |
222 | 220 |
221 // static | |
222 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailabilityInternal( | |
223 const PrefService* pref_service, | |
224 GetAvailabilityMode mode) { | |
225 DCHECK(pref_service); | |
226 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); | |
227 Availability result = IncognitoModePrefs::ENABLED; | |
228 bool valid = IntToAvailability(pref_value, &result); | |
229 DCHECK(valid); | |
230 if (result != IncognitoModePrefs::DISABLED && | |
231 mode == CHECK_PARENTAL_CONTROLS && ArePlatformParentalControlsEnabled()) { | |
232 if (result == IncognitoModePrefs::FORCED) | |
233 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on"; | |
234 return IncognitoModePrefs::DISABLED; | |
235 } | |
236 return result; | |
237 } | |
OLD | NEW |