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

Side by Side Diff: chrome/browser/extensions/external_provider_impl.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 unified diff | Download patch
OLDNEW
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 "chrome/browser/extensions/external_provider_impl.h" 5 #include "chrome/browser/extensions/external_provider_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) { 113 void ExternalProviderImpl::SetPrefs(base::DictionaryValue* prefs) {
114 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 114 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
115 115
116 // Check if the service is still alive. It is possible that it went 116 // Check if the service is still alive. It is possible that it went
117 // away while |loader_| was working on the FILE thread. 117 // away while |loader_| was working on the FILE thread.
118 if (!service_) return; 118 if (!service_) return;
119 119
120 prefs_.reset(prefs); 120 prefs_.reset(prefs);
121 ready_ = true; // Queries for extensions are allowed from this point. 121 ready_ = true; // Queries for extensions are allowed from this point.
122 NotifyExtensionsFromPrefs(true);
123 service_->OnExternalProviderReady(this);
124 }
122 125
126 void ExternalProviderImpl::UpdatePrefs(base::DictionaryValue* prefs) {
127 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
128 // We only expect updates from windows registry.
129 CHECK(crx_location_ == Manifest::EXTERNAL_REGISTRY);
130
131 // Check if the service is still alive. It is possible that it went
132 // away while |loader_| was working on the FILE thread.
133 if (!service_)
134 return;
135
136 std::set<std::string> removed_extensions;
137 // Find extensions that were removed by this ExternalProvider.
138 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) {
139 const std::string& extension_id = i.key();
140 // Don't bother about invalid ids.
141 if (!crx_file::id_util::IdIsValid(extension_id))
142 continue;
143 if (!prefs->HasKey(extension_id))
144 removed_extensions.insert(extension_id);
145 }
146
147 prefs_.reset(prefs);
148
149 // Notify ExtensionService about all the extension this provider has found
150 // "updates" for.
151 // For each update found, this will end up calling
152 // OnExternalExtensionUpdateUrlFound() or OnExternalExtensionFileFound().
153 NotifyExtensionsFromPrefs(false);
154 // Then notify about the completion of update, with list of extensions that
155 // were removed.
156 service_->OnExternalProviderUpdateComplete(this, removed_extensions);
157 }
158
159 void ExternalProviderImpl::NotifyExtensionsFromPrefs(bool is_initial_load) {
123 // Set of unsupported extensions that need to be deleted from prefs_. 160 // Set of unsupported extensions that need to be deleted from prefs_.
124 std::set<std::string> unsupported_extensions; 161 std::set<std::string> unsupported_extensions;
125 162
126 // Notify ExtensionService about all the extensions this provider has. 163 // Notify ExtensionService about all the extensions this provider has.
127 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { 164 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) {
128 const std::string& extension_id = i.key(); 165 const std::string& extension_id = i.key();
129 const base::DictionaryValue* extension = NULL; 166 const base::DictionaryValue* extension = NULL;
130 167
131 if (!crx_file::id_util::IdIsValid(extension_id)) { 168 if (!crx_file::id_util::IdIsValid(extension_id)) {
132 LOG(WARNING) << "Malformed extension dictionary: key " 169 LOG(WARNING) << "Malformed extension dictionary: key "
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 << extension_id.c_str() << ". Key " << kExternalUpdateUrl 350 << extension_id.c_str() << ". Key " << kExternalUpdateUrl
314 << " has value \"" << external_update_url 351 << " has value \"" << external_update_url
315 << "\", which is not a valid URL."; 352 << "\", which is not a valid URL.";
316 continue; 353 continue;
317 } 354 }
318 service_->OnExternalExtensionUpdateUrlFound(extension_id, 355 service_->OnExternalExtensionUpdateUrlFound(extension_id,
319 install_parameter, 356 install_parameter,
320 update_url, 357 update_url,
321 download_location_, 358 download_location_,
322 creation_flags, 359 creation_flags,
323 auto_acknowledge_); 360 auto_acknowledge_,
361 is_initial_load);
324 } 362 }
325 } 363 }
326 364
327 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); 365 for (std::set<std::string>::iterator it = unsupported_extensions.begin();
328 it != unsupported_extensions.end(); ++it) { 366 it != unsupported_extensions.end(); ++it) {
329 // Remove extension for the list of know external extensions. The extension 367 // Remove extension for the list of know external extensions. The extension
330 // will be uninstalled later because provider doesn't provide it anymore. 368 // will be uninstalled later because provider doesn't provide it anymore.
331 prefs_->Remove(*it, NULL); 369 prefs_->Remove(*it, NULL);
332 } 370 }
333
334 service_->OnExternalProviderReady(this);
335 } 371 }
336 372
337 void ExternalProviderImpl::ServiceShutdown() { 373 void ExternalProviderImpl::ServiceShutdown() {
338 service_ = NULL; 374 service_ = NULL;
339 } 375 }
340 376
341 bool ExternalProviderImpl::IsReady() const { 377 bool ExternalProviderImpl::IsReady() const {
342 return ready_; 378 return ready_;
343 } 379 }
344 380
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 new ExternalProviderImpl( 727 new ExternalProviderImpl(
692 service, 728 service,
693 new ExternalComponentLoader(profile), 729 new ExternalComponentLoader(profile),
694 profile, 730 profile,
695 Manifest::INVALID_LOCATION, 731 Manifest::INVALID_LOCATION,
696 Manifest::EXTERNAL_COMPONENT, 732 Manifest::EXTERNAL_COMPONENT,
697 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT))); 733 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT)));
698 } 734 }
699 735
700 } // namespace extensions 736 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698