| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 | 12 |
| 13 #if defined(OS_WIN) |
| 14 #include "base/win/metro.h" |
| 15 #endif // OS_WIN |
| 16 |
| 13 // static | 17 // static |
| 14 bool IncognitoModePrefs::IntToAvailability(int in_value, | 18 bool IncognitoModePrefs::IntToAvailability(int in_value, |
| 15 Availability* out_value) { | 19 Availability* out_value) { |
| 16 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { | 20 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { |
| 17 *out_value = ENABLED; | 21 *out_value = ENABLED; |
| 18 return false; | 22 return false; |
| 19 } | 23 } |
| 20 *out_value = static_cast<Availability>(in_value); | 24 *out_value = static_cast<Availability>(in_value); |
| 21 return true; | 25 return true; |
| 22 } | 26 } |
| 23 | 27 |
| 24 // static | 28 // static |
| 25 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability( | 29 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability( |
| 26 const PrefService* pref_service) { | 30 const PrefService* pref_service) { |
| 27 DCHECK(pref_service); | 31 DCHECK(pref_service); |
| 28 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); | 32 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); |
| 29 Availability result = IncognitoModePrefs::ENABLED; | 33 Availability result = IncognitoModePrefs::ENABLED; |
| 30 bool valid = IntToAvailability(pref_value, &result); | 34 bool valid = IntToAvailability(pref_value, &result); |
| 31 DCHECK(valid); | 35 DCHECK(valid); |
| 36 #if defined(OS_WIN) |
| 37 // Disable incognito mode windows if parental controls are on. This is only |
| 38 // for Windows Vista and above. |
| 39 if (base::win::IsParentalControlActivityLoggingOn()) { |
| 40 if (result == IncognitoModePrefs::FORCED) |
| 41 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on"; |
| 42 return IncognitoModePrefs::DISABLED; |
| 43 } |
| 44 #endif // OS_WIN |
| 32 return result; | 45 return result; |
| 33 } | 46 } |
| 34 | 47 |
| 35 // static | 48 // static |
| 36 void IncognitoModePrefs::SetAvailability(PrefService* prefs, | 49 void IncognitoModePrefs::SetAvailability(PrefService* prefs, |
| 37 const Availability availability) { | 50 const Availability availability) { |
| 38 prefs->SetInteger(prefs::kIncognitoModeAvailability, availability); | 51 prefs->SetInteger(prefs::kIncognitoModeAvailability, availability); |
| 39 } | 52 } |
| 40 | 53 |
| 41 // static | 54 // static |
| 42 void IncognitoModePrefs::RegisterUserPrefs(PrefService* pref_service) { | 55 void IncognitoModePrefs::RegisterUserPrefs(PrefService* pref_service) { |
| 43 DCHECK(pref_service); | 56 DCHECK(pref_service); |
| 44 pref_service->RegisterIntegerPref(prefs::kIncognitoModeAvailability, | 57 pref_service->RegisterIntegerPref(prefs::kIncognitoModeAvailability, |
| 45 IncognitoModePrefs::ENABLED, | 58 IncognitoModePrefs::ENABLED, |
| 46 PrefService::UNSYNCABLE_PREF); | 59 PrefService::UNSYNCABLE_PREF); |
| 47 } | 60 } |
| 48 | 61 |
| 49 // static | 62 // static |
| 50 bool IncognitoModePrefs::ShouldLaunchIncognito( | 63 bool IncognitoModePrefs::ShouldLaunchIncognito( |
| 51 const CommandLine& command_line, | 64 const CommandLine& command_line, |
| 52 const PrefService* prefs) { | 65 const PrefService* prefs) { |
| 53 Availability incognito_avail = GetAvailability(prefs); | 66 Availability incognito_avail = GetAvailability(prefs); |
| 54 return incognito_avail != IncognitoModePrefs::DISABLED && | 67 return incognito_avail != IncognitoModePrefs::DISABLED && |
| 55 (command_line.HasSwitch(switches::kIncognito) || | 68 (command_line.HasSwitch(switches::kIncognito) || |
| 56 incognito_avail == IncognitoModePrefs::FORCED); | 69 incognito_avail == IncognitoModePrefs::FORCED); |
| 57 } | 70 } |
| OLD | NEW |