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

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: Created 5 years, 10 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_checked = false;
26 bool g_parental_control_on = false; 27 bool g_parental_control_on = false;
gab 2015/02/24 20:39:47 How about an enum class ParentalControlState { U
robliao 2015/02/24 23:43:01 sgtm. Done
27 28
28 } // empty namespace 29 } // empty namespace
29 #endif // OS_WIN 30 #endif // OS_WIN
30 31
31 // static 32 // static
32 bool IncognitoModePrefs::IntToAvailability(int in_value, 33 bool IncognitoModePrefs::IntToAvailability(int in_value,
33 Availability* out_value) { 34 Availability* out_value) {
34 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { 35 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) {
35 *out_value = ENABLED; 36 *out_value = ENABLED;
36 return false; 37 return false;
37 } 38 }
38 *out_value = static_cast<Availability>(in_value); 39 *out_value = static_cast<Availability>(in_value);
39 return true; 40 return true;
40 } 41 }
41 42
42 // static 43 // static
43 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability( 44 IncognitoModePrefs::Availability IncognitoModePrefs::GetAvailability(
44 const PrefService* pref_service) { 45 const PrefService* pref_service) {
45 DCHECK(pref_service); 46 DCHECK(pref_service);
46 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability); 47 int pref_value = pref_service->GetInteger(prefs::kIncognitoModeAvailability);
47 Availability result = IncognitoModePrefs::ENABLED; 48 Availability result = IncognitoModePrefs::ENABLED;
48 bool valid = IntToAvailability(pref_value, &result); 49 bool valid = IntToAvailability(pref_value, &result);
49 DCHECK(valid); 50 DCHECK(valid);
50 if (ArePlatformParentalControlsEnabled()) { 51 if (ArePlatformParentalControlsEnabledCached()) {
51 if (result == IncognitoModePrefs::FORCED) 52 if (result == IncognitoModePrefs::FORCED)
52 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on"; 53 LOG(ERROR) << "Ignoring FORCED incognito. Parental control logging on";
53 return IncognitoModePrefs::DISABLED; 54 return IncognitoModePrefs::DISABLED;
54 } 55 }
55 return result; 56 return result;
56 } 57 }
57 58
58 // static 59 // static
59 void IncognitoModePrefs::SetAvailability(PrefService* prefs, 60 void IncognitoModePrefs::SetAvailability(PrefService* prefs,
60 const Availability availability) { 61 const Availability availability) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 95
95 case IncognitoModePrefs::FORCED: 96 case IncognitoModePrefs::FORCED:
96 return profile->IsOffTheRecord(); 97 return profile->IsOffTheRecord();
97 98
98 default: 99 default:
99 NOTREACHED(); 100 NOTREACHED();
100 return false; 101 return false;
101 } 102 }
102 } 103 }
103 104
104 // static
105 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
106 #if defined(OS_WIN)
107 // Disable incognito mode windows if parental controls are on. This is only
108 // for Windows Vista and above.
109 return base::win::IsParentalControlActivityLoggingOn();
110 #elif defined(OS_ANDROID)
111 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
112 #else
113 return false;
114 #endif
115 }
116
117 #if defined(OS_WIN) 105 #if defined(OS_WIN)
118 void IncognitoModePrefs::InitializePlatformParentalControls() { 106 void IncognitoModePrefs::InitializePlatformParentalControls() {
gab 2015/02/24 20:39:47 Also, should we not instead lazily initialize this
robliao 2015/02/24 23:43:01 It's oddly enough the best place for it since we n
gab 2015/02/25 20:23:51 I see, since this state is const once initialized,
robliao 2015/02/26 21:03:51 I'm going to have to think about this some more to
119 g_parental_control_on = base::win::IsParentalControlActivityLoggingOn(); 107 g_parental_control_on = base::win::IsParentalControlActivityLoggingOn();
gab 2015/02/24 20:39:47 Any idea why this call is even in base::win:: (and
robliao 2015/02/24 23:43:01 In a change a long, long, time ago, this was going
108 g_parental_control_checked = true;
120 } 109 }
121 #endif // OS_WIN 110 #endif // OS_WIN
122 111
123 bool IncognitoModePrefs::ArePlatformParentalControlsEnabledCached() { 112 bool IncognitoModePrefs::ArePlatformParentalControlsEnabledCached() {
124 #if defined(OS_WIN) 113 #if defined(OS_WIN)
114 DCHECK(g_parental_control_checked);
125 return g_parental_control_on; 115 return g_parental_control_on;
126 #elif defined(OS_ANDROID) 116 #elif defined(OS_ANDROID)
127 return chrome::android::ChromiumApplication::AreParentalControlsEnabled(); 117 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
128 #else 118 #else
129 return false; 119 return false;
130 #endif 120 #endif
131 } 121 }
132 122
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