| 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(), pending_ids.end(), extension.id()); |
| 279 if (pending_id_iter == pending_ids.end()) { |
| 278 if (downloader_->AddExtension(extension)) | 280 if (downloader_->AddExtension(extension)) |
| 279 in_progress_ids_.insert(extension.id()); | 281 in_progress_ids_.push_back(extension.id()); |
| 280 } | 282 } |
| 281 } | 283 } |
| 282 } | 284 } |
| 283 | 285 |
| 284 void ExtensionUpdater::CheckNow() { | 286 void ExtensionUpdater::CheckNow() { |
| 285 VLOG(2) << "Starting update check"; | 287 VLOG(2) << "Starting update check"; |
| 286 DCHECK(alive_); | 288 DCHECK(alive_); |
| 287 NotifyStarted(); | 289 NotifyStarted(); |
| 288 | 290 |
| 289 if (!downloader_.get()) { | 291 if (!downloader_.get()) { |
| 290 downloader_.reset( | 292 downloader_.reset( |
| 291 new ExtensionDownloader(this, profile_->GetRequestContext())); | 293 new ExtensionDownloader(this, profile_->GetRequestContext())); |
| 292 } | 294 } |
| 293 | 295 |
| 294 // Add fetch records for extensions that should be fetched by an update URL. | 296 // 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 | 297 // These extensions are not yet installed. They come from group policy |
| 296 // and external install sources. | 298 // and external install sources. |
| 297 const PendingExtensionManager* pending_extension_manager = | 299 const PendingExtensionManager* pending_extension_manager = |
| 298 service_->pending_extension_manager(); | 300 service_->pending_extension_manager(); |
| 299 | 301 |
| 300 std::set<std::string> pending_ids; | 302 std::list<std::string> pending_ids; |
| 301 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids); | 303 pending_extension_manager->GetPendingIdsForUpdateCheck(&pending_ids); |
| 302 | 304 |
| 303 std::set<std::string>::const_iterator iter; | 305 std::list<std::string>::const_iterator iter; |
| 304 for (iter = pending_ids.begin(); iter != pending_ids.end(); ++iter) { | 306 for (iter = pending_ids.begin(); iter != pending_ids.end(); ++iter) { |
| 305 PendingExtensionInfo info; | 307 const PendingExtensionInfo* info = pending_extension_manager->GetById( |
| 306 bool found_id = pending_extension_manager->GetById(*iter, &info); | 308 *iter); |
| 307 DCHECK(found_id); | 309 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"; | 310 VLOG(2) << "Extension " << *iter << " is not auto updateable"; |
| 312 continue; | 311 continue; |
| 313 } | 312 } |
| 314 if (downloader_->AddPendingExtension(*iter, info.update_url())) | 313 if (downloader_->AddPendingExtension(*iter, info->update_url())) |
| 315 in_progress_ids_.insert(*iter); | 314 in_progress_ids_.push_back(*iter); |
| 316 } | 315 } |
| 317 | 316 |
| 318 AddToDownloader(service_->extensions(), pending_ids); | 317 AddToDownloader(service_->extensions(), pending_ids); |
| 319 AddToDownloader(service_->disabled_extensions(), pending_ids); | 318 AddToDownloader(service_->disabled_extensions(), pending_ids); |
| 320 | 319 |
| 321 // Start a fetch of the blacklist if needed. | 320 // Start a fetch of the blacklist if needed. |
| 322 if (blacklist_checks_enabled_) { | 321 if (blacklist_checks_enabled_) { |
| 323 ManifestFetchData::PingData ping_data; | 322 ManifestFetchData::PingData ping_data; |
| 324 ping_data.rollcall_days = | 323 ping_data.rollcall_days = |
| 325 CalculatePingDays(extension_prefs_->BlacklistLastPingDay()); | 324 CalculatePingDays(extension_prefs_->BlacklistLastPingDay()); |
| 326 downloader_->StartBlacklistUpdate( | 325 downloader_->StartBlacklistUpdate( |
| 327 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data); | 326 prefs_->GetString(kExtensionBlacklistUpdateVersion), ping_data); |
| 328 } | 327 } |
| 329 | 328 |
| 330 // StartAllPending() will call OnExtensionUpdateCheckStarted() for each | 329 // StartAllPending() will call OnExtensionUpdateCheckStarted() for each |
| 331 // extension that is going to be checked. | 330 // extension that is going to be checked. |
| 332 downloader_->StartAllPending(); | 331 downloader_->StartAllPending(); |
| 333 | 332 |
| 334 NotifyIfFinished(); | 333 NotifyIfFinished(); |
| 335 } | 334 } |
| 336 | 335 |
| 337 void ExtensionUpdater::OnExtensionDownloadFailed(const std::string& id, | 336 void ExtensionUpdater::OnExtensionDownloadFailed(const std::string& id, |
| 338 Error error, | 337 Error error, |
| 339 const PingResult& ping) { | 338 const PingResult& ping) { |
| 340 DCHECK(alive_); | 339 DCHECK(alive_); |
| 341 UpdatePingData(id, ping); | 340 UpdatePingData(id, ping); |
| 342 in_progress_ids_.erase(id); | 341 in_progress_ids_.remove(id); |
| 343 NotifyIfFinished(); | 342 NotifyIfFinished(); |
| 344 } | 343 } |
| 345 | 344 |
| 346 void ExtensionUpdater::OnExtensionDownloadFinished(const std::string& id, | 345 void ExtensionUpdater::OnExtensionDownloadFinished(const std::string& id, |
| 347 const FilePath& path, | 346 const FilePath& path, |
| 348 const GURL& download_url, | 347 const GURL& download_url, |
| 349 const std::string& version, | 348 const std::string& version, |
| 350 const PingResult& ping) { | 349 const PingResult& ping) { |
| 351 DCHECK(alive_); | 350 DCHECK(alive_); |
| 352 UpdatePingData(id, ping); | 351 UpdatePingData(id, ping); |
| 353 | 352 |
| 354 VLOG(2) << download_url << " written to " << path.value(); | 353 VLOG(2) << download_url << " written to " << path.value(); |
| 355 | 354 |
| 356 FetchedCRXFile fetched(id, path, download_url); | 355 FetchedCRXFile fetched(id, path, download_url); |
| 357 fetched_crx_files_.push(fetched); | 356 fetched_crx_files_.push(fetched); |
| 358 | 357 |
| 359 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after | 358 // MaybeInstallCRXFile() removes extensions from |in_progress_ids_| after |
| 360 // starting the crx installer. | 359 // starting the crx installer. |
| 361 MaybeInstallCRXFile(); | 360 MaybeInstallCRXFile(); |
| 362 } | 361 } |
| 363 | 362 |
| 364 void ExtensionUpdater::OnBlacklistDownloadFinished( | 363 void ExtensionUpdater::OnBlacklistDownloadFinished( |
| 365 const std::string& data, | 364 const std::string& data, |
| 366 const std::string& package_hash, | 365 const std::string& package_hash, |
| 367 const std::string& version, | 366 const std::string& version, |
| 368 const PingResult& ping) { | 367 const PingResult& ping) { |
| 369 DCHECK(alive_); | 368 DCHECK(alive_); |
| 370 UpdatePingData(ExtensionDownloader::kBlacklistAppID, ping); | 369 UpdatePingData(ExtensionDownloader::kBlacklistAppID, ping); |
| 371 in_progress_ids_.erase(ExtensionDownloader::kBlacklistAppID); | 370 in_progress_ids_.remove(ExtensionDownloader::kBlacklistAppID); |
| 372 NotifyIfFinished(); | 371 NotifyIfFinished(); |
| 373 | 372 |
| 374 // Verify sha256 hash value. | 373 // Verify sha256 hash value. |
| 375 char sha256_hash_value[crypto::kSHA256Length]; | 374 char sha256_hash_value[crypto::kSHA256Length]; |
| 376 crypto::SHA256HashString(data, sha256_hash_value, crypto::kSHA256Length); | 375 crypto::SHA256HashString(data, sha256_hash_value, crypto::kSHA256Length); |
| 377 std::string hash_in_hex = base::HexEncode(sha256_hash_value, | 376 std::string hash_in_hex = base::HexEncode(sha256_hash_value, |
| 378 crypto::kSHA256Length); | 377 crypto::kSHA256Length); |
| 379 | 378 |
| 380 if (package_hash != hash_in_hex) { | 379 if (package_hash != hash_in_hex) { |
| 381 NOTREACHED() << "Fetched blacklist checksum is not as expected. " | 380 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, | 460 crx_file.download_url, |
| 462 &installer)) { | 461 &installer)) { |
| 463 crx_install_is_running_ = true; | 462 crx_install_is_running_ = true; |
| 464 | 463 |
| 465 // Source parameter ensures that we only see the completion event for the | 464 // Source parameter ensures that we only see the completion event for the |
| 466 // the installer we started. | 465 // the installer we started. |
| 467 registrar_.Add(this, | 466 registrar_.Add(this, |
| 468 chrome::NOTIFICATION_CRX_INSTALLER_DONE, | 467 chrome::NOTIFICATION_CRX_INSTALLER_DONE, |
| 469 content::Source<CrxInstaller>(installer)); | 468 content::Source<CrxInstaller>(installer)); |
| 470 } | 469 } |
| 471 in_progress_ids_.erase(crx_file.id); | 470 in_progress_ids_.remove(crx_file.id); |
| 472 fetched_crx_files_.pop(); | 471 fetched_crx_files_.pop(); |
| 473 } | 472 } |
| 474 | 473 |
| 475 NotifyIfFinished(); | 474 NotifyIfFinished(); |
| 476 } | 475 } |
| 477 | 476 |
| 478 void ExtensionUpdater::Observe(int type, | 477 void ExtensionUpdater::Observe(int type, |
| 479 const content::NotificationSource& source, | 478 const content::NotificationSource& source, |
| 480 const content::NotificationDetails& details) { | 479 const content::NotificationDetails& details) { |
| 481 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); | 480 DCHECK(type == chrome::NOTIFICATION_CRX_INSTALLER_DONE); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 500 if (in_progress_ids_.empty()) { | 499 if (in_progress_ids_.empty()) { |
| 501 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED"; | 500 VLOG(1) << "Sending EXTENSION_UPDATING_FINISHED"; |
| 502 content::NotificationService::current()->Notify( | 501 content::NotificationService::current()->Notify( |
| 503 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, | 502 chrome::NOTIFICATION_EXTENSION_UPDATING_FINISHED, |
| 504 content::Source<Profile>(profile_), | 503 content::Source<Profile>(profile_), |
| 505 content::NotificationService::NoDetails()); | 504 content::NotificationService::NoDetails()); |
| 506 } | 505 } |
| 507 } | 506 } |
| 508 | 507 |
| 509 } // namespace extensions | 508 } // namespace extensions |
| OLD | NEW |