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" | |
19 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
20 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
21 #include "base/stl_util.h" | 20 #include "base/stl_util.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
23 #include "base/timer/timer.h" | 22 #include "base/timer/timer.h" |
24 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/component_updater/component_unpacker.h" | 24 #include "chrome/browser/component_updater/component_unpacker.h" |
26 #include "chrome/browser/component_updater/component_updater_ping_manager.h" | 25 #include "chrome/browser/component_updater/component_updater_ping_manager.h" |
27 #include "chrome/browser/component_updater/component_updater_utils.h" | 26 #include "chrome/browser/component_updater/component_updater_utils.h" |
28 #include "chrome/browser/component_updater/crx_downloader.h" | 27 #include "chrome/browser/component_updater/crx_downloader.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); | 147 explicit CrxUpdateService(ComponentUpdateService::Configurator* config); |
149 virtual ~CrxUpdateService(); | 148 virtual ~CrxUpdateService(); |
150 | 149 |
151 // Overrides for ComponentUpdateService. | 150 // Overrides for ComponentUpdateService. |
152 virtual void AddObserver(Observer* observer) OVERRIDE; | 151 virtual void AddObserver(Observer* observer) OVERRIDE; |
153 virtual void RemoveObserver(Observer* observer) OVERRIDE; | 152 virtual void RemoveObserver(Observer* observer) OVERRIDE; |
154 virtual Status Start() OVERRIDE; | 153 virtual Status Start() OVERRIDE; |
155 virtual Status Stop() OVERRIDE; | 154 virtual Status Stop() OVERRIDE; |
156 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; | 155 virtual Status RegisterComponent(const CrxComponent& component) OVERRIDE; |
157 virtual std::vector<std::string> GetComponentIDs() const OVERRIDE; | 156 virtual std::vector<std::string> GetComponentIDs() const OVERRIDE; |
158 virtual CrxUpdateItem* GetComponentDetails( | 157 virtual bool GetComponentDetails(const std::string& component_id, |
159 const std::string& component_id) const OVERRIDE; | 158 CrxUpdateItem* item) const OVERRIDE; |
160 virtual OnDemandUpdater& GetOnDemandUpdater() OVERRIDE; | 159 virtual OnDemandUpdater& GetOnDemandUpdater() OVERRIDE; |
161 | 160 |
162 // Overrides for OnDemandUpdater. | 161 // Overrides for OnDemandUpdater. |
163 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( | 162 virtual content::ResourceThrottle* GetOnDemandResourceThrottle( |
164 net::URLRequest* request, | 163 net::URLRequest* request, |
165 const std::string& crx_id) OVERRIDE; | 164 const std::string& crx_id) OVERRIDE; |
166 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; | 165 virtual Status OnDemandUpdate(const std::string& component_id) OVERRIDE; |
167 | 166 |
168 // Context for a crx download url request. | 167 // Context for a crx download url request. |
169 struct CRXContext { | 168 struct CRXContext { |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 std::vector<std::string> component_ids; | 502 std::vector<std::string> component_ids; |
504 for (UpdateItems::const_iterator it = work_items_.begin(); | 503 for (UpdateItems::const_iterator it = work_items_.begin(); |
505 it != work_items_.end(); | 504 it != work_items_.end(); |
506 ++it) { | 505 ++it) { |
507 const CrxUpdateItem* item = *it; | 506 const CrxUpdateItem* item = *it; |
508 component_ids.push_back(item->id); | 507 component_ids.push_back(item->id); |
509 } | 508 } |
510 return component_ids; | 509 return component_ids; |
511 } | 510 } |
512 | 511 |
513 CrxUpdateItem* CrxUpdateService::GetComponentDetails( | 512 bool CrxUpdateService::GetComponentDetails(const std::string& component_id, |
514 const std::string& component_id) const { | 513 CrxUpdateItem* item) const { |
515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
516 return FindUpdateItemById(component_id); | 515 const CrxUpdateItem* crx_update_item(FindUpdateItemById(component_id)); |
| 516 if (crx_update_item) |
| 517 *item = *crx_update_item; |
| 518 return crx_update_item != NULL; |
517 } | 519 } |
518 | 520 |
519 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() { | 521 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() { |
520 return *this; | 522 return *this; |
521 } | 523 } |
522 | 524 |
523 // This is the main loop of the component updater. It updates one component | 525 // This is the main loop of the component updater. It updates one component |
524 // at a time if updates are available. Otherwise, it does an update check or | 526 // at a time if updates are available. Otherwise, it does an update check or |
525 // takes a long sleep until the loop runs again. | 527 // takes a long sleep until the loop runs again. |
526 void CrxUpdateService::ProcessPendingItems() { | 528 void CrxUpdateService::ProcessPendingItems() { |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 | 1075 |
1074 // The component update factory. Using the component updater as a singleton | 1076 // The component update factory. Using the component updater as a singleton |
1075 // is the job of the browser process. | 1077 // is the job of the browser process. |
1076 ComponentUpdateService* ComponentUpdateServiceFactory( | 1078 ComponentUpdateService* ComponentUpdateServiceFactory( |
1077 ComponentUpdateService::Configurator* config) { | 1079 ComponentUpdateService::Configurator* config) { |
1078 DCHECK(config); | 1080 DCHECK(config); |
1079 return new CrxUpdateService(config); | 1081 return new CrxUpdateService(config); |
1080 } | 1082 } |
1081 | 1083 |
1082 } // namespace component_updater | 1084 } // namespace component_updater |
OLD | NEW |