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

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: CR Feedback 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 // Returns true if Windows Parental control activity logging is enabled. This
34 // feature is available on Windows 7 and beyond. This function should be called
35 // on a COM Initialized thread and is potentially blocking.
36 bool IsParentalControlActivityLoggingOn() {
37 using namespace base::win;
grt (UTC plus 2) 2015/03/04 03:59:39 this doesn't seem to reduce the need for wrapping
robliao 2015/03/04 18:47:44 More of a style thing than anything, since that's
38
39 // Since we can potentially block, make sure the thread is okay with this.
40 base::ThreadRestrictions::AssertIOAllowed();
41 base::ThreadRestrictions::AssertWaitAllowed();
42
43 // Query this info on Windows 7 and above.
44 if (base::win::GetVersion() < base::win::VERSION_WIN7)
45 return false;
46
47 ScopedComPtr<IWindowsParentalControlsCore> parent_controls;
48 HRESULT hr = parent_controls.CreateInstance(
49 __uuidof(WindowsParentalControls));
50 if (FAILED(hr))
51 return false;
52
53 ScopedComPtr<IWPCSettings> settings;
54 hr = parent_controls->GetUserSettings(nullptr, settings.Receive());
55 if (FAILED(hr))
56 return false;
57
58 unsigned long restrictions = 0;
59 settings->GetRestrictions(&restrictions);
60
61 return (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED;
62 }
27 63
28 } // empty namespace 64 } // empty namespace
grt (UTC plus 2) 2015/03/04 03:59:39 while you're here, please change to: } // namespa
robliao 2015/03/04 18:47:44 Done.
29 #endif // OS_WIN 65 #endif // OS_WIN
30 66
31 // static 67 // static
32 bool IncognitoModePrefs::IntToAvailability(int in_value, 68 bool IncognitoModePrefs::IntToAvailability(int in_value,
33 Availability* out_value) { 69 Availability* out_value) {
34 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { 70 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) {
35 *out_value = ENABLED; 71 *out_value = ENABLED;
36 return false; 72 return false;
37 } 73 }
38 *out_value = static_cast<Availability>(in_value); 74 *out_value = static_cast<Availability>(in_value);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 133
98 default: 134 default:
99 NOTREACHED(); 135 NOTREACHED();
100 return false; 136 return false;
101 } 137 }
102 } 138 }
103 139
104 // static 140 // static
105 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { 141 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
106 #if defined(OS_WIN) 142 #if defined(OS_WIN)
107 // Disable incognito mode windows if parental controls are on. This is only 143 // Possible values for the parental controls state.
gab 2015/03/04 16:25:23 Consider removing this comment, feels redundant (i
robliao 2015/03/04 18:47:44 Just following the style set by enums in the neigh
108 // for Windows Vista and above. 144 static enum class ParentalControlsState {
gab 2015/03/04 16:25:23 Move static keyword right before variable declarat
grt (UTC plus 2) 2015/03/04 16:45:12 Not sure I agree here. You would never write int
gab 2015/03/04 16:53:19 I see your point, I still prefer my proposal thoug
robliao 2015/03/04 18:47:44 A search from the earlier proposal revealed that t
gab 2015/03/04 19:21:20 Okay, sgtm.
109 return base::win::IsParentalControlActivityLoggingOn(); 145 // Parental controls state unknown. We have not queried for this value yet.
146 UNKNOWN = 0,
147 // Parental controls activity logging disabled.
148 ACTIVITY_LOGGING_DISABLED = 1,
149 // Parental controls activity logging enabled.
150 ACTIVITY_LOGGING_ENABLED = 2,
151 } g_parental_controls_state = ParentalControlsState::UNKNOWN;
grt (UTC plus 2) 2015/03/04 03:59:39 no need for g_ since this is no longer a global
robliao 2015/03/04 18:47:44 Missed that. Thanks.
152 if (g_parental_controls_state == ParentalControlsState::UNKNOWN) {
153 // Production: The thread isn't initialized, so we're the only thread that
154 // should be able to update this.
155 // Test: The thread may be initialized, so check that it's the UI thread.
156 DCHECK(
157 !BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
grt (UTC plus 2) 2015/03/04 03:59:39 formatting nit: DCHECK(!BrowserThread::IsThrea
robliao 2015/03/04 18:47:44 Done.
158 BrowserThread::CurrentlyOn(BrowserThread::UI));
159 g_parental_controls_state =
160 IsParentalControlActivityLoggingOn() ?
161 ParentalControlsState::ACTIVITY_LOGGING_ENABLED :
162 ParentalControlsState::ACTIVITY_LOGGING_DISABLED;
163 }
164 return g_parental_controls_state ==
165 ParentalControlsState::ACTIVITY_LOGGING_ENABLED;
110 #elif defined(OS_ANDROID) 166 #elif defined(OS_ANDROID)
111 return chrome::android::ChromiumApplication::AreParentalControlsEnabled(); 167 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
112 #else 168 #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; 169 return false;
130 #endif 170 #endif
131 } 171 }
132 172
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698