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