Chromium Code Reviews| Index: chrome/browser/component_updater/component_updater_service.cc |
| diff --git a/chrome/browser/component_updater/component_updater_service.cc b/chrome/browser/component_updater/component_updater_service.cc |
| index 268cfb242c5552b415e69a9e3d16f896193073b0..212e31381ef4014b430a9997454362e60304db23 100644 |
| --- a/chrome/browser/component_updater/component_updater_service.cc |
| +++ b/chrome/browser/component_updater/component_updater_service.cc |
| @@ -90,12 +90,6 @@ CrxComponent::CrxComponent() |
| CrxComponent::~CrxComponent() { |
| } |
| -CrxComponentInfo::CrxComponentInfo() { |
| -} |
| - |
| -CrxComponentInfo::~CrxComponentInfo() { |
| -} |
| - |
| /////////////////////////////////////////////////////////////////////////////// |
| // In charge of blocking url requests until the |crx_id| component has been |
| // updated. This class is touched solely from the IO thread. The UI thread |
| @@ -169,8 +163,10 @@ class CrxUpdateService : public ComponentUpdateService { |
| virtual Status Stop() OVERRIDE; |
| virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; |
| virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; |
| - virtual void GetComponents( |
| - std::vector<CrxComponentInfo>* components) OVERRIDE; |
| + virtual std::vector<std::string> GetComponentIDs() const OVERRIDE; |
| + virtual CrxUpdateItem* GetComponentDetails( |
| + const std::string& component_id) const OVERRIDE; |
| + |
| virtual content::ResourceThrottle* GetOnDemandResourceThrottle( |
| net::URLRequest* request, const std::string& crx_id) OVERRIDE; |
| @@ -243,7 +239,7 @@ class CrxUpdateService : public ComponentUpdateService { |
| size_t ChangeItemStatus(CrxUpdateItem::Status from, |
| CrxUpdateItem::Status to); |
| - CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| + CrxUpdateItem* FindUpdateItemById(const std::string& id) const; |
| void NotifyObservers(Observer::Events event, const std::string& id); |
| @@ -252,6 +248,8 @@ class CrxUpdateService : public ComponentUpdateService { |
| void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, |
| const std::string& crx_id); |
| + Status GetServiceStatus(const CrxUpdateItem::Status status); |
| + |
| scoped_ptr<ComponentUpdateService::Configurator> config_; |
| scoped_ptr<UpdateChecker> update_checker_; |
| @@ -401,12 +399,13 @@ void CrxUpdateService::ScheduleNextRun(StepDelayInterval step_delay) { |
| } |
| // Given a extension-like component id, find the associated component. |
| -CrxUpdateItem* CrxUpdateService::FindUpdateItemById(const std::string& id) { |
| +CrxUpdateItem* CrxUpdateService::FindUpdateItemById( |
| + const std::string& id) const { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| CrxUpdateItem::FindById finder(id); |
| - UpdateItems::iterator it = std::find_if(work_items_.begin(), |
| - work_items_.end(), |
| - finder); |
| + UpdateItems::const_iterator it = std::find_if(work_items_.begin(), |
| + work_items_.end(), |
| + finder); |
| return it != work_items_.end() ? *it : NULL; |
| } |
| @@ -522,28 +521,16 @@ ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( |
| if (delta < base::TimeDelta::FromSeconds(config_->OnDemandDelay())) |
| return kError; |
| - switch (uit->status) { |
| - // If the item is already in the process of being updated, there is |
| - // no point in this call, so return kInProgress. |
| - case CrxUpdateItem::kChecking: |
| - case CrxUpdateItem::kCanUpdate: |
| - case CrxUpdateItem::kDownloadingDiff: |
| - case CrxUpdateItem::kDownloading: |
| - case CrxUpdateItem::kUpdatingDiff: |
| - case CrxUpdateItem::kUpdating: |
| - return kInProgress; |
| - // Otherwise the item was already checked a while back (or it is new), |
| - // set its status to kNew to give it a slightly higher priority. |
| - case CrxUpdateItem::kNew: |
| - case CrxUpdateItem::kUpdated: |
| - case CrxUpdateItem::kUpToDate: |
| - case CrxUpdateItem::kNoUpdate: |
| - ChangeItemState(uit, CrxUpdateItem::kNew); |
| - uit->on_demand = true; |
| - break; |
| - case CrxUpdateItem::kLastStatus: |
| - NOTREACHED() << uit->status; |
| - } |
| + Status service_status = GetServiceStatus(uit->status); |
| + // If the item is already in the process of being updated, there is |
| + // no point in this call, so return kInProgress. |
| + if (service_status == kInProgress) |
| + return service_status; |
| + |
| + // Otherwise the item was already checked a while back (or it is new), |
| + // set its status to kNew to give it a slightly higher priority. |
| + ChangeItemState(uit, CrxUpdateItem::kNew); |
| + uit->on_demand = true; |
| // In case the current delay is long, set the timer to a shorter value |
| // to get the ball rolling. |
| @@ -556,20 +543,25 @@ ComponentUpdateService::Status CrxUpdateService::OnDemandUpdateInternal( |
| return kOk; |
| } |
| -void CrxUpdateService::GetComponents( |
| - std::vector<CrxComponentInfo>* components) { |
| +std::vector<std::string> CrxUpdateService::GetComponentIDs() const { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + std::vector<std::string> component_ids; |
| for (UpdateItems::const_iterator it = work_items_.begin(); |
| it != work_items_.end(); ++it) { |
| const CrxUpdateItem* item = *it; |
| - CrxComponentInfo info; |
| - info.id = GetCrxComponentID(item->component); |
| - info.version = item->component.version.GetString(); |
| - info.name = item->component.name; |
| - components->push_back(info); |
| + component_ids.push_back(item->id); |
| } |
| + return component_ids; |
| } |
| +CrxUpdateItem* CrxUpdateService::GetComponentDetails( |
| + const std::string& component_id) const { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + CrxUpdateItem* item = FindUpdateItemById(component_id); |
|
Sorin Jianu
2014/05/08 22:07:24
we could just return FindUpdateItemById(component_
Shrikant Kelkar
2014/05/15 23:12:43
Done.
|
| + return item; |
| +} |
| + |
| + |
|
Sorin Jianu
2014/05/08 22:07:24
One extra empty line could be removed.
Shrikant Kelkar
2014/05/15 23:12:43
Done.
|
| // This is the main loop of the component updater. It updates one component |
| // at a time if updates are available. Otherwise, it does an update check or |
| // takes a long sleep until the loop runs again. |
| @@ -1013,6 +1005,28 @@ void CrxUpdateService::OnNewResourceThrottle( |
| UnblockResourceThrottle(rt); |
| } |
| +ComponentUpdateService::Status CrxUpdateService::GetServiceStatus( |
| + CrxUpdateItem::Status status) { |
| + switch (status) { |
| + case CrxUpdateItem::kChecking: |
| + case CrxUpdateItem::kCanUpdate: |
| + case CrxUpdateItem::kDownloadingDiff: |
| + case CrxUpdateItem::kDownloading: |
| + case CrxUpdateItem::kUpdatingDiff: |
| + case CrxUpdateItem::kUpdating: |
| + return kInProgress; |
| + case CrxUpdateItem::kNew: |
| + case CrxUpdateItem::kUpdated: |
| + case CrxUpdateItem::kUpToDate: |
| + case CrxUpdateItem::kNoUpdate: |
| + return kOk; |
| + break; |
| + case CrxUpdateItem::kLastStatus: |
| + NOTREACHED() << status; |
| + } |
| + return kError; |
| +} |
| + |
| /////////////////////////////////////////////////////////////////////////////// |
| CUResourceThrottle::CUResourceThrottle(const net::URLRequest* request) |