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

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

Issue 969813005: Unify the Windows Parental Controls Platform Caching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Downgrade the check 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 "base/threading/thread_restrictions.h"
10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "components/pref_registry/pref_registry_syncable.h" 14 #include "components/pref_registry/pref_registry_syncable.h"
15 #include "content/public/browser/browser_thread.h"
14 16
15 #if defined(OS_WIN) 17 #if defined(OS_WIN)
16 #include "base/win/metro.h" 18 #include <windows.h>
19 #include <wpcapi.h>
20 #include "base/win/scoped_comptr.h"
21 #include "base/win/windows_version.h"
17 #endif // OS_WIN 22 #endif // OS_WIN
18 23
19 #if defined(OS_ANDROID) 24 #if defined(OS_ANDROID)
20 #include "chrome/browser/android/chromium_application.h" 25 #include "chrome/browser/android/chromium_application.h"
21 #endif // OS_ANDROID 26 #endif // OS_ANDROID
22 27
28 using content::BrowserThread;
29
23 #if defined(OS_WIN) 30 #if defined(OS_WIN)
24 namespace { 31 namespace {
25 32
26 bool g_parental_control_on = false; 33 // Possible values for the parental controls state.
34 enum class ParentalControlsState {
35 // Parental controls state unknown. We have not queried for this value yet.
36 UNKNOWN = 0,
37 // Parental controls activity logging disabled.
38 ACTIVITY_LOGGING_DISABLED = 1,
39 // Parental controls activity logging enabled.
40 ACTIVITY_LOGGING_ENABLED = 2,
41 } g_parental_controls_state = ParentalControlsState::UNKNOWN;
42
43 // Returns true if Windows Parental control activity logging is enabled. This
44 // feature is available on Windows Vista and beyond.
gab 2015/03/03 20:05:03 Is it? You only query it for Win7+?
robliao 2015/03/03 20:20:35 Looks like this comment wasn't updated in https://
45 // This function should be called on a COM Initialized thread.
gab 2015/03/03 20:05:03 Also mention that this can be blocking? And move t
robliao 2015/03/03 20:20:35 Done.
46 bool IsParentalControlActivityLoggingOn() {
47 using namespace base::win;
gab 2015/03/03 20:05:03 Hmmm, I wouldn't do this, what does it simplify? I
robliao 2015/03/03 20:20:35 This simplifies the ScopedComPtr uses below. Unfor
48
49 // Query this info on Windows 7 and above.
50 if (base::win::GetVersion() < base::win::VERSION_WIN7)
51 return false;
52
53 ScopedComPtr<IWindowsParentalControlsCore> parent_controls;
54 HRESULT hr = parent_controls.CreateInstance(
55 __uuidof(WindowsParentalControls));
56 if (FAILED(hr))
57 return false;
58
59 ScopedComPtr<IWPCSettings> settings;
60 hr = parent_controls->GetUserSettings(NULL, settings.Receive());
gab 2015/03/03 20:05:03 s/NULL/nullptr
robliao 2015/03/03 20:20:35 Done.
61 if (FAILED(hr))
62 return false;
63
64 unsigned long restrictions = 0;
65 settings->GetRestrictions(&restrictions);
66
67 return (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED;
68 }
27 69
28 } // empty namespace 70 } // empty namespace
29 #endif // OS_WIN 71 #endif // OS_WIN
30 72
31 // static 73 // static
32 bool IncognitoModePrefs::IntToAvailability(int in_value, 74 bool IncognitoModePrefs::IntToAvailability(int in_value,
33 Availability* out_value) { 75 Availability* out_value) {
34 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { 76 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) {
35 *out_value = ENABLED; 77 *out_value = ENABLED;
36 return false; 78 return false;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 139
98 default: 140 default:
99 NOTREACHED(); 141 NOTREACHED();
100 return false; 142 return false;
101 } 143 }
102 } 144 }
103 145
104 // static 146 // static
105 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { 147 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
106 #if defined(OS_WIN) 148 #if defined(OS_WIN)
107 // Disable incognito mode windows if parental controls are on. This is only 149 if (g_parental_controls_state == ParentalControlsState::UNKNOWN) {
grt (UTC plus 2) 2015/03/03 20:28:54 g_parental_controls_state should be a local static
robliao 2015/03/03 21:07:12 Done.
108 // for Windows Vista and above. 150 // Production: The thread isn't initialized, so we're the only thread with
109 return base::win::IsParentalControlActivityLoggingOn(); 151 // IO and waiting allowed.
152 // Test: The thread may be initialized, so check that it's the UI thread.
153 DCHECK(
154 !BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
155 BrowserThread::CurrentlyOn(BrowserThread::UI));
156 base::ThreadRestrictions::AssertIOAllowed();
157 base::ThreadRestrictions::AssertWaitAllowed();
158 g_parental_controls_state =
159 IsParentalControlActivityLoggingOn() ?
160 ParentalControlsState::ACTIVITY_LOGGING_ENABLED :
161 ParentalControlsState::ACTIVITY_LOGGING_DISABLED;
162 }
163 return g_parental_controls_state ==
164 ParentalControlsState::ACTIVITY_LOGGING_ENABLED;
110 #elif defined(OS_ANDROID) 165 #elif defined(OS_ANDROID)
111 return chrome::android::ChromiumApplication::AreParentalControlsEnabled(); 166 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
112 #else 167 #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; 168 return false;
130 #endif 169 #endif
131 } 170 }
132 171
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698