| 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/component_updater/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 extra_code1(0), | 212 extra_code1(0), |
| 213 diff_error_category(0), | 213 diff_error_category(0), |
| 214 diff_error_code(0), | 214 diff_error_code(0), |
| 215 diff_extra_code1(0) { | 215 diff_extra_code1(0) { |
| 216 } | 216 } |
| 217 | 217 |
| 218 CrxUpdateItem::~CrxUpdateItem() { | 218 CrxUpdateItem::~CrxUpdateItem() { |
| 219 } | 219 } |
| 220 | 220 |
| 221 CrxComponent::CrxComponent() | 221 CrxComponent::CrxComponent() |
| 222 : installer(NULL) { | 222 : installer(NULL), |
| 223 observer(NULL) { |
| 223 } | 224 } |
| 224 | 225 |
| 225 CrxComponent::~CrxComponent() { | 226 CrxComponent::~CrxComponent() { |
| 226 } | 227 } |
| 227 | 228 |
| 228 ////////////////////////////////////////////////////////////////////////////// | 229 ////////////////////////////////////////////////////////////////////////////// |
| 229 // The one and only implementation of the ComponentUpdateService interface. In | 230 // The one and only implementation of the ComponentUpdateService interface. In |
| 230 // charge of running the show. The main method is ProcessPendingItems() which | 231 // charge of running the show. The main method is ProcessPendingItems() which |
| 231 // is called periodically to do the upgrades/installs or the update checks. | 232 // is called periodically to do the upgrades/installs or the update checks. |
| 232 // An important consideration here is to be as "low impact" as we can to the | 233 // An important consideration here is to be as "low impact" as we can to the |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 334 |
| 334 void DoneInstalling(const std::string& component_id, | 335 void DoneInstalling(const std::string& component_id, |
| 335 ComponentUnpacker::Error error, | 336 ComponentUnpacker::Error error, |
| 336 int extended_error); | 337 int extended_error); |
| 337 | 338 |
| 338 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 339 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
| 339 CrxUpdateItem::Status to); | 340 CrxUpdateItem::Status to); |
| 340 | 341 |
| 341 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 342 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| 342 | 343 |
| 344 void NotifyComponentObservers(ComponentObserver::Events event, |
| 345 int extra) const; |
| 346 |
| 343 scoped_ptr<ComponentUpdateService::Configurator> config_; | 347 scoped_ptr<ComponentUpdateService::Configurator> config_; |
| 344 | 348 |
| 345 scoped_ptr<ComponentPatcher> component_patcher_; | 349 scoped_ptr<ComponentPatcher> component_patcher_; |
| 346 | 350 |
| 347 scoped_ptr<net::URLFetcher> url_fetcher_; | 351 scoped_ptr<net::URLFetcher> url_fetcher_; |
| 348 | 352 |
| 349 scoped_ptr<component_updater::PingManager> ping_manager_; | 353 scoped_ptr<component_updater::PingManager> ping_manager_; |
| 350 | 354 |
| 351 // A collection of every work item. | 355 // A collection of every work item. |
| 352 typedef std::vector<CrxUpdateItem*> UpdateItems; | 356 typedef std::vector<CrxUpdateItem*> UpdateItems; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 389 } |
| 386 | 390 |
| 387 ComponentUpdateService::Status CrxUpdateService::Start() { | 391 ComponentUpdateService::Status CrxUpdateService::Start() { |
| 388 // Note that RegisterComponent will call Start() when the first | 392 // Note that RegisterComponent will call Start() when the first |
| 389 // component is registered, so it can be called twice. This way | 393 // component is registered, so it can be called twice. This way |
| 390 // we avoid scheduling the timer if there is no work to do. | 394 // we avoid scheduling the timer if there is no work to do. |
| 391 running_ = true; | 395 running_ = true; |
| 392 if (work_items_.empty()) | 396 if (work_items_.empty()) |
| 393 return kOk; | 397 return kOk; |
| 394 | 398 |
| 399 NotifyComponentObservers(ComponentObserver::COMPONENT_UPDATER_STARTED, 0); |
| 400 |
| 395 content::NotificationService::current()->Notify( | 401 content::NotificationService::current()->Notify( |
| 396 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, | 402 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, |
| 397 content::Source<ComponentUpdateService>(this), | 403 content::Source<ComponentUpdateService>(this), |
| 398 content::NotificationService::NoDetails()); | 404 content::NotificationService::NoDetails()); |
| 399 | 405 |
| 400 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->InitialDelay()), | 406 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->InitialDelay()), |
| 401 this, &CrxUpdateService::ProcessPendingItems); | 407 this, &CrxUpdateService::ProcessPendingItems); |
| 402 return kOk; | 408 return kOk; |
| 403 } | 409 } |
| 404 | 410 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 424 // false. In that case do not loop again. | 430 // false. In that case do not loop again. |
| 425 if (!running_) | 431 if (!running_) |
| 426 return; | 432 return; |
| 427 | 433 |
| 428 // Keep the delay short if in the middle of an update (step_delay), | 434 // Keep the delay short if in the middle of an update (step_delay), |
| 429 // or there are new requested_work_items_ that have not been processed yet. | 435 // or there are new requested_work_items_ that have not been processed yet. |
| 430 int64 delay = (step_delay || requested_work_items_.size() > 0) | 436 int64 delay = (step_delay || requested_work_items_.size() > 0) |
| 431 ? config_->StepDelay() : config_->NextCheckDelay(); | 437 ? config_->StepDelay() : config_->NextCheckDelay(); |
| 432 | 438 |
| 433 if (!step_delay) { | 439 if (!step_delay) { |
| 440 NotifyComponentObservers(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0); |
| 441 |
| 434 content::NotificationService::current()->Notify( | 442 content::NotificationService::current()->Notify( |
| 435 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | 443 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
| 436 content::Source<ComponentUpdateService>(this), | 444 content::Source<ComponentUpdateService>(this), |
| 437 content::NotificationService::NoDetails()); | 445 content::NotificationService::NoDetails()); |
| 438 // Zero is only used for unit tests. | 446 // Zero is only used for unit tests. |
| 439 if (0 == delay) | 447 if (0 == delay) |
| 440 return; | 448 return; |
| 441 } | 449 } |
| 442 | 450 |
| 443 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay), | 451 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay), |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 780 } |
| 773 // All test passed. Queue an upgrade for this component and fire the | 781 // All test passed. Queue an upgrade for this component and fire the |
| 774 // notifications. | 782 // notifications. |
| 775 crx->crx_url = it->crx_url; | 783 crx->crx_url = it->crx_url; |
| 776 crx->diff_crx_url = it->diff_crx_url; | 784 crx->diff_crx_url = it->diff_crx_url; |
| 777 crx->status = CrxUpdateItem::kCanUpdate; | 785 crx->status = CrxUpdateItem::kCanUpdate; |
| 778 crx->next_version = Version(it->version); | 786 crx->next_version = Version(it->version); |
| 779 crx->next_fp = it->package_fingerprint; | 787 crx->next_fp = it->package_fingerprint; |
| 780 ++update_pending; | 788 ++update_pending; |
| 781 | 789 |
| 790 if (crx->component.observer) { |
| 791 crx->component.observer->OnEvent( |
| 792 ComponentObserver::COMPONENT_UPDATE_FOUND, 0); |
| 793 } |
| 794 |
| 782 content::NotificationService::current()->Notify( | 795 content::NotificationService::current()->Notify( |
| 783 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, | 796 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, |
| 784 content::Source<std::string>(&crx->id), | 797 content::Source<std::string>(&crx->id), |
| 785 content::NotificationService::NoDetails()); | 798 content::NotificationService::NoDetails()); |
| 786 } | 799 } |
| 787 | 800 |
| 788 // All the components that are not mentioned in the manifest we | 801 // All the components that are not mentioned in the manifest we |
| 789 // consider them up to date. | 802 // consider them up to date. |
| 790 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate); | 803 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate); |
| 791 | 804 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff, | 861 count = ChangeItemStatus(CrxUpdateItem::kDownloadingDiff, |
| 849 CrxUpdateItem::kUpdatingDiff); | 862 CrxUpdateItem::kUpdatingDiff); |
| 850 } else { | 863 } else { |
| 851 count = ChangeItemStatus(CrxUpdateItem::kDownloading, | 864 count = ChangeItemStatus(CrxUpdateItem::kDownloading, |
| 852 CrxUpdateItem::kUpdating); | 865 CrxUpdateItem::kUpdating); |
| 853 } | 866 } |
| 854 DCHECK_EQ(count, 1ul); | 867 DCHECK_EQ(count, 1ul); |
| 855 | 868 |
| 856 url_fetcher_.reset(); | 869 url_fetcher_.reset(); |
| 857 | 870 |
| 871 if (crx->component.observer) { |
| 872 crx->component.observer->OnEvent( |
| 873 ComponentObserver::COMPONENT_UPDATE_READY, 0); |
| 874 } |
| 875 |
| 858 content::NotificationService::current()->Notify( | 876 content::NotificationService::current()->Notify( |
| 859 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, | 877 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, |
| 860 content::Source<std::string>(&context->id), | 878 content::Source<std::string>(&context->id), |
| 861 content::NotificationService::NoDetails()); | 879 content::NotificationService::NoDetails()); |
| 862 | 880 |
| 863 // Why unretained? See comment at top of file. | 881 // Why unretained? See comment at top of file. |
| 864 BrowserThread::PostDelayedTask( | 882 BrowserThread::PostDelayedTask( |
| 865 BrowserThread::FILE, | 883 BrowserThread::FILE, |
| 866 FROM_HERE, | 884 FROM_HERE, |
| 867 base::Bind(&CrxUpdateService::Install, | 885 base::Bind(&CrxUpdateService::Install, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 item->error_category = error_category; | 959 item->error_category = error_category; |
| 942 item->error_code = error; | 960 item->error_code = error; |
| 943 item->extra_code1 = extra_code; | 961 item->extra_code1 = extra_code; |
| 944 } | 962 } |
| 945 | 963 |
| 946 ping_manager_->OnUpdateComplete(item); | 964 ping_manager_->OnUpdateComplete(item); |
| 947 | 965 |
| 948 ScheduleNextRun(false); | 966 ScheduleNextRun(false); |
| 949 } | 967 } |
| 950 | 968 |
| 969 void CrxUpdateService::NotifyComponentObservers( |
| 970 ComponentObserver::Events event, int extra) const { |
| 971 for (UpdateItems::const_iterator it = work_items_.begin(); |
| 972 it != work_items_.end(); ++it) { |
| 973 ComponentObserver* observer = (*it)->component.observer; |
| 974 if (observer) |
| 975 observer->OnEvent(event, 0); |
| 976 } |
| 977 } |
| 978 |
| 951 // The component update factory. Using the component updater as a singleton | 979 // The component update factory. Using the component updater as a singleton |
| 952 // is the job of the browser process. | 980 // is the job of the browser process. |
| 953 ComponentUpdateService* ComponentUpdateServiceFactory( | 981 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 954 ComponentUpdateService::Configurator* config) { | 982 ComponentUpdateService::Configurator* config) { |
| 955 DCHECK(config); | 983 DCHECK(config); |
| 956 return new CrxUpdateService(config); | 984 return new CrxUpdateService(config); |
| 957 } | 985 } |
| OLD | NEW |