Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/prefs/incognito_mode_prefs.cc

Issue 950053002: Cache the Windows Parental Controls Platform Answer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test Isolation Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "components/pref_registry/pref_registry_syncable.h" 13 #include "components/pref_registry/pref_registry_syncable.h"
14 14
15 #if defined(OS_WIN) 15 #if defined(OS_WIN)
16 #include "base/win/metro.h" 16 #include "base/win/metro.h"
17 #endif // OS_WIN 17 #endif // OS_WIN
18 18
19 #if defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
20 #include "chrome/browser/android/chromium_application.h" 20 #include "chrome/browser/android/chromium_application.h"
21 #endif // OS_ANDROID 21 #endif // OS_ANDROID
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 namespace { 24 namespace {
25 25
26 bool g_parental_control_on = false; 26 // Possible values for the parental controls state.
27 enum class ParentalControlsState {
28 // Parental controls state unknown. We have not queried for this value yet.
29 UNKNOWN = 0,
30 // Parental controls activity logging disabled.
31 ACTIVITY_LOGGING_DISABLED = 1,
32 // Parental controls activity logging enabled.
33 ACTIVITY_LOGGING_ENABLED = 2,
34 };
35 ParentalControlsState g_parental_controls_state =
36 ParentalControlsState::UNKNOWN;
27 37
28 } // empty namespace 38 } // empty namespace
29 #endif // OS_WIN 39 #endif // OS_WIN
30 40
31 // static 41 // static
32 bool IncognitoModePrefs::IntToAvailability(int in_value, 42 bool IncognitoModePrefs::IntToAvailability(int in_value,
33 Availability* out_value) { 43 Availability* out_value) {
34 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { 44 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) {
35 *out_value = ENABLED; 45 *out_value = ENABLED;
36 return false; 46 return false;
37 } 47 }
38 *out_value = static_cast<Availability>(in_value); 48 *out_value = static_cast<Availability>(in_value);
39 return true; 49 return true;
40 } 50 }
41 51
42 // static 52 // static
43 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability( 53 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability(
44 const PrefService* pref_service) { 54 const PrefService* pref_service) {
45 DCHECK(pref_service); 55 DCHECK(pref_service);
46 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); 56 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
47 Availability result = IncognitoModePrefs::ENABLED; 57 Availability result = IncognitoModePrefs::ENABLED;
48 bool valid = IntToAvailability(pref_value, &result); 58 bool valid = IntToAvailability(pref_value, &result);
49 DCHECK(valid); 59 DCHECK(valid);
50 if (ArePlatformParentalControlsEnabled()) { 60 if (ArePlatformParentalControlsEnabledCached()) {
51 if (result == IncognitoModePrefs::FORCED) 61 if (result == IncognitoModePrefs::FORCED)
52 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on"; 62 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on";
53 return IncognitoModePrefs::DISABLED; 63 return IncognitoModePrefs::DISABLED;
54 } 64 }
55 return result; 65 return result;
56 } 66 }
57 67
58 // static 68 // static
59 void IncognitoModePrefs::SetAvailability(PrefService* prefs, 69 void IncognitoModePrefs::SetAvailability(PrefService* prefs,
60 const Availability availability) { 70 const Availability availability) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 104
95 case IncognitoModePrefs::FORCED: 105 case IncognitoModePrefs::FORCED:
96 return profile->IsOffTheRecord(); 106 return profile->IsOffTheRecord();
97 107
98 default: 108 default:
99 NOTREACHED(); 109 NOTREACHED();
100 return false; 110 return false;
101 } 111 }
102 } 112 }
103 113
104 // static 114 void IncognitoModePrefs::InitializePlatformParentalControls() {
105 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
106 #if defined(OS_WIN) 115 #if defined(OS_WIN)
107 // Disable incognito mode windows if parental controls are on. This is only 116 DCHECK(g_parental_controls_state == ParentalControlsState::UNKNOWN);
108 // for Windows Vista and above. 117 g_parental_controls_state =
109 return base::win::IsParentalControlActivityLoggingOn(); 118 base::win::IsParentalControlActivityLoggingOn() ?
119 ParentalControlsState::ACTIVITY_LOGGING_ENABLED :
120 ParentalControlsState::ACTIVITY_LOGGING_DISABLED;
121 #endif // defined(OS_WIN)
122 }
123
124 void IncognitoModePrefs::UninitializePlatformParentalControlsImpl() {
125 #if defined(OS_WIN)
126 g_parental_controls_state = ParentalControlsState::UNKNOWN;
msw 2015/02/28 01:05:33 Why do tests have to do this? Will the system valu
robliao 2015/02/28 01:16:31 Turns out this state is shared between groups of t
127 #endif // defined(OS_WIN)
128 }
129
130 bool IncognitoModePrefs::ArePlatformParentalControlsEnabledCached() {
131 #if defined(OS_WIN)
132 DCHECK(g_parental_controls_state != ParentalControlsState::UNKNOWN);
133 return g_parental_controls_state ==
134 ParentalControlsState::ACTIVITY_LOGGING_ENABLED;
110 #elif defined(OS_ANDROID) 135 #elif defined(OS_ANDROID)
111 return chrome::android::ChromiumApplication::AreParentalControlsEnabled(); 136 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
112 #else 137 #else
113 return false;
114 #endif
115 }
116
117 #if defined(OS_WIN)
118 void IncognitoModePrefs::InitializePlatformParentalControls() {
119 g_parental_control_on = base::win::IsParentalControlActivityLoggingOn();
120 }
121 #endif // OS_WIN
122
123 bool IncognitoModePrefs::ArePlatformParentalControlsEnabledCached() {
124 #if defined(OS_WIN)
125 return g_parental_control_on;
126 #elif defined(OS_ANDROID)
127 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
128 #else
129 return false; 138 return false;
130 #endif 139 #endif
131 } 140 }
132 141
OLDNEW
« no previous file with comments | « chrome/browser/prefs/incognito_mode_prefs.h ('k') | chrome/browser/prefs/incognito_mode_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698