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 "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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 122 |
| 123 ScopedVector<UpdateUrlExtensionInfo> external_update_url_extensions; |
| 124 ScopedVector<FileExtensionInfo> external_file_extensions; |
| 125 |
| 126 RetrieveExtensionsFromPrefs(&external_update_url_extensions, |
| 127 &external_file_extensions); |
| 128 for (const auto& extension : external_update_url_extensions) |
| 129 service_->OnExternalExtensionUpdateUrlFound(extension, true); |
| 130 |
| 131 for (const auto& extension : external_file_extensions) |
| 132 service_->OnExternalExtensionFileFound(extension); |
| 133 |
| 134 service_->OnExternalProviderReady(this); |
| 135 } |
| 136 |
| 137 void ExternalProviderImpl::UpdatePrefs(base::DictionaryValue* prefs) { |
| 138 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 139 // We only expect updates from windows registry. |
| 140 CHECK(crx_location_ == Manifest::EXTERNAL_REGISTRY); |
| 141 |
| 142 // Check if the service is still alive. It is possible that it went |
| 143 // away while |loader_| was working on the FILE thread. |
| 144 if (!service_) |
| 145 return; |
| 146 |
| 147 std::set<std::string> removed_extensions; |
| 148 // Find extensions that were removed by this ExternalProvider. |
| 149 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { |
| 150 const std::string& extension_id = i.key(); |
| 151 // Don't bother about invalid ids. |
| 152 if (!crx_file::id_util::IdIsValid(extension_id)) |
| 153 continue; |
| 154 if (!prefs->HasKey(extension_id)) |
| 155 removed_extensions.insert(extension_id); |
| 156 } |
| 157 |
| 158 prefs_.reset(prefs); |
| 159 |
| 160 ScopedVector<UpdateUrlExtensionInfo> external_update_url_extensions; |
| 161 ScopedVector<FileExtensionInfo> external_file_extensions; |
| 162 RetrieveExtensionsFromPrefs(&external_update_url_extensions, |
| 163 &external_file_extensions); |
| 164 |
| 165 // Notify ExtensionService about completion of finding incremental updates |
| 166 // from this provider. |
| 167 // Provide the list of added and removed extensions. |
| 168 service_->OnExternalProviderUpdateComplete( |
| 169 this, external_update_url_extensions, external_file_extensions, |
| 170 removed_extensions); |
| 171 } |
| 172 |
| 173 void ExternalProviderImpl::RetrieveExtensionsFromPrefs( |
| 174 ScopedVector<UpdateUrlExtensionInfo>* external_update_url_extensions, |
| 175 ScopedVector<FileExtensionInfo>* external_file_extensions) { |
123 // Set of unsupported extensions that need to be deleted from prefs_. | 176 // Set of unsupported extensions that need to be deleted from prefs_. |
124 std::set<std::string> unsupported_extensions; | 177 std::set<std::string> unsupported_extensions; |
125 | 178 |
126 // Notify ExtensionService about all the extensions this provider has. | 179 // Discover all the extensions this provider has. |
127 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { | 180 for (base::DictionaryValue::Iterator i(*prefs_); !i.IsAtEnd(); i.Advance()) { |
128 const std::string& extension_id = i.key(); | 181 const std::string& extension_id = i.key(); |
129 const base::DictionaryValue* extension = NULL; | 182 const base::DictionaryValue* extension = NULL; |
130 | 183 |
131 if (!crx_file::id_util::IdIsValid(extension_id)) { | 184 if (!crx_file::id_util::IdIsValid(extension_id)) { |
132 LOG(WARNING) << "Malformed extension dictionary: key " | 185 LOG(WARNING) << "Malformed extension dictionary: key " |
133 << extension_id.c_str() << " is not a valid id."; | 186 << extension_id.c_str() << " is not a valid id."; |
134 continue; | 187 continue; |
135 } | 188 } |
136 | 189 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 if (!path.IsAbsolute()) { | 335 if (!path.IsAbsolute()) { |
283 base::FilePath base_path = loader_->GetBaseCrxFilePath(); | 336 base::FilePath base_path = loader_->GetBaseCrxFilePath(); |
284 if (base_path.empty()) { | 337 if (base_path.empty()) { |
285 LOG(WARNING) << "File path " << external_crx.c_str() | 338 LOG(WARNING) << "File path " << external_crx.c_str() |
286 << " is relative. An absolute path is required."; | 339 << " is relative. An absolute path is required."; |
287 continue; | 340 continue; |
288 } | 341 } |
289 path = base_path.Append(external_crx); | 342 path = base_path.Append(external_crx); |
290 } | 343 } |
291 | 344 |
292 Version version(external_version); | 345 scoped_ptr<Version> version(new Version(external_version)); |
293 if (!version.IsValid()) { | 346 if (!version->IsValid()) { |
294 LOG(WARNING) << "Malformed extension dictionary for extension: " | 347 LOG(WARNING) << "Malformed extension dictionary for extension: " |
295 << extension_id.c_str() << ". Invalid version string \"" | 348 << extension_id.c_str() << ". Invalid version string \"" |
296 << external_version << "\"."; | 349 << external_version << "\"."; |
297 continue; | 350 continue; |
298 } | 351 } |
299 service_->OnExternalExtensionFileFound(extension_id, &version, path, | 352 external_file_extensions->push_back(new FileExtensionInfo( |
300 crx_location_, creation_flags, | 353 extension_id, std::move(version), path, crx_location_, creation_flags, |
301 auto_acknowledge_, | 354 auto_acknowledge_, install_immediately_)); |
302 install_immediately_); | |
303 } else { // if (has_external_update_url) | 355 } else { // if (has_external_update_url) |
304 CHECK(has_external_update_url); // Checking of keys above ensures this. | 356 CHECK(has_external_update_url); // Checking of keys above ensures this. |
305 if (download_location_ == Manifest::INVALID_LOCATION) { | 357 if (download_location_ == Manifest::INVALID_LOCATION) { |
306 LOG(WARNING) << "This provider does not support installing external " | 358 LOG(WARNING) << "This provider does not support installing external " |
307 << "extensions from update URLs."; | 359 << "extensions from update URLs."; |
308 continue; | 360 continue; |
309 } | 361 } |
310 GURL update_url(external_update_url); | 362 scoped_ptr<GURL> update_url(new GURL(external_update_url)); |
311 if (!update_url.is_valid()) { | 363 if (!update_url->is_valid()) { |
312 LOG(WARNING) << "Malformed extension dictionary for extension: " | 364 LOG(WARNING) << "Malformed extension dictionary for extension: " |
313 << extension_id.c_str() << ". Key " << kExternalUpdateUrl | 365 << extension_id.c_str() << ". Key " << kExternalUpdateUrl |
314 << " has value \"" << external_update_url | 366 << " has value \"" << external_update_url |
315 << "\", which is not a valid URL."; | 367 << "\", which is not a valid URL."; |
316 continue; | 368 continue; |
317 } | 369 } |
318 service_->OnExternalExtensionUpdateUrlFound(extension_id, | 370 external_update_url_extensions->push_back(new UpdateUrlExtensionInfo( |
319 install_parameter, | 371 extension_id, install_parameter, std::move(update_url), |
320 update_url, | 372 download_location_, creation_flags, auto_acknowledge_)); |
321 download_location_, | |
322 creation_flags, | |
323 auto_acknowledge_); | |
324 } | 373 } |
325 } | 374 } |
326 | 375 |
327 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); | 376 for (std::set<std::string>::iterator it = unsupported_extensions.begin(); |
328 it != unsupported_extensions.end(); ++it) { | 377 it != unsupported_extensions.end(); ++it) { |
329 // Remove extension for the list of know external extensions. The extension | 378 // Remove extension for the list of know external extensions. The extension |
330 // will be uninstalled later because provider doesn't provide it anymore. | 379 // will be uninstalled later because provider doesn't provide it anymore. |
331 prefs_->Remove(*it, NULL); | 380 prefs_->Remove(*it, NULL); |
332 } | 381 } |
333 | |
334 service_->OnExternalProviderReady(this); | |
335 } | 382 } |
336 | 383 |
337 void ExternalProviderImpl::ServiceShutdown() { | 384 void ExternalProviderImpl::ServiceShutdown() { |
338 service_ = NULL; | 385 service_ = NULL; |
339 } | 386 } |
340 | 387 |
341 bool ExternalProviderImpl::IsReady() const { | 388 bool ExternalProviderImpl::IsReady() const { |
342 return ready_; | 389 return ready_; |
343 } | 390 } |
344 | 391 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 new ExternalProviderImpl( | 738 new ExternalProviderImpl( |
692 service, | 739 service, |
693 new ExternalComponentLoader(profile), | 740 new ExternalComponentLoader(profile), |
694 profile, | 741 profile, |
695 Manifest::INVALID_LOCATION, | 742 Manifest::INVALID_LOCATION, |
696 Manifest::EXTERNAL_COMPONENT, | 743 Manifest::EXTERNAL_COMPONENT, |
697 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT))); | 744 Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_DEFAULT))); |
698 } | 745 } |
699 | 746 |
700 } // namespace extensions | 747 } // namespace extensions |
OLD | NEW |