[email protected] | f4091a3 | 2012-06-05 22:21:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 5 | #include "chrome/browser/extensions/external_registry_loader_win.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 6 | |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
[email protected] | 8e6ac4b | 2011-10-17 19:04:31 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 10 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 11 | #include "base/files/file_util.h" |
[email protected] | 0910bae | 2014-06-10 17:53:21 | [diff] [blame] | 12 | #include "base/files/scoped_file.h" |
asvitkine | aa06031 | 2016-09-01 22:44:13 | [diff] [blame] | 13 | #include "base/metrics/histogram_macros.h" |
Gabriel Charette | 1452023 | 2018-04-30 23:27:22 | [diff] [blame^] | 14 | #include "base/sequenced_task_runner.h" |
[email protected] | 46acbf1 | 2013-06-10 18:43:42 | [diff] [blame] | 15 | #include "base/strings/string_util.h" |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 16 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 18 | #include "base/task_scheduler/post_task.h" |
| 19 | #include "base/threading/thread_restrictions.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 20 | #include "base/time/time.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 21 | #include "base/values.h" |
| 22 | #include "base/version.h" |
| 23 | #include "base/win/registry.h" |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 24 | #include "chrome/browser/extensions/external_provider_impl.h" |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 25 | #include "components/crx_file/id_util.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 26 | #include "content/public/browser/browser_thread.h" |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 27 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 28 | using content::BrowserThread; |
| 29 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 30 | namespace { |
| 31 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 32 | // The Registry subkey that contains information about external extensions. |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 33 | const base::char16 kRegistryExtensions[] = |
| 34 | L"Software\\Google\\Chrome\\Extensions"; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 35 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 36 | // Registry value of the key that defines the installation parameter. |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 37 | const base::char16 kRegistryExtensionInstallParam[] = L"install_parameter"; |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 38 | |
[email protected] | 5873a5a | 2013-12-16 19:53:00 | [diff] [blame] | 39 | // Registry value of the key that defines the path to the .crx file. |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 40 | const base::char16 kRegistryExtensionPath[] = L"path"; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 41 | |
| 42 | // Registry value of that key that defines the current version of the .crx file. |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 43 | const base::char16 kRegistryExtensionVersion[] = L"version"; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 44 | |
[email protected] | 5873a5a | 2013-12-16 19:53:00 | [diff] [blame] | 45 | // Registry value of the key that defines an external update URL. |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 46 | const base::char16 kRegistryExtensionUpdateUrl[] = L"update_url"; |
[email protected] | 5873a5a | 2013-12-16 19:53:00 | [diff] [blame] | 47 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 48 | bool CanOpenFileForReading(const base::FilePath& path) { |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 49 | // Note: Because this ScopedFILE is used on the stack and not passed around |
| 50 | // threads/sequences, this method doesn't require callers to run on tasks with |
| 51 | // BLOCK_SHUTDOWN. SKIP_ON_SHUTDOWN is enough and safe because it guarantees |
| 52 | // that if a task starts, it will always finish, and will block shutdown at |
| 53 | // that point. |
[email protected] | 0910bae | 2014-06-10 17:53:21 | [diff] [blame] | 54 | base::ScopedFILE file_handle(base::OpenFile(path, "rb")); |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 55 | return file_handle.get() != NULL; |
| 56 | } |
| 57 | |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 58 | std::string MakePrefName(const std::string& extension_id, |
| 59 | const std::string& pref_name) { |
| 60 | return base::StringPrintf("%s.%s", extension_id.c_str(), pref_name.c_str()); |
| 61 | } |
| 62 | |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 63 | } // namespace |
| 64 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 65 | namespace extensions { |
| 66 | |
lazyboy | 3692027 | 2017-04-04 23:51:32 | [diff] [blame] | 67 | ExternalRegistryLoader::ExternalRegistryLoader() |
| 68 | : attempted_watching_registry_(false) {} |
| 69 | |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 70 | ExternalRegistryLoader::~ExternalRegistryLoader() {} |
| 71 | |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 72 | void ExternalRegistryLoader::StartLoading() { |
Istiaque Ahmed | f6e7262 | 2017-09-08 23:14:17 | [diff] [blame] | 73 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 74 | GetOrCreateTaskRunner()->PostTask( |
| 75 | FROM_HERE, |
| 76 | base::BindOnce(&ExternalRegistryLoader::LoadOnBlockingThread, this)); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 77 | } |
| 78 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 79 | std::unique_ptr<base::DictionaryValue> |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 80 | ExternalRegistryLoader::LoadPrefsOnBlockingThread() { |
Francois Doray | 66bdfd8 | 2017-10-20 13:50:37 | [diff] [blame] | 81 | base::AssertBlockingAllowed(); |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 82 | auto prefs = std::make_unique<base::DictionaryValue>(); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 83 | |
[email protected] | 1358b28 | 2011-09-15 15:35:14 | [diff] [blame] | 84 | // A map of IDs, to weed out duplicates between HKCU and HKLM. |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 85 | std::set<base::string16> keys; |
[email protected] | 1358b28 | 2011-09-15 15:35:14 | [diff] [blame] | 86 | base::win::RegistryKeyIterator iterator_machine_key( |
wfh | 9353beb9 | 2014-10-09 04:31:38 | [diff] [blame] | 87 | HKEY_LOCAL_MACHINE, |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 88 | kRegistryExtensions, |
wfh | 9353beb9 | 2014-10-09 04:31:38 | [diff] [blame] | 89 | KEY_WOW64_32KEY); |
[email protected] | 1358b28 | 2011-09-15 15:35:14 | [diff] [blame] | 90 | for (; iterator_machine_key.Valid(); ++iterator_machine_key) |
| 91 | keys.insert(iterator_machine_key.Name()); |
| 92 | base::win::RegistryKeyIterator iterator_user_key( |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 93 | HKEY_CURRENT_USER, kRegistryExtensions); |
[email protected] | 1358b28 | 2011-09-15 15:35:14 | [diff] [blame] | 94 | for (; iterator_user_key.Valid(); ++iterator_user_key) |
| 95 | keys.insert(iterator_user_key.Name()); |
| 96 | |
| 97 | // Iterate over the keys found, first trying HKLM, then HKCU, as per Windows |
| 98 | // policy conventions. We only fall back to HKCU if the HKLM key cannot be |
| 99 | // opened, not if the data within the key is invalid, for example. |
[email protected] | d2065e06 | 2013-12-12 23:49:52 | [diff] [blame] | 100 | for (std::set<base::string16>::const_iterator it = keys.begin(); |
[email protected] | 1358b28 | 2011-09-15 15:35:14 | [diff] [blame] | 101 | it != keys.end(); ++it) { |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 102 | base::win::RegKey key; |
thestig | 11bf74d | 2014-11-24 20:14:42 | [diff] [blame] | 103 | base::string16 key_path = kRegistryExtensions; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 104 | key_path.append(L"\\"); |
[email protected] | 1358b28 | 2011-09-15 15:35:14 | [diff] [blame] | 105 | key_path.append(*it); |
| 106 | if (key.Open(HKEY_LOCAL_MACHINE, |
wfh | 9353beb9 | 2014-10-09 04:31:38 | [diff] [blame] | 107 | key_path.c_str(), |
| 108 | KEY_READ | KEY_WOW64_32KEY) != ERROR_SUCCESS && |
| 109 | key.Open(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ) != |
| 110 | ERROR_SUCCESS) { |
| 111 | LOG(ERROR) << "Unable to read registry key at path (HKLM & HKCU): " |
| 112 | << key_path << "."; |
| 113 | continue; |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 114 | } |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 115 | |
brettw | fce8d19 | 2015-08-10 19:07:51 | [diff] [blame] | 116 | std::string id = base::ToLowerASCII(base::UTF16ToASCII(*it)); |
[email protected] | fdd2837 | 2014-08-21 02:27:26 | [diff] [blame] | 117 | if (!crx_file::id_util::IdIsValid(id)) { |
[email protected] | 5873a5a | 2013-12-16 19:53:00 | [diff] [blame] | 118 | LOG(ERROR) << "Invalid id value " << id |
| 119 | << " for key " << key_path << "."; |
| 120 | continue; |
| 121 | } |
| 122 | |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 123 | base::string16 extension_dist_id; |
| 124 | if (key.ReadValue(kRegistryExtensionInstallParam, &extension_dist_id) == |
| 125 | ERROR_SUCCESS) { |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 126 | prefs->SetString(MakePrefName(id, ExternalProviderImpl::kInstallParam), |
[email protected] | d8fd0fd | 2014-03-24 13:16:06 | [diff] [blame] | 127 | base::UTF16ToASCII(extension_dist_id)); |
| 128 | } |
| 129 | |
[email protected] | 5873a5a | 2013-12-16 19:53:00 | [diff] [blame] | 130 | // If there is an update URL present, copy it to prefs and ignore |
| 131 | // path and version keys for this entry. |
| 132 | base::string16 extension_update_url; |
| 133 | if (key.ReadValue(kRegistryExtensionUpdateUrl, &extension_update_url) |
| 134 | == ERROR_SUCCESS) { |
| 135 | prefs->SetString( |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 136 | MakePrefName(id, ExternalProviderImpl::kExternalUpdateUrl), |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 137 | base::UTF16ToASCII(extension_update_url)); |
[email protected] | 5873a5a | 2013-12-16 19:53:00 | [diff] [blame] | 138 | continue; |
| 139 | } |
| 140 | |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 141 | base::string16 extension_path_str; |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 142 | if (key.ReadValue(kRegistryExtensionPath, &extension_path_str) |
| 143 | != ERROR_SUCCESS) { |
| 144 | // TODO(erikkay): find a way to get this into about:extensions |
| 145 | LOG(ERROR) << "Missing value " << kRegistryExtensionPath |
| 146 | << " for key " << key_path << "."; |
| 147 | continue; |
| 148 | } |
| 149 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 150 | base::FilePath extension_path(extension_path_str); |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 151 | if (!extension_path.IsAbsolute()) { |
| 152 | LOG(ERROR) << "File path " << extension_path_str |
| 153 | << " needs to be absolute in key " |
| 154 | << key_path; |
| 155 | continue; |
| 156 | } |
| 157 | |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 158 | if (!base::PathExists(extension_path)) { |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 159 | LOG(ERROR) << "File " << extension_path_str |
| 160 | << " for key " << key_path |
| 161 | << " does not exist or is not readable."; |
| 162 | continue; |
| 163 | } |
| 164 | |
| 165 | if (!CanOpenFileForReading(extension_path)) { |
| 166 | LOG(ERROR) << "File " << extension_path_str |
| 167 | << " for key " << key_path << " can not be read. " |
| 168 | << "Check that users who should have the extension " |
| 169 | << "installed have permission to read it."; |
| 170 | continue; |
| 171 | } |
| 172 | |
[email protected] | 439f1e3 | 2013-12-09 20:09:09 | [diff] [blame] | 173 | base::string16 extension_version; |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 174 | if (key.ReadValue(kRegistryExtensionVersion, &extension_version) |
| 175 | != ERROR_SUCCESS) { |
| 176 | // TODO(erikkay): find a way to get this into about:extensions |
| 177 | LOG(ERROR) << "Missing value " << kRegistryExtensionVersion |
| 178 | << " for key " << key_path << "."; |
| 179 | continue; |
| 180 | } |
| 181 | |
pwnall | cbd7319 | 2016-08-22 18:59:17 | [diff] [blame] | 182 | base::Version version(base::UTF16ToASCII(extension_version)); |
[email protected] | 12126d37 | 2012-07-11 18:40:53 | [diff] [blame] | 183 | if (!version.IsValid()) { |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 184 | LOG(ERROR) << "Invalid version value " << extension_version |
| 185 | << " for key " << key_path << "."; |
| 186 | continue; |
| 187 | } |
| 188 | |
| 189 | prefs->SetString( |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 190 | MakePrefName(id, ExternalProviderImpl::kExternalVersion), |
[email protected] | 74f778e | 2014-03-14 21:11:46 | [diff] [blame] | 191 | base::UTF16ToASCII(extension_version)); |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 192 | prefs->SetString( |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 193 | MakePrefName(id, ExternalProviderImpl::kExternalCrx), |
[email protected] | b967a1b | 2011-08-17 14:39:58 | [diff] [blame] | 194 | extension_path_str); |
[email protected] | 2b6a580 | 2014-08-16 07:58:08 | [diff] [blame] | 195 | prefs->SetBoolean( |
| 196 | MakePrefName(id, ExternalProviderImpl::kMayBeUntrusted), |
| 197 | true); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 198 | } |
| 199 | |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 200 | return prefs; |
| 201 | } |
| 202 | |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 203 | void ExternalRegistryLoader::LoadOnBlockingThread() { |
| 204 | DCHECK(task_runner_); |
| 205 | DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 206 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 207 | std::unique_ptr<base::DictionaryValue> prefs = LoadPrefsOnBlockingThread(); |
asvitkine | c0fb802 | 2014-08-26 04:39:35 | [diff] [blame] | 208 | LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin", |
| 209 | base::TimeTicks::Now() - start_time); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 210 | BrowserThread::PostTask( |
| 211 | BrowserThread::UI, FROM_HERE, |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 212 | base::Bind(&ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry, |
lazyboy | 57972e0 | 2017-04-12 22:40:59 | [diff] [blame] | 213 | this, base::Passed(&prefs))); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 214 | } |
| 215 | |
lazyboy | 57972e0 | 2017-04-12 22:40:59 | [diff] [blame] | 216 | void ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry( |
| 217 | std::unique_ptr<base::DictionaryValue> prefs) { |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 218 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
lazyboy | 57972e0 | 2017-04-12 22:40:59 | [diff] [blame] | 219 | DCHECK(prefs); |
Istiaque Ahmed | ef99c8ea | 2017-09-06 21:19:57 | [diff] [blame] | 220 | LoadFinished(std::move(prefs)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 221 | |
lazyboy | 3692027 | 2017-04-04 23:51:32 | [diff] [blame] | 222 | // Attempt to watch registry if we haven't already. |
| 223 | if (attempted_watching_registry_) |
| 224 | return; |
| 225 | |
wez | 2884d9b | 2017-02-15 01:19:26 | [diff] [blame] | 226 | LONG result = ERROR_SUCCESS; |
| 227 | if ((result = hklm_key_.Create(HKEY_LOCAL_MACHINE, kRegistryExtensions, |
| 228 | KEY_NOTIFY | KEY_WOW64_32KEY)) == |
| 229 | ERROR_SUCCESS) { |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 230 | base::win::RegKey::ChangeCallback callback = |
| 231 | base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, |
| 232 | base::Unretained(this), base::Unretained(&hklm_key_)); |
| 233 | hklm_key_.StartWatching(callback); |
| 234 | } else { |
wez | 2884d9b | 2017-02-15 01:19:26 | [diff] [blame] | 235 | LOG(WARNING) << "Error observing HKLM: " << result; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 236 | } |
| 237 | |
wez | 2884d9b | 2017-02-15 01:19:26 | [diff] [blame] | 238 | if ((result = hkcu_key_.Create(HKEY_CURRENT_USER, kRegistryExtensions, |
| 239 | KEY_NOTIFY)) == ERROR_SUCCESS) { |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 240 | base::win::RegKey::ChangeCallback callback = |
| 241 | base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, |
| 242 | base::Unretained(this), base::Unretained(&hkcu_key_)); |
| 243 | hkcu_key_.StartWatching(callback); |
| 244 | } else { |
wez | 2884d9b | 2017-02-15 01:19:26 | [diff] [blame] | 245 | LOG(WARNING) << "Error observing HKCU: " << result; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 246 | } |
lazyboy | 3692027 | 2017-04-04 23:51:32 | [diff] [blame] | 247 | |
| 248 | attempted_watching_registry_ = true; |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) { |
| 252 | // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is |
| 253 | // called, so we need to re-register. |
| 254 | key->StartWatching(base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged, |
| 255 | base::Unretained(this), base::Unretained(key))); |
| 256 | |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 257 | GetOrCreateTaskRunner()->PostTask( |
| 258 | FROM_HERE, |
| 259 | base::BindOnce(&ExternalRegistryLoader::UpatePrefsOnBlockingThread, |
| 260 | this)); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 261 | } |
| 262 | |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 263 | scoped_refptr<base::SequencedTaskRunner> |
| 264 | ExternalRegistryLoader::GetOrCreateTaskRunner() { |
| 265 | if (!task_runner_.get()) { |
| 266 | task_runner_ = base::CreateSequencedTaskRunnerWithTraits( |
| 267 | {// Requires I/O for registry. |
| 268 | base::MayBlock(), |
| 269 | |
| 270 | // Inherit priority. |
| 271 | |
| 272 | base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}); |
| 273 | } |
| 274 | return task_runner_; |
| 275 | } |
| 276 | |
| 277 | void ExternalRegistryLoader::UpatePrefsOnBlockingThread() { |
| 278 | DCHECK(task_runner_); |
| 279 | DCHECK(task_runner_->RunsTasksInCurrentSequence()); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 280 | base::TimeTicks start_time = base::TimeTicks::Now(); |
Istiaque Ahmed | 35e30fd | 2017-08-10 17:41:30 | [diff] [blame] | 281 | std::unique_ptr<base::DictionaryValue> prefs = LoadPrefsOnBlockingThread(); |
lazyboy | e863417 | 2016-01-28 00:10:48 | [diff] [blame] | 282 | LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate", |
| 283 | base::TimeTicks::Now() - start_time); |
| 284 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 285 | base::Bind(&ExternalRegistryLoader::OnUpdated, this, |
| 286 | base::Passed(&prefs))); |
[email protected] | 8e4560b6 | 2011-01-14 10:09:14 | [diff] [blame] | 287 | } |
[email protected] | 5df038b | 2012-07-16 19:03:27 | [diff] [blame] | 288 | |
| 289 | } // namespace extensions |