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

Unified Diff: chrome/browser/extensions/external_registry_loader_win.cc

Issue 1495403002: Observe adding external extensions via windows registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments from asargent and devlin Created 4 years, 11 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/extensions/external_registry_loader_win.cc
diff --git a/chrome/browser/extensions/external_registry_loader_win.cc b/chrome/browser/extensions/external_registry_loader_win.cc
index 0b5a67f83687c838b7723790af6f0953dc435e9f..bdda83fc1f8ac7871cedafe6c5c56bb4b3356dd1 100644
--- a/chrome/browser/extensions/external_registry_loader_win.cc
+++ b/chrome/browser/extensions/external_registry_loader_win.cc
@@ -61,9 +61,8 @@ void ExternalRegistryLoader::StartLoading() {
base::Bind(&ExternalRegistryLoader::LoadOnFileThread, this));
}
-void ExternalRegistryLoader::LoadOnFileThread() {
+void ExternalRegistryLoader::LoadPrefsOnFileThread() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- base::TimeTicks start_time = base::TimeTicks::Now();
scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue);
// A map of IDs, to weed out duplicates between HKCU and HKLM.
@@ -183,11 +182,74 @@ void ExternalRegistryLoader::LoadOnFileThread() {
}
prefs_.reset(prefs.release());
+}
+
+void ExternalRegistryLoader::LoadOnFileThread() {
+ base::TimeTicks start_time = base::TimeTicks::Now();
+ LoadPrefsOnFileThread();
LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWin",
base::TimeTicks::Now() - start_time);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(&ExternalRegistryLoader::LoadFinished, this));
+ base::Bind(
+ &ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry, this));
+}
+
+void ExternalRegistryLoader::CompleteLoadAndStartWatchingRegistry() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ LoadFinished();
+
+ // Start watching registry.
+ // TODO(lazyboy): Is using KEY_WOW64_32KEY correct?
+ if (hklm_key_.Create(HKEY_LOCAL_MACHINE,
+ kRegistryExtensions,
+ KEY_NOTIFY | KEY_WOW64_32KEY) == ERROR_SUCCESS) {
scottmg 2016/01/21 21:16:16 How are these keys set? Is this because the instal
lazyboy 2016/01/21 21:24:47 I'm not sure about this one (as the TODO suggests)
asargent_no_longer_on_chrome 2016/01/25 18:50:52 These registry entries are written by third party
lazyboy 2016/01/26 05:20:04 I'll drop by to talk to you person about this one
lazyboy 2016/01/26 23:44:43 After chatting /w asargent@, I've removed the TODO
+ base::win::RegKey::ChangeCallback callback =
+ base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged,
+ base::Unretained(this),
+ base::Unretained(&hklm_key_));
+ hklm_key_.StartWatching(callback);
+ } else {
+ // TODO(lazyboy): Error handling.
+ LOG(ERROR) << "Error observing HKLM.";
+ }
+
+ if (hkcu_key_.Create(HKEY_CURRENT_USER,
+ kRegistryExtensions,
+ KEY_NOTIFY) == ERROR_SUCCESS) {
+ base::win::RegKey::ChangeCallback callback =
+ base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged,
+ base::Unretained(this),
+ base::Unretained(&hkcu_key_));
+ hkcu_key_.StartWatching(callback);
+ } else {
+ // TODO(lazyboy): Error handling.
+ LOG(ERROR) << "Error observing HKCU.";
+ }
+}
+
+void ExternalRegistryLoader::OnRegistryKeyChanged(base::win::RegKey* key) {
+ // |OnRegistryKeyChanged| is removed as an observer when the ChangeCallback is
+ // called, so we need to re-register.
+ key->StartWatching(
+ base::Bind(&ExternalRegistryLoader::OnRegistryKeyChanged,
+ base::Unretained(this),
+ base::Unretained(key)));
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&ExternalRegistryLoader::UpdatePrefsOnFileThread, this));
+}
+
+void ExternalRegistryLoader::UpdatePrefsOnFileThread() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ base::TimeTicks start_time = base::TimeTicks::Now();
+ LoadPrefsOnFileThread();
+ LOCAL_HISTOGRAM_TIMES("Extensions.ExternalRegistryLoaderWinUpdate",
+ base::TimeTicks::Now() - start_time);
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&ExternalRegistryLoader::OnUpdated, this));
}
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/external_registry_loader_win.h ('k') | extensions/browser/external_provider_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698