Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/win/metro.h" | 5 #include "base/win/metro.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/win/scoped_comptr.h" | 9 #include "base/win/scoped_comptr.h" |
| 10 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
| 11 | 11 |
| 12 namespace { | |
| 13 | |
| 14 bool parental_control_logging_required = false; | |
|
Bernhard Bauer
2014/06/17 09:15:45
Global (mutable) variables are usually named start
guohui
2014/06/17 18:45:03
Done.
| |
| 15 bool parental_control_status_determined = false; | |
| 16 | |
| 17 } // empty namespace | |
| 18 | |
| 12 namespace base { | 19 namespace base { |
| 13 namespace win { | 20 namespace win { |
| 14 | 21 |
| 15 HMODULE GetMetroModule() { | 22 HMODULE GetMetroModule() { |
| 16 const HMODULE kUninitialized = reinterpret_cast<HMODULE>(1); | 23 const HMODULE kUninitialized = reinterpret_cast<HMODULE>(1); |
| 17 static HMODULE metro_module = kUninitialized; | 24 static HMODULE metro_module = kUninitialized; |
| 18 | 25 |
| 19 if (metro_module == kUninitialized) { | 26 if (metro_module == kUninitialized) { |
| 20 // Initialize the cache, note that the initialization is idempotent | 27 // Initialize the cache, note that the initialization is idempotent |
| 21 // under the assumption that metro_driver is never unloaded, so the | 28 // under the assumption that metro_driver is never unloaded, so the |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 } | 74 } |
| 68 | 75 |
| 69 wchar_t* LocalAllocAndCopyString(const string16& src) { | 76 wchar_t* LocalAllocAndCopyString(const string16& src) { |
| 70 size_t dest_size = (src.length() + 1) * sizeof(wchar_t); | 77 size_t dest_size = (src.length() + 1) * sizeof(wchar_t); |
| 71 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size)); | 78 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size)); |
| 72 base::wcslcpy(dest, src.c_str(), dest_size); | 79 base::wcslcpy(dest, src.c_str(), dest_size); |
| 73 return dest; | 80 return dest; |
| 74 } | 81 } |
| 75 | 82 |
| 76 bool IsParentalControlActivityLoggingOn() { | 83 bool IsParentalControlActivityLoggingOn() { |
| 77 // Query this info on Windows Vista and above. | |
| 78 if (base::win::GetVersion() < base::win::VERSION_VISTA) | |
| 79 return false; | |
| 80 | |
| 81 static bool parental_control_logging_required = false; | |
| 82 static bool parental_control_status_determined = false; | |
| 83 | |
| 84 if (parental_control_status_determined) | 84 if (parental_control_status_determined) |
| 85 return parental_control_logging_required; | 85 return parental_control_logging_required; |
| 86 | 86 |
| 87 parental_control_status_determined = true; | 87 parental_control_status_determined = true; |
| 88 | 88 |
| 89 // Query this info on Windows Vista and above. | |
| 90 if (base::win::GetVersion() < base::win::VERSION_VISTA) | |
| 91 return false; | |
| 92 | |
| 89 ScopedComPtr<IWindowsParentalControlsCore> parent_controls; | 93 ScopedComPtr<IWindowsParentalControlsCore> parent_controls; |
| 90 HRESULT hr = parent_controls.CreateInstance( | 94 HRESULT hr = parent_controls.CreateInstance( |
| 91 __uuidof(WindowsParentalControls)); | 95 __uuidof(WindowsParentalControls)); |
| 92 if (FAILED(hr)) | 96 if (FAILED(hr)) |
| 93 return false; | 97 return false; |
| 94 | 98 |
| 95 ScopedComPtr<IWPCSettings> settings; | 99 ScopedComPtr<IWPCSettings> settings; |
| 96 hr = parent_controls->GetUserSettings(NULL, settings.Receive()); | 100 hr = parent_controls->GetUserSettings(NULL, settings.Receive()); |
| 97 if (FAILED(hr)) | 101 if (FAILED(hr)) |
| 98 return false; | 102 return false; |
| 99 | 103 |
| 100 unsigned long restrictions = 0; | 104 unsigned long restrictions = 0; |
| 101 settings->GetRestrictions(&restrictions); | 105 settings->GetRestrictions(&restrictions); |
| 102 | 106 |
| 103 parental_control_logging_required = | 107 parental_control_logging_required = |
| 104 (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED; | 108 (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED; |
| 105 return parental_control_logging_required; | 109 return parental_control_logging_required; |
| 106 } | 110 } |
| 107 | 111 |
| 112 bool IsParentalControlActivityLoggingOnCached() { | |
| 113 DCHECK(parental_control_status_determined); | |
| 114 return parental_control_logging_required; | |
| 115 } | |
| 116 | |
| 108 // Metro driver exports for getting the launch type, initial url, initial | 117 // Metro driver exports for getting the launch type, initial url, initial |
| 109 // search term, etc. | 118 // search term, etc. |
| 110 extern "C" { | 119 extern "C" { |
| 111 typedef const wchar_t* (*GetInitialUrl)(); | 120 typedef const wchar_t* (*GetInitialUrl)(); |
| 112 typedef const wchar_t* (*GetInitialSearchString)(); | 121 typedef const wchar_t* (*GetInitialSearchString)(); |
| 113 typedef base::win::MetroLaunchType (*GetLaunchType)( | 122 typedef base::win::MetroLaunchType (*GetLaunchType)( |
| 114 base::win::MetroPreviousExecutionState* previous_state); | 123 base::win::MetroPreviousExecutionState* previous_state); |
| 115 } | 124 } |
| 116 | 125 |
| 117 MetroLaunchType GetMetroLaunchParams(string16* params) { | 126 MetroLaunchType GetMetroLaunchParams(string16* params) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 136 reinterpret_cast<GetInitialSearchString>( | 145 reinterpret_cast<GetInitialSearchString>( |
| 137 ::GetProcAddress(metro, "GetInitialSearchString")); | 146 ::GetProcAddress(metro, "GetInitialSearchString")); |
| 138 DCHECK(initial_search_string); | 147 DCHECK(initial_search_string); |
| 139 *params = initial_search_string(); | 148 *params = initial_search_string(); |
| 140 } | 149 } |
| 141 return launch_type; | 150 return launch_type; |
| 142 } | 151 } |
| 143 | 152 |
| 144 } // namespace win | 153 } // namespace win |
| 145 } // namespace base | 154 } // namespace base |
| OLD | NEW |