OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/component_updater/component_updater_service.h" | 5 #include "components/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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // eligible for update, we only do one thing at a time with pauses in between | 96 // eligible for update, we only do one thing at a time with pauses in between |
97 // the tasks. Also when we do network requests there is only one |url_fetcher_| | 97 // the tasks. Also when we do network requests there is only one |url_fetcher_| |
98 // in flight at a time. | 98 // in flight at a time. |
99 // There are no locks in this code, the main structure |work_items_| is mutated | 99 // There are no locks in this code, the main structure |work_items_| is mutated |
100 // only from the main thread. The unpack and installation is done in a blocking | 100 // only from the main thread. The unpack and installation is done in a blocking |
101 // pool thread. The network requests are done in the IO thread or in the file | 101 // pool thread. The network requests are done in the IO thread or in the file |
102 // thread. | 102 // thread. |
103 class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater { | 103 class CrxUpdateService : public ComponentUpdateService, public OnDemandUpdater { |
104 public: | 104 public: |
105 explicit CrxUpdateService(Configurator* config); | 105 explicit CrxUpdateService(Configurator* config); |
106 virtual ~CrxUpdateService(); | 106 ~CrxUpdateService() override; |
107 | 107 |
108 // Overrides for ComponentUpdateService. | 108 // Overrides for ComponentUpdateService. |
109 virtual void AddObserver(Observer* observer) override; | 109 void AddObserver(Observer* observer) override; |
110 virtual void RemoveObserver(Observer* observer) override; | 110 void RemoveObserver(Observer* observer) override; |
111 virtual Status Start() override; | 111 Status Start() override; |
112 virtual Status Stop() override; | 112 Status Stop() override; |
113 virtual Status RegisterComponent(const CrxComponent& component) override; | 113 Status RegisterComponent(const CrxComponent& component) override; |
114 virtual std::vector<std::string> GetComponentIDs() const override; | 114 std::vector<std::string> GetComponentIDs() const override; |
115 virtual OnDemandUpdater& GetOnDemandUpdater() override; | 115 OnDemandUpdater& GetOnDemandUpdater() override; |
116 virtual void MaybeThrottle(const std::string& crx_id, | 116 void MaybeThrottle(const std::string& crx_id, |
117 const base::Closure& callback) override; | 117 const base::Closure& callback) override; |
118 virtual scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() | 118 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override; |
119 override; | |
120 | 119 |
121 // Context for a crx download url request. | 120 // Context for a crx download url request. |
122 struct CRXContext { | 121 struct CRXContext { |
123 ComponentInstaller* installer; | 122 ComponentInstaller* installer; |
124 std::vector<uint8_t> pk_hash; | 123 std::vector<uint8_t> pk_hash; |
125 std::string id; | 124 std::string id; |
126 std::string fingerprint; | 125 std::string fingerprint; |
127 CRXContext() : installer(NULL) {} | 126 CRXContext() : installer(NULL) {} |
128 }; | 127 }; |
129 | 128 |
130 private: | 129 private: |
131 enum ErrorCategory { | 130 enum ErrorCategory { |
132 kErrorNone = 0, | 131 kErrorNone = 0, |
133 kNetworkError, | 132 kNetworkError, |
134 kUnpackError, | 133 kUnpackError, |
135 kInstallError, | 134 kInstallError, |
136 }; | 135 }; |
137 | 136 |
138 enum StepDelayInterval { | 137 enum StepDelayInterval { |
139 kStepDelayShort = 0, | 138 kStepDelayShort = 0, |
140 kStepDelayMedium, | 139 kStepDelayMedium, |
141 kStepDelayLong, | 140 kStepDelayLong, |
142 }; | 141 }; |
143 | 142 |
144 // Overrides for ComponentUpdateService. | 143 // Overrides for ComponentUpdateService. |
145 virtual bool GetComponentDetails(const std::string& component_id, | 144 bool GetComponentDetails(const std::string& component_id, |
146 CrxUpdateItem* item) const override; | 145 CrxUpdateItem* item) const override; |
147 | 146 |
148 // Overrides for OnDemandUpdater. | 147 // Overrides for OnDemandUpdater. |
149 virtual Status OnDemandUpdate(const std::string& component_id) override; | 148 Status OnDemandUpdate(const std::string& component_id) override; |
150 | 149 |
151 void UpdateCheckComplete(const GURL& original_url, | 150 void UpdateCheckComplete(const GURL& original_url, |
152 int error, | 151 int error, |
153 const std::string& error_message, | 152 const std::string& error_message, |
154 const UpdateResponse::Results& results); | 153 const UpdateResponse::Results& results); |
155 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results); | 154 void OnUpdateCheckSucceeded(const UpdateResponse::Results& results); |
156 void OnUpdateCheckFailed(int error, const std::string& error_message); | 155 void OnUpdateCheckFailed(int error, const std::string& error_message); |
157 | 156 |
158 void DownloadProgress(const std::string& component_id, | 157 void DownloadProgress(const std::string& component_id, |
159 const CrxDownloader::Result& download_result); | 158 const CrxDownloader::Result& download_result); |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 /////////////////////////////////////////////////////////////////////////////// | 1013 /////////////////////////////////////////////////////////////////////////////// |
1015 | 1014 |
1016 // The component update factory. Using the component updater as a singleton | 1015 // The component update factory. Using the component updater as a singleton |
1017 // is the job of the browser process. | 1016 // is the job of the browser process. |
1018 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { | 1017 ComponentUpdateService* ComponentUpdateServiceFactory(Configurator* config) { |
1019 DCHECK(config); | 1018 DCHECK(config); |
1020 return new CrxUpdateService(config); | 1019 return new CrxUpdateService(config); |
1021 } | 1020 } |
1022 | 1021 |
1023 } // namespace component_updater | 1022 } // namespace component_updater |
OLD | NEW |