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

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 // Since we can potentially block, make sure the thread is okay with this.
38 base::ThreadRestrictions::AssertIOAllowed();
39 base::ThreadRestrictions::AssertWaitAllowed();
27 40
28 } // empty namespace 41 // Query this info on Windows 7 and above.
42 if (base::win::GetVersion() < base::win::VERSION_WIN7)
43 return false;
44
45 base::win::ScopedComPtr<IWindowsParentalControlsCore> parent_controls;
46 HRESULT hr = parent_controls.CreateInstance(
47 __uuidof(WindowsParentalControls));
48 if (FAILED(hr))
49 return false;
50
51 base::win::ScopedComPtr<IWPCSettings> settings;
52 hr = parent_controls->GetUserSettings(nullptr, settings.Receive());
53 if (FAILED(hr))
54 return false;
55
56 unsigned long restrictions = 0;
57 settings->GetRestrictions(&restrictions);
58
59 return (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED;
60 }
61
62 } // namespace
29 #endif // OS_WIN 63 #endif // OS_WIN
30 64
31 // static 65 // static
32 bool IncognitoModePrefs::IntToAvailability(int in_value, 66 bool IncognitoModePrefs::IntToAvailability(int in_value,
33 Availability* out_value) { 67 Availability* out_value) {
34 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) { 68 if (in_value < 0 || in_value >= AVAILABILITY_NUM_TYPES) {
35 *out_value = ENABLED; 69 *out_value = ENABLED;
36 return false; 70 return false;
37 } 71 }
38 *out_value = static_cast<Availability>(in_value); 72 *out_value = static_cast<Availability>(in_value);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 131
98 default: 132 default:
99 NOTREACHED(); 133 NOTREACHED();
100 return false; 134 return false;
101 } 135 }
102 } 136 }
103 137
104 // static 138 // static
105 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() { 139 bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
106 #if defined(OS_WIN) 140 #if defined(OS_WIN)
107 // Disable incognito mode windows if parental controls are on. This is only 141 enum class ParentalControlsState {
108 // for Windows Vista and above. 142 UNKNOWN = 0,
109 return base::win::IsParentalControlActivityLoggingOn(); 143 ACTIVITY_LOGGING_DISABLED = 1,
144 ACTIVITY_LOGGING_ENABLED = 2,
145 };
146 static ParentalControlsState parental_controls_state =
147 ParentalControlsState::UNKNOWN;
148 if (parental_controls_state == ParentalControlsState::UNKNOWN) {
149 // Production: The thread isn't initialized, so we're the only thread that
150 // should be able to update this.
151 // Test: The thread may be initialized, so check that it's the UI thread.
152 DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
153 BrowserThread::CurrentlyOn(BrowserThread::UI));
154 parental_controls_state =
155 IsParentalControlActivityLoggingOn() ?
156 ParentalControlsState::ACTIVITY_LOGGING_ENABLED :
157 ParentalControlsState::ACTIVITY_LOGGING_DISABLED;
158 }
159 return parental_controls_state ==
160 ParentalControlsState::ACTIVITY_LOGGING_ENABLED;
110 #elif defined(OS_ANDROID) 161 #elif defined(OS_ANDROID)
111 return chrome::android::ChromiumApplication::AreParentalControlsEnabled(); 162 return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
112 #else 163 #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; 164 return false;
130 #endif 165 #endif
131 } 166 }
132 167
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698