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
3 // found in the LICENSE file.
5 #include "chrome/browser/prefs/incognito_mode_prefs.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/pref_names.h"
14 #include "base/win/metro.h"
18 bool IncognitoModePrefs::IntToAvailability(int in_value
,
19 Availability
* out_value
) {
20 if (in_value
< 0 || in_value
>= AVAILABILITY_NUM_TYPES
) {
24 *out_value
= static_cast<Availability
>(in_value
);
29 IncognitoModePrefs::Availability
IncognitoModePrefs::GetAvailability(
30 const PrefService
* pref_service
) {
32 int pref_value
= pref_service
->GetInteger(prefs::kIncognitoModeAvailability
);
33 Availability result
= IncognitoModePrefs::ENABLED
;
34 bool valid
= IntToAvailability(pref_value
, &result
);
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
;
49 void IncognitoModePrefs::SetAvailability(PrefService
* prefs
,
50 const Availability availability
) {
51 prefs
->SetInteger(prefs::kIncognitoModeAvailability
, availability
);
55 void IncognitoModePrefs::RegisterUserPrefs(PrefService
* pref_service
) {
57 pref_service
->RegisterIntegerPref(prefs::kIncognitoModeAvailability
,
58 IncognitoModePrefs::ENABLED
,
59 PrefService::UNSYNCABLE_PREF
);
63 bool IncognitoModePrefs::ShouldLaunchIncognito(
64 const CommandLine
& command_line
,
65 const PrefService
* prefs
) {
66 Availability incognito_avail
= GetAvailability(prefs
);
67 return incognito_avail
!= IncognitoModePrefs::DISABLED
&&
68 (command_line
.HasSwitch(switches::kIncognito
) ||
69 incognito_avail
== IncognitoModePrefs::FORCED
);