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: This code only checks parental controls if the user requested |
176 return incognito_avail != IncognitoModePrefs::DISABLED && | 166 // to launch in incognito mode or if it was forced via prefs. This way, |
177 (command_line.HasSwitch(switches::kIncognito) || | 167 // the parental controls check (which can be quite slow) can be avoided |
178 incognito_avail == IncognitoModePrefs::FORCED); | 168 // most of the time. |
| 169 const bool should_use_incognito = |
| 170 command_line.HasSwitch(switches::kIncognito) || |
| 171 GetAvailabilityInternal(prefs, DONT_CHECK_PARENTAL_CONTROLS) == |
| 172 IncognitoModePrefs::FORCED; |
| 173 return should_use_incognito && |
| 174 GetAvailabilityInternal(prefs, CHECK_PARENTAL_CONTROLS) != |
| 175 IncognitoModePrefs::DISABLED; |
179 } | 176 } |
180 | 177 |
181 // static | 178 // static |
182 bool IncognitoModePrefs::CanOpenBrowser(Profile* profile) { | 179 bool IncognitoModePrefs::CanOpenBrowser(Profile* profile) { |
183 if (profile->IsGuestSession()) | 180 if (profile->IsGuestSession()) |
184 return true; | 181 return true; |
185 | 182 |
186 switch (GetAvailability(profile->GetPrefs())) { | 183 switch (GetAvailability(profile->GetPrefs())) { |
187 case IncognitoModePrefs::ENABLED: | 184 case IncognitoModePrefs::ENABLED: |
188 return true; | 185 return true; |
(...skipping 24 matching lines...) Expand all Loading... |
213 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { | 210 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { |
214 #if defined(OS_WIN) | 211 #if defined(OS_WIN) |
215 return PlatformParentalControlsValue::GetInstance()->is_enabled(); | 212 return PlatformParentalControlsValue::GetInstance()->is_enabled(); |
216 #elif BUILDFLAG(ANDROID_JAVA_UI) | 213 #elif BUILDFLAG(ANDROID_JAVA_UI) |
217 return chrome::android::ChromeApplication::AreParentalControlsEnabled(); | 214 return chrome::android::ChromeApplication::AreParentalControlsEnabled(); |
218 #else | 215 #else |
219 return false; | 216 return false; |
220 #endif | 217 #endif |
221 } | 218 } |
222 | 219 |
| 220 // static |
| 221 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailabilityInternal( |
| 222 const PrefService* pref_service, |
| 223 GetAvailabilityMode mode) { |
| 224 DCHECK(pref_service); |
| 225 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); |
| 226 Availability result = IncognitoModePrefs::ENABLED; |
| 227 bool valid = IntToAvailability(pref_value, &result); |
| 228 DCHECK(valid); |
| 229 if (result != IncognitoModePrefs::DISABLED && |
| 230 mode == CHECK_PARENTAL_CONTROLS && ArePlatformParentalControlsEnabled()) { |
| 231 if (result == IncognitoModePrefs::FORCED) |
| 232 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on"; |
| 233 return IncognitoModePrefs::DISABLED; |
| 234 } |
| 235 return result; |
| 236 } |
OLD | NEW |