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 "base/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h"
13 #include "components/user_prefs/pref_registry_syncable.h"
16 #include "base/win/metro.h"
19 #if defined(OS_ANDROID)
20 #include "chrome/browser/android/chromium_application.h"
24 bool IncognitoModePrefs::IntToAvailability(int in_value
,
25 Availability
* out_value
) {
26 if (in_value
< 0 || in_value
>= AVAILABILITY_NUM_TYPES
) {
30 *out_value
= static_cast<Availability
>(in_value
);
35 IncognitoModePrefs::Availability
IncognitoModePrefs::GetAvailability(
36 const PrefService
* pref_service
) {
38 int pref_value
= pref_service
->GetInteger(prefs::kIncognitoModeAvailability
);
39 Availability result
= IncognitoModePrefs::ENABLED
;
40 bool valid
= IntToAvailability(pref_value
, &result
);
42 if (ArePlatformParentalControlsEnabled()) {
43 if (result
== IncognitoModePrefs::FORCED
)
44 LOG(ERROR
) << "Ignoring FORCED incognito. Parental control logging on";
45 return IncognitoModePrefs::DISABLED
;
51 void IncognitoModePrefs::SetAvailability(PrefService
* prefs
,
52 const Availability availability
) {
53 prefs
->SetInteger(prefs::kIncognitoModeAvailability
, availability
);
57 void IncognitoModePrefs::RegisterProfilePrefs(
58 user_prefs::PrefRegistrySyncable
* registry
) {
59 registry
->RegisterIntegerPref(
60 prefs::kIncognitoModeAvailability
,
61 IncognitoModePrefs::ENABLED
,
62 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF
);
66 bool IncognitoModePrefs::ShouldLaunchIncognito(
67 const CommandLine
& command_line
,
68 const PrefService
* prefs
) {
69 Availability incognito_avail
= GetAvailability(prefs
);
70 return incognito_avail
!= IncognitoModePrefs::DISABLED
&&
71 (command_line
.HasSwitch(switches::kIncognito
) ||
72 incognito_avail
== IncognitoModePrefs::FORCED
);
76 bool IncognitoModePrefs::CanOpenBrowser(Profile
* profile
) {
77 switch (GetAvailability(profile
->GetPrefs())) {
78 case IncognitoModePrefs::ENABLED
:
80 case IncognitoModePrefs::DISABLED
:
81 return !profile
->IsOffTheRecord();
82 case IncognitoModePrefs::FORCED
:
83 return profile
->IsOffTheRecord();
84 case IncognitoModePrefs::AVAILABILITY_NUM_TYPES
:
92 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
94 // Disable incognito mode windows if parental controls are on. This is only
95 // for Windows Vista and above.
96 return base::win::IsParentalControlActivityLoggingOn();
97 #elif defined(OS_ANDROID)
98 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();