Chromium Code Reviews| 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/updater/extension_updater.h" | 5 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 return will_check_soon_; | 256 return will_check_soon_; |
| 257 } | 257 } |
| 258 | 258 |
| 259 void ExtensionUpdater::DoCheckSoon() { | 259 void ExtensionUpdater::DoCheckSoon() { |
| 260 DCHECK(will_check_soon_); | 260 DCHECK(will_check_soon_); |
| 261 CheckNow(); | 261 CheckNow(); |
| 262 will_check_soon_ = false; | 262 will_check_soon_ = false; |
| 263 } | 263 } |
| 264 | 264 |
| 265 void ExtensionUpdater::AddToDownloader(const ExtensionSet* extensions, | 265 void ExtensionUpdater::AddToDownloader(const ExtensionSet* extensions, |
| 266 const std::set<std::string>& pending_ids) { | 266 const std::list<std::string>& pending_ids) { |
| 267 for (ExtensionSet::const_iterator iter = extensions->begin(); | 267 for (ExtensionSet::const_iterator extension_iter = extensions->begin(); |
| 268 iter != extensions->end(); ++iter) { | 268 extension_iter != extensions->end(); ++extension_iter) { |
| 269 const Extension& extension = **iter; | 269 const Extension& extension = **extension_iter; |
| 270 if (!Extension::IsAutoUpdateableLocation(extension.location())) { | 270 if (!Extension::IsAutoUpdateableLocation(extension.location())) { |
| 271 VLOG(2) << "Extension " << extension.id() << " is not auto updateable"; | 271 VLOG(2) << "Extension " << extension.id() << " is not auto updateable"; |
| 272 continue; | 272 continue; |
| 273 } | 273 } |
| 274 // An extension might be overwritten by policy, and have its update url | 274 // An extension might be overwritten by policy, and have its update url |
| 275 // changed. Make sure existing extensions aren't fetched again, if a | 275 // changed. Make sure existing extensions aren't fetched again, if a |
| 276 // pending fetch for an extension with the same id already exists. | 276 // pending fetch for an extension with the same id already exists. |
| 277 if (!ContainsKey(pending_ids, extension.id())) { | 277 std::list<std::string>::const_iterator pending_id_iter = std::find( |
| 278 pending_ids.begin(), | |
|
Aaron Boodman
2012/05/01 15:50:22
Nit: no need to wrap so vigorously. These can go o
mitchellwrosen
2012/05/11 05:45:03
Done.
| |
| 279 pending_ids.end(), | |
| 280 extension.id()); | |
| 281 if (pending_id_iter == pending_ids.end()) { | |
| 278 if (downloader_->AddExtension(extension)) | 282 if (downloader_->AddExtension(extension)) |
| 279 in_progress_ids_.insert(extension.id()); | 283 in_progress_ids_.push_back(extension.id()); |
| 280 } | 284 } |
| 281 } | 285 } |
| 282 } | 286 } |
| 283 | 287 |
| 284 void ExtensionUpdater::CheckNow() { | 288 void ExtensionUpdater::CheckNow() { |
| 285 VLOG(2) << "Starting update check"; | 289 VLOG(2) << "Starting update check"; |
| 286 DCHECK(alive_); | 290 DCHECK(alive_); |
| 287 NotifyStarted(); | 291 NotifyStarted(); |
| 288 | 292 |
| 289 if (!downloader_.get()) { | 293 if (!downloader_.get()) { |
| 290 downloader_.reset( | 294 downloader_.reset( |
| 291 new ExtensionDownloader(this, profile_->GetRequestContext())); | 295 new ExtensionDownloader(this, profile_->GetRequestContext())); |
| 292 } | 296 } |
| 293 | 297 |
| 294 // Add fetch records for extensions that should be fetched by an update URL. | 298 // Add fetch records for extensions that should be fetched by an update URL. |
| 295 // These extensions are not yet installed. They come from group policy | 299 // These extensions are not yet installed. They come from group policy |
| 296 // and external install sources. | 300 // and external install sources. |
| 297 const PendingExtensionManager* pending_extension_manager = | 301 const PendingExtensionManager* pending_extension_manager = |
| 298 service_->pending_extension_manager(); | 302 service_->pending_extension_manager(); |
| 299 | 303 |
| 300 std::set<std::string> pending_ids; | 304 std::list<std::string> pending_ids; |
| 301 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids); | 305 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids); |
| 302 | 306 |
| 303 std::set<std::string>::const_iterator iter; | 307 std::list<std::string>::const_iterator iter; |
| 304 for (iter = pending_ids.begin(); iter != pending_ids.end(); ++iter) { | 308 for (iter = pending_ids.begin(); iter != pending_ids.end(); ++iter) { |
| 305 PendingExtensionInfo info; | 309 const PendingExtensionInfo* info = pending_extension_manager->GetById( |
| 306 bool found_id = pending_extension_manager->GetById(*iter, &info); | 310 *iter); |
| 307 DCHECK(found_id); | 311 if (!Extension::IsAutoUpdateableLocation(info->install_source())) { |
| 308 if (!found_id) | |
| 309 continue; | |
| 310 if (!Extension::IsAutoUpdateableLocation(info.install_source())) { | |
| 311 VLOG(2) << "Extension " << *iter << " is not auto updateable"; | 312 VLOG(2) << "Extension " << *iter << " is not auto updateable"; |
| 312 continue; | 313 continue; |
| 313 } | 314 } |
| 314 if (downloader_->AddPendingExtension(*iter, info.update_url())) | 315 if (downloader_->AddPendingExtension(*iter, info->update_url())) |
| 315 in_progress_ids_.insert(*iter); | 316 in_progress_ids_.push_back(*iter); |
| 316 } | 317 } |
| 317 | 318 |
| 318 AddToDownloader(service_->extensions(), pending_ids); | 319 AddToDownloader(service_->extensions(), pending_ids); |
| 319 AddToDownloader(service_->disabled_extensions(), pending_ids); | 320 AddToDownloader(service_->disabled_extensions(), pending_ids); |
| 320 | 321 |
| 321 // Start a fetch of the blacklist if needed. | 322 // Start a fetch of the blacklist if needed. |
| 322 if (blacklist_checks_enabled_) { | 323 if (blacklist_checks_enabled_) { |
| 323 ManifestFetchData::PingData ping_data; | 324 ManifestFetchData::PingData ping_data; |
| 324 ping_data.rollcall_days = | 325 ping_data.rollcall_days = |
| 325 CalculatePingDays(extension_prefs_->BlacklistLastPingDay()); | 326 CalculatePingDays(extension_prefs_->BlacklistLastPingDay()); |
| 326 downloader_->StartBlacklistUpdate( | 327 downloader_->StartBlacklistUpdate( |
| 327 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data); | 328 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data); |
| 328 } | 329 } |
| 329 | 330 |
| 330 // StartAllPending() will call OnExtensionUpdateCheckStarted() for each | 331 // StartAllPending() will call OnExtensionUpdateCheckStarted() for each |
| 331 // extension that is going to be checked. | 332 // extension that is going to be checked. |
| 332 downloader_->StartAllPending(); | 333 downloader_->StartAllPending(); |
| 333 | 334 |
| 334 NotifyIfFinished(); | 335 NotifyIfFinished(); |
| 335 } | 336 } |
| 336 | 337 |
| 337 void ExtensionUpdater::OnExtensionDownloadFailed(const std::string& id, | 338 void ExtensionUpdater::OnExtensionDownloadFailed(const std::string& id, |
| 338 Error error, | 339 Error error, |
| 339 const PingResult& ping) { | 340 const PingResult& ping) { |
| 340 DCHECK(alive_); | 341 DCHECK(alive_); |
| 341 UpdatePingData(id, ping); | 342 UpdatePingData(id, ping); |
| 342 in_progress_ids_.erase(id); | 343 in_progress_ids_.remove(id); |
| 343 NotifyIfFinished(); | 344 NotifyIfFinished(); |
| 344 } | 345 } |
| 345 | 346 |
| 346 void ExtensionUpdater::OnExtensionDownloadFinished(const std::string& id, | 347 void ExtensionUpdater::OnExtensionDownloadFinished(const std::string& id, |
| 347 const FilePath& path, | 348 const FilePath& path, |
| 348 const GURL& download_url, | 349 const GURL& download_url, |
| 349 const std::string& version, | 350 const std::string& version, |
| 350 const PingResult& ping) { | 351 const PingResult& ping) { |
| 351 DCHECK(alive_); | 352 DCHECK(alive_); |
| 352 UpdatePingData(id, ping); | 353 UpdatePingData(id, ping); |
| 353 | 354 |
| 354 VLOG(2) << download_url << " written to " << path.value(); | 355 VLOG(2) << download_url << " written to " << path.value(); |
| 355 | 356 |
| 356 FetchedCRXFile fetched(id, path, download_url); | 357 FetchedCRXFile fetched(id, path, download_url); |
| 357 fetched_crx_files_.push(fetched); | 358 fetched_crx_files_.push(fetched); |
| 358 | 359 |
| 359 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after | 360 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after |
| 360 // starting the crx installer. | 361 // starting the crx installer. |
| 361 MaybeInstallCRXFile(); | 362 MaybeInstallCRXFile(); |
| 362 } | 363 } |
| 363 | 364 |
| 364 void ExtensionUpdater::OnBlacklistDownloadFinished( | 365 void ExtensionUpdater::OnBlacklistDownloadFinished( |
| 365 const std::string& data, | 366 const std::string& data, |
| 366 const std::string& package_hash, | 367 const std::string& package_hash, |
| 367 const std::string& version, | 368 const std::string& version, |
| 368 const PingResult& ping) { | 369 const PingResult& ping) { |
| 369 DCHECK(alive_); | 370 DCHECK(alive_); |
| 370 UpdatePingData(ExtensionDownloader::kBlacklistAppID, ping); | 371 UpdatePingData(ExtensionDownloader::kBlacklistAppID, ping); |
| 371 in_progress_ids_.erase(ExtensionDownloader::kBlacklistAppID); | 372 in_progress_ids_.remove(ExtensionDownloader::kBlacklistAppID); |
| 372 NotifyIfFinished(); | 373 NotifyIfFinished(); |
| 373 | 374 |
| 374 // Verify sha256 hash value. | 375 // Verify sha256 hash value. |
| 375 char sha256_hash_value[crypto::kSHA256Length]; | 376 char sha256_hash_value[crypto::kSHA256Length]; |
| 376 crypto::SHA256HashString(data, sha256_hash_value, crypto::kSHA256Length); | 377 crypto::SHA256HashString(data, sha256_hash_value, crypto::kSHA256Length); |
| 377 std::string hash_in_hex = base::HexEncode(sha256_hash_value, | 378 std::string hash_in_hex = base::HexEncode(sha256_hash_value, |
| 378 crypto::kSHA256Length); | 379 crypto::kSHA256Length); |
| 379 | 380 |
| 380 if (package_hash != hash_in_hex) { | 381 if (package_hash != hash_in_hex) { |
| 381 NOTREACHED() << "Fetched blacklist checksum is not as expected. " | 382 NOTREACHED() << "Fetched blacklist checksum is not as expected. " |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 crx_file.download_url, | 462 crx_file.download_url, |
| 462 &installer)) { | 463 &installer)) { |
| 463 crx_install_is_running_ = true; | 464 crx_install_is_running_ = true; |
| 464 | 465 |
| 465 // Source parameter ensures that we only see the completion event for the | 466 // Source parameter ensures that we only see the completion event for the |
| 466 // the installer we started. | 467 // the installer we started. |
| 467 registrar_.Add(this, | 468 registrar_.Add(this, |
| 468 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 469 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 469 content::Source<CrxInstaller>(installer)); | 470 content::Source<CrxInstaller>(installer)); |
| 470 } | 471 } |
| 471 in_progress_ids_.erase(crx_file.id); | 472 in_progress_ids_.remove(crx_file.id); |
| 472 fetched_crx_files_.pop(); | 473 fetched_crx_files_.pop(); |
| 473 } | 474 } |
| 474 | 475 |
| 475 NotifyIfFinished(); | 476 NotifyIfFinished(); |
| 476 } | 477 } |
| 477 | 478 |
| 478 void ExtensionUpdater::Observe(int type, | 479 void ExtensionUpdater::Observe(int type, |
| 479 const content::NotificationSource& source, | 480 const content::NotificationSource& source, |
| 480 const content::NotificationDetails& details) { | 481 const content::NotificationDetails& details) { |
| 481 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); | 482 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 500 if (in_progress_ids_.empty()) { | 501 if (in_progress_ids_.empty()) { |
| 501 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED"; | 502 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED"; |
| 502 content::NotificationService::current()->Notify( | 503 content::NotificationService::current()->Notify( |
| 503 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, | 504 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, |
| 504 content::Source<Profile>(profile_), | 505 content::Source<Profile>(profile_), |
| 505 content::NotificationService::NoDetails()); | 506 content::NotificationService::NoDetails()); |
| 506 } | 507 } |
| 507 } | 508 } |
| 508 | 509 |
| 509 } // namespace extensions | 510 } // namespace extensions |
| OLD | NEW |