Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / prefs / incognito_mode_prefs.cc
blobfe498ea2513cfff5aaec530ec32344b20a5ffe66
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"
13 #if defined(OS_WIN)
14 #include "base/win/metro.h"
15 #endif // OS_WIN
17 // static
18 bool IncognitoModePrefs::IntToAvailability(int in_value,
19 Availability* out_value) {
20 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) {
21 *out_value = ENABLED;
22 return false;
24 *out_value = static_cast<Availability>(in_value);
25 return true;
28 // static
29 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability(
30 const PrefService* pref_service) {
31 DCHECK(pref_service);
32 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
33 Availability result = IncognitoModePrefs::ENABLED;
34 bool valid = IntToAvailability(pref_value, &result);
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;
44 #endif // OS_WIN
45 return result;
48 // static
49 void IncognitoModePrefs::SetAvailability(PrefService* prefs,
50 const Availability availability) {
51 prefs->SetInteger(prefs::kIncognitoModeAvailability, availability);
54 // static
55 void IncognitoModePrefs::RegisterUserPrefs(PrefService* pref_service) {
56 DCHECK(pref_service);
57 pref_service->RegisterIntegerPref(prefs::kIncognitoModeAvailability,
58 IncognitoModePrefs::ENABLED,
59 PrefService::UNSYNCABLE_PREF);
62 // static
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);