Chromium Code Reviews| 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/update_client/update_checker.h" | 5 #include "components/update_client/update_checker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 // Include the updater state in the update check request. | 138 // Include the updater state in the update check request. |
| 139 return BuildProtocolRequest( | 139 return BuildProtocolRequest( |
| 140 config.GetProdId(), config.GetBrowserVersion().GetString(), | 140 config.GetProdId(), config.GetBrowserVersion().GetString(), |
| 141 config.GetChannel(), config.GetLang(), config.GetOSLongName(), | 141 config.GetChannel(), config.GetLang(), config.GetOSLongName(), |
| 142 config.GetDownloadPreference(), app_elements, additional_attributes, | 142 config.GetDownloadPreference(), app_elements, additional_attributes, |
| 143 updater_state_attributes); | 143 updater_state_attributes); |
| 144 } | 144 } |
| 145 | 145 |
| 146 class UpdateCheckerImpl : public UpdateChecker { | 146 class UpdateCheckerImpl : public UpdateChecker { |
| 147 public: | 147 public: |
| 148 UpdateCheckerImpl(const scoped_refptr<Configurator>& config, | 148 UpdateCheckerImpl(const scoped_refptr<Configurator>& config); |
| 149 PersistedData* metadata); | |
| 150 ~UpdateCheckerImpl() override; | 149 ~UpdateCheckerImpl() override; |
| 151 | 150 |
| 152 // Overrides for UpdateChecker. | 151 // Overrides for UpdateChecker. |
| 153 bool CheckForUpdates( | 152 bool CheckForUpdates( |
| 154 const std::vector<std::string>& ids_checked, | 153 const std::vector<std::string>& ids_checked, |
| 155 const IdToComponentPtrMap& components, | 154 const IdToComponentPtrMap& components, |
| 156 const std::string& additional_attributes, | 155 const std::string& additional_attributes, |
| 157 bool enabled_component_updates, | 156 bool enabled_component_updates, |
| 158 const UpdateCheckCallback& update_check_callback) override; | 157 const UpdateCheckCallback& update_check_callback) override; |
| 159 | 158 |
| 160 private: | 159 private: |
| 161 void ReadUpdaterStateAttributes(); | 160 void ReadUpdaterStateAttributes(); |
| 162 void CheckForUpdatesHelper(const IdToComponentPtrMap& components, | 161 void CheckForUpdatesHelper(const IdToComponentPtrMap& components, |
| 163 const std::string& additional_attributes, | 162 const std::string& additional_attributes, |
| 164 bool enabled_component_updates); | 163 bool enabled_component_updates); |
| 165 void OnRequestSenderComplete(const IdToComponentPtrMap& components, | 164 void OnRequestSenderComplete(const IdToComponentPtrMap& components, |
| 166 int error, | 165 int error, |
| 167 const std::string& response, | 166 const std::string& response, |
| 168 int retry_after_sec); | 167 int retry_after_sec); |
| 169 void UpdateCheckSucceeded(const IdToComponentPtrMap& components, | 168 void UpdateCheckSucceeded(const IdToComponentPtrMap& components, |
| 170 const UpdateResponse::Results& results, | 169 const UpdateResponse::Results& results, |
| 171 int retry_after_sec); | 170 int retry_after_sec); |
| 172 void UpdateCheckFailed(const IdToComponentPtrMap& components, | 171 void UpdateCheckFailed(const IdToComponentPtrMap& components, |
| 173 int error, | 172 int error, |
| 174 int retry_after_sec); | 173 int retry_after_sec); |
| 175 | 174 |
| 176 base::ThreadChecker thread_checker_; | 175 base::ThreadChecker thread_checker_; |
| 177 | 176 |
| 178 const scoped_refptr<Configurator> config_; | 177 const scoped_refptr<Configurator> config_; |
| 179 PersistedData* metadata_ = nullptr; | 178 std::unique_ptr<PersistedData> metadata_; |
| 180 std::vector<std::string> ids_checked_; | 179 std::vector<std::string> ids_checked_; |
| 181 UpdateCheckCallback update_check_callback_; | 180 UpdateCheckCallback update_check_callback_; |
| 182 std::unique_ptr<UpdaterState::Attributes> updater_state_attributes_; | 181 std::unique_ptr<UpdaterState::Attributes> updater_state_attributes_; |
| 183 std::unique_ptr<RequestSender> request_sender_; | 182 std::unique_ptr<RequestSender> request_sender_; |
| 184 | 183 |
| 185 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); | 184 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); |
| 186 }; | 185 }; |
| 187 | 186 |
| 188 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config, | 187 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config) |
| 189 PersistedData* metadata) | 188 : config_(config), metadata_(config->CreateMetadata()) {} |
|
waffles
2017/05/12 17:33:34
This will be called once per update check - I thin
Minh X. Nguyen
2017/05/14 23:57:22
As discussed offline, it's better to store Persist
| |
| 190 : config_(config), metadata_(metadata) {} | |
| 191 | 189 |
| 192 UpdateCheckerImpl::~UpdateCheckerImpl() { | 190 UpdateCheckerImpl::~UpdateCheckerImpl() { |
| 193 DCHECK(thread_checker_.CalledOnValidThread()); | 191 DCHECK(thread_checker_.CalledOnValidThread()); |
| 194 } | 192 } |
| 195 | 193 |
| 196 bool UpdateCheckerImpl::CheckForUpdates( | 194 bool UpdateCheckerImpl::CheckForUpdates( |
| 197 const std::vector<std::string>& ids_checked, | 195 const std::vector<std::string>& ids_checked, |
| 198 const IdToComponentPtrMap& components, | 196 const IdToComponentPtrMap& components, |
| 199 const std::string& additional_attributes, | 197 const std::string& additional_attributes, |
| 200 bool enabled_component_updates, | 198 bool enabled_component_updates, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 225 bool enabled_component_updates) { | 223 bool enabled_component_updates) { |
| 226 DCHECK(thread_checker_.CalledOnValidThread()); | 224 DCHECK(thread_checker_.CalledOnValidThread()); |
| 227 | 225 |
| 228 auto urls(config_->UpdateUrl()); | 226 auto urls(config_->UpdateUrl()); |
| 229 if (IsEncryptionRequired(components)) | 227 if (IsEncryptionRequired(components)) |
| 230 RemoveUnsecureUrls(&urls); | 228 RemoveUnsecureUrls(&urls); |
| 231 | 229 |
| 232 request_sender_ = base::MakeUnique<RequestSender>(config_); | 230 request_sender_ = base::MakeUnique<RequestSender>(config_); |
| 233 request_sender_->Send( | 231 request_sender_->Send( |
| 234 config_->EnabledCupSigning(), | 232 config_->EnabledCupSigning(), |
| 235 BuildUpdateCheckRequest(*config_, ids_checked_, components, metadata_, | 233 BuildUpdateCheckRequest(*config_, ids_checked_, components, |
| 236 additional_attributes, enabled_component_updates, | 234 metadata_.get(), additional_attributes, |
| 235 enabled_component_updates, | |
| 237 updater_state_attributes_), | 236 updater_state_attributes_), |
| 238 urls, | 237 urls, |
| 239 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete, | 238 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete, |
| 240 base::Unretained(this), base::ConstRef(components))); | 239 base::Unretained(this), base::ConstRef(components))); |
| 241 } | 240 } |
| 242 | 241 |
| 243 void UpdateCheckerImpl::OnRequestSenderComplete( | 242 void UpdateCheckerImpl::OnRequestSenderComplete( |
| 244 const IdToComponentPtrMap& components, | 243 const IdToComponentPtrMap& components, |
| 245 int error, | 244 int error, |
| 246 const std::string& response, | 245 const std::string& response, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 307 component.set_update_check_error(error); | 306 component.set_update_check_error(error); |
| 308 } | 307 } |
| 309 | 308 |
| 310 base::ThreadTaskRunnerHandle::Get()->PostTask( | 309 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 311 FROM_HERE, base::Bind(update_check_callback_, error, retry_after_sec)); | 310 FROM_HERE, base::Bind(update_check_callback_, error, retry_after_sec)); |
| 312 } | 311 } |
| 313 | 312 |
| 314 } // namespace | 313 } // namespace |
| 315 | 314 |
| 316 std::unique_ptr<UpdateChecker> UpdateChecker::Create( | 315 std::unique_ptr<UpdateChecker> UpdateChecker::Create( |
| 317 const scoped_refptr<Configurator>& config, | 316 const scoped_refptr<Configurator>& config) { |
| 318 PersistedData* persistent) { | 317 return base::MakeUnique<UpdateCheckerImpl>(config); |
| 319 return base::MakeUnique<UpdateCheckerImpl>(config, persistent); | |
| 320 } | 318 } |
| 321 | 319 |
| 322 } // namespace update_client | 320 } // namespace update_client |
| OLD | NEW |