| 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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 explicit UpdateCheckerImpl(const scoped_refptr<Configurator>& config); | 78 explicit UpdateCheckerImpl(const scoped_refptr<Configurator>& config); |
| 79 ~UpdateCheckerImpl() override; | 79 ~UpdateCheckerImpl() override; |
| 80 | 80 |
| 81 // Overrides for UpdateChecker. | 81 // Overrides for UpdateChecker. |
| 82 bool CheckForUpdates( | 82 bool CheckForUpdates( |
| 83 const std::vector<CrxUpdateItem*>& items_to_check, | 83 const std::vector<CrxUpdateItem*>& items_to_check, |
| 84 const std::string& additional_attributes, | 84 const std::string& additional_attributes, |
| 85 const UpdateCheckCallback& update_check_callback) override; | 85 const UpdateCheckCallback& update_check_callback) override; |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 void OnRequestSenderComplete(int error, const std::string& response); | 88 void OnRequestSenderComplete(int error, |
| 89 const std::string& response, |
| 90 int retry_after_sec); |
| 89 base::ThreadChecker thread_checker_; | 91 base::ThreadChecker thread_checker_; |
| 90 | 92 |
| 91 const scoped_refptr<Configurator> config_; | 93 const scoped_refptr<Configurator> config_; |
| 92 UpdateCheckCallback update_check_callback_; | 94 UpdateCheckCallback update_check_callback_; |
| 93 scoped_ptr<RequestSender> request_sender_; | 95 scoped_ptr<RequestSender> request_sender_; |
| 94 | 96 |
| 95 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); | 97 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); |
| 96 }; | 98 }; |
| 97 | 99 |
| 98 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config) | 100 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 119 request_sender_->Send( | 121 request_sender_->Send( |
| 120 config_->UseCupSigning(), | 122 config_->UseCupSigning(), |
| 121 BuildUpdateCheckRequest(*config_, items_to_check, additional_attributes), | 123 BuildUpdateCheckRequest(*config_, items_to_check, additional_attributes), |
| 122 config_->UpdateUrl(), | 124 config_->UpdateUrl(), |
| 123 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete, | 125 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete, |
| 124 base::Unretained(this))); | 126 base::Unretained(this))); |
| 125 return true; | 127 return true; |
| 126 } | 128 } |
| 127 | 129 |
| 128 void UpdateCheckerImpl::OnRequestSenderComplete(int error, | 130 void UpdateCheckerImpl::OnRequestSenderComplete(int error, |
| 129 const std::string& response) { | 131 const std::string& response, |
| 132 int retry_after_sec) { |
| 130 DCHECK(thread_checker_.CalledOnValidThread()); | 133 DCHECK(thread_checker_.CalledOnValidThread()); |
| 131 | 134 |
| 132 if (!error) { | 135 if (!error) { |
| 133 UpdateResponse update_response; | 136 UpdateResponse update_response; |
| 134 if (update_response.Parse(response)) { | 137 if (update_response.Parse(response)) { |
| 135 base::ThreadTaskRunnerHandle::Get()->PostTask( | 138 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 136 FROM_HERE, | 139 FROM_HERE, base::Bind(update_check_callback_, error, |
| 137 base::Bind(update_check_callback_, error, update_response.results())); | 140 update_response.results(), retry_after_sec)); |
| 138 return; | 141 return; |
| 139 } | 142 } |
| 140 | 143 |
| 141 error = -1; | 144 error = -1; |
| 142 VLOG(1) << "Parse failed " << update_response.errors(); | 145 VLOG(1) << "Parse failed " << update_response.errors(); |
| 143 } | 146 } |
| 144 | 147 |
| 145 base::ThreadTaskRunnerHandle::Get()->PostTask( | 148 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 146 FROM_HERE, | 149 FROM_HERE, base::Bind(update_check_callback_, error, |
| 147 base::Bind(update_check_callback_, error, UpdateResponse::Results())); | 150 UpdateResponse::Results(), retry_after_sec)); |
| 148 } | 151 } |
| 149 | 152 |
| 150 } // namespace | 153 } // namespace |
| 151 | 154 |
| 152 scoped_ptr<UpdateChecker> UpdateChecker::Create( | 155 scoped_ptr<UpdateChecker> UpdateChecker::Create( |
| 153 const scoped_refptr<Configurator>& config) { | 156 const scoped_refptr<Configurator>& config) { |
| 154 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); | 157 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); |
| 155 } | 158 } |
| 156 | 159 |
| 157 } // namespace update_client | 160 } // namespace update_client |
| OLD | NEW |