| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/sequenced_task_runner.h" |
| 19 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
| 20 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 21 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
| 22 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
| 23 #include "chrome/browser/component_updater/component_patcher.h" | 24 #include "chrome/browser/component_updater/component_patcher.h" |
| 24 #include "chrome/browser/component_updater/component_unpacker.h" | 25 #include "chrome/browser/component_updater/component_unpacker.h" |
| 25 #include "chrome/browser/component_updater/component_updater_ping_manager.h" | 26 #include "chrome/browser/component_updater/component_updater_ping_manager.h" |
| 26 #include "chrome/browser/component_updater/component_updater_utils.h" | 27 #include "chrome/browser/component_updater/component_updater_utils.h" |
| 27 #include "chrome/browser/component_updater/crx_downloader.h" | 28 #include "chrome/browser/component_updater/crx_downloader.h" |
| 28 #include "chrome/browser/component_updater/crx_update_item.h" | 29 #include "chrome/browser/component_updater/crx_update_item.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 bool CheckForUpdates(); | 218 bool CheckForUpdates(); |
| 218 | 219 |
| 219 void UpdateComponent(CrxUpdateItem* workitem); | 220 void UpdateComponent(CrxUpdateItem* workitem); |
| 220 | 221 |
| 221 void ScheduleNextRun(StepDelayInterval step_delay); | 222 void ScheduleNextRun(StepDelayInterval step_delay); |
| 222 | 223 |
| 223 void ParseResponse(const std::string& xml); | 224 void ParseResponse(const std::string& xml); |
| 224 | 225 |
| 225 void Install(scoped_ptr<CRXContext> context, const base::FilePath& crx_path); | 226 void Install(scoped_ptr<CRXContext> context, const base::FilePath& crx_path); |
| 226 | 227 |
| 228 void EndUnpacking(const std::string& component_id, |
| 229 const base::FilePath& crx_path, |
| 230 ComponentUnpacker::Error error, |
| 231 int extended_error); |
| 232 |
| 227 void DoneInstalling(const std::string& component_id, | 233 void DoneInstalling(const std::string& component_id, |
| 228 ComponentUnpacker::Error error, | 234 ComponentUnpacker::Error error, |
| 229 int extended_error); | 235 int extended_error); |
| 230 | 236 |
| 231 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); | 237 void ChangeItemState(CrxUpdateItem* item, CrxUpdateItem::Status to); |
| 232 | 238 |
| 233 size_t ChangeItemStatus(CrxUpdateItem::Status from, | 239 size_t ChangeItemStatus(CrxUpdateItem::Status from, |
| 234 CrxUpdateItem::Status to); | 240 CrxUpdateItem::Status to); |
| 235 | 241 |
| 236 CrxUpdateItem* FindUpdateItemById(const std::string& id); | 242 CrxUpdateItem* FindUpdateItemById(const std::string& id); |
| 237 | 243 |
| 238 void NotifyComponentObservers(ComponentObserver::Events event, | 244 void NotifyComponentObservers(ComponentObserver::Events event, |
| 239 int extra) const; | 245 int extra) const; |
| 240 | 246 |
| 241 bool HasOnDemandItems() const; | 247 bool HasOnDemandItems() const; |
| 242 | 248 |
| 243 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, | 249 void OnNewResourceThrottle(base::WeakPtr<CUResourceThrottle> rt, |
| 244 const std::string& crx_id); | 250 const std::string& crx_id); |
| 245 | 251 |
| 246 scoped_ptr<ComponentUpdateService::Configurator> config_; | 252 scoped_ptr<ComponentUpdateService::Configurator> config_; |
| 247 | 253 |
| 248 scoped_ptr<ComponentPatcher> component_patcher_; | 254 scoped_ptr<ComponentPatcher> component_patcher_; |
| 249 | 255 |
| 250 scoped_ptr<UpdateChecker> update_checker_; | 256 scoped_ptr<UpdateChecker> update_checker_; |
| 251 | 257 |
| 252 scoped_ptr<PingManager> ping_manager_; | 258 scoped_ptr<PingManager> ping_manager_; |
| 253 | 259 |
| 260 scoped_ptr<ComponentUnpacker> unpacker_; |
| 261 |
| 254 scoped_ptr<CrxDownloader> crx_downloader_; | 262 scoped_ptr<CrxDownloader> crx_downloader_; |
| 255 | 263 |
| 256 // A collection of every work item. | 264 // A collection of every work item. |
| 257 typedef std::vector<CrxUpdateItem*> UpdateItems; | 265 typedef std::vector<CrxUpdateItem*> UpdateItems; |
| 258 UpdateItems work_items_; | 266 UpdateItems work_items_; |
| 259 | 267 |
| 260 base::OneShotTimer<CrxUpdateService> timer_; | 268 base::OneShotTimer<CrxUpdateService> timer_; |
| 261 | 269 |
| 262 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 270 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
| 263 | 271 |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 base::Bind(&CrxUpdateService::Install, | 828 base::Bind(&CrxUpdateService::Install, |
| 821 base::Unretained(this), | 829 base::Unretained(this), |
| 822 base::Passed(&crx_context), | 830 base::Passed(&crx_context), |
| 823 download_result.response), | 831 download_result.response), |
| 824 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 832 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
| 825 } | 833 } |
| 826 } | 834 } |
| 827 | 835 |
| 828 // Install consists of digital signature verification, unpacking and then | 836 // Install consists of digital signature verification, unpacking and then |
| 829 // calling the component specific installer. All that is handled by the | 837 // calling the component specific installer. All that is handled by the |
| 830 // |unpacker|. If there is an error this function is in charge of deleting | 838 // |unpacker_|. If there is an error this function is in charge of deleting |
| 831 // the files created. | 839 // the files created. |
| 832 void CrxUpdateService::Install(scoped_ptr<CRXContext> context, | 840 void CrxUpdateService::Install(scoped_ptr<CRXContext> context, |
| 833 const base::FilePath& crx_path) { | 841 const base::FilePath& crx_path) { |
| 834 // This function owns the file at |crx_path| and the |context| object. | 842 // This function owns the file at |crx_path| and the |context| object. |
| 835 ComponentUnpacker unpacker(context->pk_hash, | 843 unpacker_.reset(new ComponentUnpacker(context->pk_hash, |
| 836 crx_path, | 844 crx_path, |
| 837 context->fingerprint, | 845 context->fingerprint, |
| 838 component_patcher_.get(), | 846 component_patcher_.get(), |
| 839 context->installer); | 847 context->installer, |
| 848 blocking_task_runner_)); |
| 849 unpacker_->Unpack(base::Bind(&CrxUpdateService::EndUnpacking, |
| 850 base::Unretained(this), |
| 851 context->id, |
| 852 crx_path)); |
| 853 } |
| 854 |
| 855 void CrxUpdateService::EndUnpacking(const std::string& component_id, |
| 856 const base::FilePath& crx_path, |
| 857 ComponentUnpacker::Error error, |
| 858 int extended_error) { |
| 840 if (!DeleteFileAndEmptyParentDirectory(crx_path)) | 859 if (!DeleteFileAndEmptyParentDirectory(crx_path)) |
| 841 NOTREACHED() << crx_path.value(); | 860 NOTREACHED() << crx_path.value(); |
| 842 | |
| 843 // Why unretained? See comment at top of file. | |
| 844 BrowserThread::PostDelayedTask( | 861 BrowserThread::PostDelayedTask( |
| 845 BrowserThread::UI, | 862 BrowserThread::UI, |
| 846 FROM_HERE, | 863 FROM_HERE, |
| 847 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), | 864 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this), |
| 848 context->id, unpacker.error(), unpacker.extended_error()), | 865 component_id, error, extended_error), |
| 849 base::TimeDelta::FromMilliseconds(config_->StepDelay())); | 866 base::TimeDelta::FromMilliseconds(config_->StepDelay())); |
| 850 } | 867 } |
| 851 | 868 |
| 852 // Installation has been completed. Adjust the component status and | 869 // Installation has been completed. Adjust the component status and |
| 853 // schedule the next check. Schedule a short delay before trying the full | 870 // schedule the next check. Schedule a short delay before trying the full |
| 854 // update when the differential update failed. | 871 // update when the differential update failed. |
| 855 void CrxUpdateService::DoneInstalling(const std::string& component_id, | 872 void CrxUpdateService::DoneInstalling(const std::string& component_id, |
| 856 ComponentUnpacker::Error error, | 873 ComponentUnpacker::Error error, |
| 857 int extra_code) { | 874 int extra_code) { |
| 858 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 875 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 // The component update factory. Using the component updater as a singleton | 995 // The component update factory. Using the component updater as a singleton |
| 979 // is the job of the browser process. | 996 // is the job of the browser process. |
| 980 ComponentUpdateService* ComponentUpdateServiceFactory( | 997 ComponentUpdateService* ComponentUpdateServiceFactory( |
| 981 ComponentUpdateService::Configurator* config) { | 998 ComponentUpdateService::Configurator* config) { |
| 982 DCHECK(config); | 999 DCHECK(config); |
| 983 return new CrxUpdateService(config); | 1000 return new CrxUpdateService(config); |
| 984 } | 1001 } |
| 985 | 1002 |
| 986 } // namespace component_updater | 1003 } // namespace component_updater |
| 987 | 1004 |
| OLD | NEW |