OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_updater.h" | 5 #include "chrome/browser/extensions/extension_updater.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/memory/scoped_handle.h" | 13 #include "base/memory/scoped_handle.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
16 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/string_split.h" | 18 #include "base/string_split.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "base/version.h" | 22 #include "base/version.h" |
23 #include "crypto/sha2.h" | 23 #include "crypto/sha2.h" |
24 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
| 25 #include "content/common/notification_source.h" |
25 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/extensions/crx_installer.h" |
26 #include "chrome/browser/extensions/extension_error_reporter.h" | 28 #include "chrome/browser/extensions/extension_error_reporter.h" |
27 #include "chrome/browser/extensions/extension_service.h" | 29 #include "chrome/browser/extensions/extension_service.h" |
28 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
29 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/utility_process_host.h" | 32 #include "chrome/browser/utility_process_host.h" |
31 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
32 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
33 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
34 #include "chrome/common/extensions/extension_constants.h" | 36 #include "chrome/common/extensions/extension_constants.h" |
35 #include "chrome/common/extensions/extension_file_util.h" | 37 #include "chrome/common/extensions/extension_file_util.h" |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 version("") {} | 439 version("") {} |
438 | 440 |
439 ExtensionUpdater::ExtensionFetch::ExtensionFetch(const std::string& i, | 441 ExtensionUpdater::ExtensionFetch::ExtensionFetch(const std::string& i, |
440 const GURL& u, | 442 const GURL& u, |
441 const std::string& h, | 443 const std::string& h, |
442 const std::string& v) | 444 const std::string& v) |
443 : id(i), url(u), package_hash(h), version(v) {} | 445 : id(i), url(u), package_hash(h), version(v) {} |
444 | 446 |
445 ExtensionUpdater::ExtensionFetch::~ExtensionFetch() {} | 447 ExtensionUpdater::ExtensionFetch::~ExtensionFetch() {} |
446 | 448 |
| 449 ExtensionUpdater::FetchedCrxFile::FetchedCrxFile(const std::string& i, |
| 450 const FilePath& p, |
| 451 const GURL& u) |
| 452 : id(i), |
| 453 path(p), |
| 454 download_url(u) {} |
| 455 |
| 456 ExtensionUpdater::FetchedCrxFile::FetchedCrxFile() |
| 457 : id(""), |
| 458 path(), |
| 459 download_url() {} |
| 460 |
| 461 ExtensionUpdater::FetchedCrxFile::~FetchedCrxFile() {} |
| 462 |
447 ExtensionUpdater::ExtensionUpdater(ExtensionServiceInterface* service, | 463 ExtensionUpdater::ExtensionUpdater(ExtensionServiceInterface* service, |
448 ExtensionPrefs* extension_prefs, | 464 ExtensionPrefs* extension_prefs, |
449 PrefService* prefs, | 465 PrefService* prefs, |
450 Profile* profile, | 466 Profile* profile, |
451 int frequency_seconds) | 467 int frequency_seconds) |
452 : alive_(false), | 468 : alive_(false), |
453 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 469 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
454 service_(service), frequency_seconds_(frequency_seconds), | 470 service_(service), frequency_seconds_(frequency_seconds), |
455 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 471 method_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
456 will_check_soon_(false), extension_prefs_(extension_prefs), | 472 will_check_soon_(false), extension_prefs_(extension_prefs), |
457 prefs_(prefs), profile_(profile), blacklist_checks_enabled_(true) { | 473 prefs_(prefs), profile_(profile), blacklist_checks_enabled_(true), |
| 474 crx_install_is_running_(false) { |
458 Init(); | 475 Init(); |
459 } | 476 } |
460 | 477 |
461 void ExtensionUpdater::Init() { | 478 void ExtensionUpdater::Init() { |
462 DCHECK_GE(frequency_seconds_, 5); | 479 DCHECK_GE(frequency_seconds_, 5); |
463 DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds); | 480 DCHECK_LE(frequency_seconds_, kMaxUpdateFrequencySeconds); |
464 #ifdef NDEBUG | 481 #ifdef NDEBUG |
465 // In Release mode we enforce that update checks don't happen too often. | 482 // In Release mode we enforce that update checks don't happen too often. |
466 frequency_seconds_ = std::max(frequency_seconds_, kMinUpdateFrequencySeconds); | 483 frequency_seconds_ = std::max(frequency_seconds_, kMinUpdateFrequencySeconds); |
467 #endif | 484 #endif |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 ExtensionFetch next = extensions_pending_.front(); | 849 ExtensionFetch next = extensions_pending_.front(); |
833 extensions_pending_.pop_front(); | 850 extensions_pending_.pop_front(); |
834 FetchUpdatedExtension(next.id, next.url, next.package_hash, next.version); | 851 FetchUpdatedExtension(next.id, next.url, next.package_hash, next.version); |
835 } | 852 } |
836 } | 853 } |
837 | 854 |
838 void ExtensionUpdater::OnCRXFileWritten(const std::string& id, | 855 void ExtensionUpdater::OnCRXFileWritten(const std::string& id, |
839 const FilePath& path, | 856 const FilePath& path, |
840 const GURL& download_url) { | 857 const GURL& download_url) { |
841 DCHECK(alive_); | 858 DCHECK(alive_); |
842 // The ExtensionService is now responsible for cleaning up the temp file | 859 |
843 // at |path|. | 860 FetchedCrxFile fetched(id, path, download_url); |
844 service_->UpdateExtension(id, path, download_url); | 861 fetched_crx_files_.push(fetched); |
845 in_progress_ids_.erase(id); | 862 |
| 863 MaybeUpdateCrxFile(); |
| 864 } |
| 865 |
| 866 bool ExtensionUpdater::MaybeUpdateCrxFile() { |
| 867 if (crx_install_is_running_) { |
| 868 return false; |
| 869 } |
| 870 |
| 871 while (!fetched_crx_files_.empty() && !crx_install_is_running_) { |
| 872 const FetchedCrxFile& crx_file = fetched_crx_files_.top(); |
| 873 |
| 874 // The ExtensionService is now responsible for cleaning up the temp file |
| 875 // at |extension_file.path|. |
| 876 Source<CrxInstaller> install_notification_source(NULL); |
| 877 if (service_->UpdateExtension(crx_file.id, |
| 878 crx_file.path, |
| 879 crx_file.download_url, |
| 880 &install_notification_source)) { |
| 881 crx_install_is_running_ = true; |
| 882 |
| 883 // Source parameter ensures that we only see the completion event for the |
| 884 // the installer we started. |
| 885 registrar_.Add(this, |
| 886 NotificationType::CRX_INSTALLER_DONE, |
| 887 install_notification_source); |
| 888 } |
| 889 in_progress_ids_.erase(crx_file.id); |
| 890 fetched_crx_files_.pop(); |
| 891 } |
| 892 |
| 893 // If an updater is running, it was started above. |
| 894 return crx_install_is_running_; |
| 895 } |
| 896 |
| 897 void ExtensionUpdater::Observe(NotificationType type, |
| 898 const NotificationSource& source, |
| 899 const NotificationDetails& details) { |
| 900 DCHECK(type == NotificationType::CRX_INSTALLER_DONE); |
| 901 |
| 902 // No need to listen for CRX_INSTALLER_DONE anymore. |
| 903 registrar_.Remove(this, |
| 904 NotificationType::CRX_INSTALLER_DONE, |
| 905 source); |
| 906 crx_install_is_running_ = false; |
| 907 // If any files are available to update, start one. |
| 908 MaybeUpdateCrxFile(); |
846 } | 909 } |
847 | 910 |
848 void ExtensionUpdater::OnCRXFileWriteError(const std::string& id) { | 911 void ExtensionUpdater::OnCRXFileWriteError(const std::string& id) { |
849 DCHECK(alive_); | 912 DCHECK(alive_); |
850 in_progress_ids_.erase(id); | 913 in_progress_ids_.erase(id); |
851 } | 914 } |
852 | 915 |
853 void ExtensionUpdater::ScheduleNextCheck(const TimeDelta& target_delay) { | 916 void ExtensionUpdater::ScheduleNextCheck(const TimeDelta& target_delay) { |
854 DCHECK(alive_); | 917 DCHECK(alive_); |
855 DCHECK(!timer_.IsRunning()); | 918 DCHECK(!timer_.IsRunning()); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 std::set<std::string>::const_iterator i; | 1222 std::set<std::string>::const_iterator i; |
1160 for (i = ids.begin(); i != ids.end(); ++i) | 1223 for (i = ids.begin(); i != ids.end(); ++i) |
1161 in_progress_ids_.insert(*i); | 1224 in_progress_ids_.insert(*i); |
1162 } | 1225 } |
1163 | 1226 |
1164 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) { | 1227 void ExtensionUpdater::RemoveFromInProgress(const std::set<std::string>& ids) { |
1165 std::set<std::string>::const_iterator i; | 1228 std::set<std::string>::const_iterator i; |
1166 for (i = ids.begin(); i != ids.end(); ++i) | 1229 for (i = ids.begin(); i != ids.end(); ++i) |
1167 in_progress_ids_.erase(*i); | 1230 in_progress_ids_.erase(*i); |
1168 } | 1231 } |
OLD | NEW |