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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/prefs/incognito_mode_prefs.cc
diff --git a/chrome/browser/prefs/incognito_mode_prefs.cc b/chrome/browser/prefs/incognito_mode_prefs.cc
index e0255d4947d11a90c3d2e5fbbd56f707459c811b..6e021bac3e7359101053723c8f9ac79a7d2bc573 100644
--- a/chrome/browser/prefs/incognito_mode_prefs.cc
+++ b/chrome/browser/prefs/incognito_mode_prefs.cc
@@ -7,23 +7,59 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/prefs/pref_service.h"
+#include "base/threading/thread_restrictions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/pref_registry/pref_registry_syncable.h"
+#include "content/public/browser/browser_thread.h"
#if defined(OS_WIN)
-#include "base/win/metro.h"
+#include <windows.h>
+#include <wpcapi.h>
+#include "base/win/scoped_comptr.h"
+#include "base/win/windows_version.h"
#endif // OS_WIN
#if defined(OS_ANDROID)
#include "chrome/browser/android/chromium_application.h"
#endif // OS_ANDROID
+using content::BrowserThread;
+
#if defined(OS_WIN)
namespace {
-bool g_parental_control_on = false;
+// Returns true if Windows Parental control activity logging is enabled. This
+// feature is available on Windows 7 and beyond. This function should be called
+// on a COM Initialized thread and is potentially blocking.
+bool IsParentalControlActivityLoggingOn() {
+ 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
+
+ // Since we can potentially block, make sure the thread is okay with this.
+ base::ThreadRestrictions::AssertIOAllowed();
+ base::ThreadRestrictions::AssertWaitAllowed();
+
+ // Query this info on Windows 7 and above.
+ if (base::win::GetVersion() < base::win::VERSION_WIN7)
+ return false;
+
+ ScopedComPtr<IWindowsParentalControlsCore> parent_controls;
+ HRESULT hr = parent_controls.CreateInstance(
+ __uuidof(WindowsParentalControls));
+ if (FAILED(hr))
+ return false;
+
+ ScopedComPtr<IWPCSettings> settings;
+ hr = parent_controls->GetUserSettings(nullptr, settings.Receive());
+ if (FAILED(hr))
+ return false;
+
+ unsigned long restrictions = 0;
+ settings->GetRestrictions(&restrictions);
+
+ return (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED;
+}
} // 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.
#endif // OS_WIN
@@ -104,25 +140,29 @@ bool IncognitoModePrefs::CanOpenBrowser(Profile* profile) {
// static
bool IncognitoModePrefs::ArePlatformParentalControlsEnabled() {
#if defined(OS_WIN)
- // Disable incognito mode windows if parental controls are on. This is only
- // for Windows Vista and above.
- return base::win::IsParentalControlActivityLoggingOn();
-#elif defined(OS_ANDROID)
- return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
-#else
- return false;
-#endif
-}
-
-#if defined(OS_WIN)
-void IncognitoModePrefs::InitializePlatformParentalControls() {
- g_parental_control_on = base::win::IsParentalControlActivityLoggingOn();
-}
-#endif // OS_WIN
-
-bool IncognitoModePrefs::ArePlatformParentalControlsEnabledCached() {
-#if defined(OS_WIN)
- return g_parental_control_on;
+ // 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
+ 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.
+ // Parental controls state unknown. We have not queried for this value yet.
+ UNKNOWN = 0,
+ // Parental controls activity logging disabled.
+ ACTIVITY_LOGGING_DISABLED = 1,
+ // Parental controls activity logging enabled.
+ ACTIVITY_LOGGING_ENABLED = 2,
+ } 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.
+ if (g_parental_controls_state == ParentalControlsState::UNKNOWN) {
+ // Production: The thread isn't initialized, so we're the only thread that
+ // should be able to update this.
+ // Test: The thread may be initialized, so check that it's the UI thread.
+ DCHECK(
+ !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.
+ BrowserThread::CurrentlyOn(BrowserThread::UI));
+ g_parental_controls_state =
+ IsParentalControlActivityLoggingOn() ?
+ ParentalControlsState::ACTIVITY_LOGGING_ENABLED :
+ ParentalControlsState::ACTIVITY_LOGGING_DISABLED;
+ }
+ return g_parental_controls_state ==
+ ParentalControlsState::ACTIVITY_LOGGING_ENABLED;
#elif defined(OS_ANDROID)
return chrome::android::ChromiumApplication::AreParentalControlsEnabled();
#else

Powered by Google App Engine
This is Rietveld 408576698