diff options
author | robliao <robliao@chromium.org> | 2015-03-06 11:49:24 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-06 19:52:25 +0000 |
commit | 4e3ceb427b2285c6288e7daff5e2f316f19b6607 (patch) | |
tree | 416acb3ffd4789b773d168721b3de6f3f24b43e9 | |
parent | 2b6f0c85fc4dcdb1746c4ac717b4b71c96e6e22a (diff) | |
download | chromium_src-4e3ceb427b2285c6288e7daff5e2f316f19b6607.zip chromium_src-4e3ceb427b2285c6288e7daff5e2f316f19b6607.tar.gz chromium_src-4e3ceb427b2285c6288e7daff5e2f316f19b6607.tar.bz2 |
Unify the Windows Parental Controls Platform Caching
There were two caches running around for Windows Platform Controls caching. One lived in the incognito mode prefs and the other lived in the Windows code. This change unifies both caches for easier management.
BUG=458388
TBR=rogerta
Review URL: https://codereview.chromium.org/969813005
Cr-Commit-Position: refs/heads/master@{#319482}
-rw-r--r-- | base/win/metro.cc | 35 | ||||
-rw-r--r-- | base/win/metro.h | 6 | ||||
-rw-r--r-- | chrome/browser/chrome_browser_main_win.cc | 4 | ||||
-rw-r--r-- | chrome/browser/prefs/incognito_mode_prefs.cc | 79 | ||||
-rw-r--r-- | chrome/browser/prefs/incognito_mode_prefs.h | 18 | ||||
-rw-r--r-- | chrome/browser/signin/signin_header_helper.cc | 2 |
6 files changed, 66 insertions, 78 deletions
diff --git a/base/win/metro.cc b/base/win/metro.cc index 6e443ba..7946698 100644 --- a/base/win/metro.cc +++ b/base/win/metro.cc @@ -4,10 +4,7 @@ #include "base/win/metro.h" -#include "base/message_loop/message_loop.h" #include "base/strings/string_util.h" -#include "base/win/scoped_comptr.h" -#include "base/win/windows_version.h" namespace base { namespace win { @@ -73,38 +70,6 @@ wchar_t* LocalAllocAndCopyString(const string16& src) { return dest; } -bool IsParentalControlActivityLoggingOn() { - // Query this info on Windows 7 and above. - if (base::win::GetVersion() < base::win::VERSION_WIN7) - return false; - - static bool parental_control_logging_required = false; - static bool parental_control_status_determined = false; - - if (parental_control_status_determined) - return parental_control_logging_required; - - parental_control_status_determined = true; - - ScopedComPtr<IWindowsParentalControlsCore> parent_controls; - HRESULT hr = parent_controls.CreateInstance( - __uuidof(WindowsParentalControls)); - if (FAILED(hr)) - return false; - - ScopedComPtr<IWPCSettings> settings; - hr = parent_controls->GetUserSettings(NULL, settings.Receive()); - if (FAILED(hr)) - return false; - - unsigned long restrictions = 0; - settings->GetRestrictions(&restrictions); - - parental_control_logging_required = - (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED; - return parental_control_logging_required; -} - // Metro driver exports for getting the launch type, initial url, initial // search term, etc. extern "C" { diff --git a/base/win/metro.h b/base/win/metro.h index 5894ef0..0696006 100644 --- a/base/win/metro.h +++ b/base/win/metro.h @@ -6,7 +6,6 @@ #define BASE_WIN_METRO_H_ #include <windows.h> -#include <wpcapi.h> #include "base/base_export.h" #include "base/callback.h" @@ -80,11 +79,6 @@ BASE_EXPORT bool IsProcessImmersive(HANDLE process); // copying the src to it. BASE_EXPORT wchar_t* LocalAllocAndCopyString(const string16& src); -// Returns true if Windows Parental control activity logging is enabled. This -// feature is available on Windows Vista and beyond. -// This function should ideally be called on the UI thread. -BASE_EXPORT bool IsParentalControlActivityLoggingOn(); - // Returns the type of launch and the activation params. For example if the // the launch is for METRO_PROTOCOL then the params is a url. BASE_EXPORT MetroLaunchType GetMetroLaunchParams(string16* params); diff --git a/chrome/browser/chrome_browser_main_win.cc b/chrome/browser/chrome_browser_main_win.cc index 822cd3c..3458df2 100644 --- a/chrome/browser/chrome_browser_main_win.cc +++ b/chrome/browser/chrome_browser_main_win.cc @@ -14,6 +14,7 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/i18n/rtl.h" +#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/metrics/histogram.h" #include "base/path_service.h" @@ -211,7 +212,8 @@ void ChromeBrowserMainPartsWin::PreMainMessageLoopStart() { InitializeWindowProcExceptions(); } - IncognitoModePrefs::InitializePlatformParentalControls(); + // Prime the parental controls cache on Windows. + ignore_result(IncognitoModePrefs::ArePlatformParentalControlsEnabled()); } int ChromeBrowserMainPartsWin::PreCreateThreads() { diff --git a/chrome/browser/prefs/incognito_mode_prefs.cc b/chrome/browser/prefs/incognito_mode_prefs.cc index e0255d4..06bb0e0 100644 --- a/chrome/browser/prefs/incognito_mode_prefs.cc +++ b/chrome/browser/prefs/incognito_mode_prefs.cc @@ -7,25 +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() { + // 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; + + base::win::ScopedComPtr<IWindowsParentalControlsCore> parent_controls; + HRESULT hr = parent_controls.CreateInstance( + __uuidof(WindowsParentalControls)); + if (FAILED(hr)) + return false; -} // empty namespace + base::win::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; +} + +} // namespace #endif // OS_WIN // static @@ -104,25 +138,26 @@ 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; + enum class ParentalControlsState { + UNKNOWN = 0, + ACTIVITY_LOGGING_DISABLED = 1, + ACTIVITY_LOGGING_ENABLED = 2, + }; + static ParentalControlsState parental_controls_state = + ParentalControlsState::UNKNOWN; + if (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) || + BrowserThread::CurrentlyOn(BrowserThread::UI)); + parental_controls_state = + IsParentalControlActivityLoggingOn() ? + ParentalControlsState::ACTIVITY_LOGGING_ENABLED : + ParentalControlsState::ACTIVITY_LOGGING_DISABLED; + } + return parental_controls_state == + ParentalControlsState::ACTIVITY_LOGGING_ENABLED; #elif defined(OS_ANDROID) return chrome::android::ChromiumApplication::AreParentalControlsEnabled(); #else diff --git a/chrome/browser/prefs/incognito_mode_prefs.h b/chrome/browser/prefs/incognito_mode_prefs.h index 0837cb4..6cb3f90 100644 --- a/chrome/browser/prefs/incognito_mode_prefs.h +++ b/chrome/browser/prefs/incognito_mode_prefs.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_PREFS_INCOGNITO_MODE_PREFS_H_ #include "base/basictypes.h" +#include "base/compiler_specific.h" class PrefService; class Profile; @@ -64,21 +65,12 @@ class IncognitoModePrefs { static bool CanOpenBrowser(Profile* profile); // Returns whether parental controls have been enabled on the platform. This - // method simply returns a cached value and thus the result may be stale. May - // be called on any thread. - static bool ArePlatformParentalControlsEnabledCached(); - -#if defined(OS_WIN) - // Initializes the parental control settings. Must be called on UI thread and - // before |ArePlatformParentalControlsEnabled|. - static void InitializePlatformParentalControls(); -#endif // OS_WIN + // method evaluates and caches if the platform controls have been enabled on + // the first call, which must be on the UI thread when IO and blocking are + // allowed. Subsequent calls may be from any thread. + static bool ArePlatformParentalControlsEnabled() WARN_UNUSED_RESULT; private: - // Returns whether parental controls have been enabled on the platform, which - // if enabled will overrule the Availability as configured in prefs. - static bool ArePlatformParentalControlsEnabled(); - DISALLOW_IMPLICIT_CONSTRUCTORS(IncognitoModePrefs); }; diff --git a/chrome/browser/signin/signin_header_helper.cc b/chrome/browser/signin/signin_header_helper.cc index 8909ced..674a59f 100644 --- a/chrome/browser/signin/signin_header_helper.cc +++ b/chrome/browser/signin/signin_header_helper.cc @@ -256,7 +256,7 @@ bool AppendMirrorRequestHeaderIfPossible( int profile_mode_mask = PROFILE_MODE_DEFAULT; if (io_data->incognito_availibility()->GetValue() == IncognitoModePrefs::DISABLED || - IncognitoModePrefs::ArePlatformParentalControlsEnabledCached()) { + IncognitoModePrefs::ArePlatformParentalControlsEnabled()) { profile_mode_mask |= PROFILE_MODE_INCOGNITO_DISABLED; } |