Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Side by Side Diff: components/update_client/update_checker.cc

Issue 1740333002: Allow fallback from https to http for component update checks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 26
27 namespace update_client { 27 namespace update_client {
28 28
29 namespace { 29 namespace {
30 30
31 // Returns a sanitized version of the brand or an empty string otherwise. 31 // Returns a sanitized version of the brand or an empty string otherwise.
32 std::string SanitizeBrand(const std::string& brand) { 32 std::string SanitizeBrand(const std::string& brand) {
33 return IsValidBrand(brand) ? brand : std::string(""); 33 return IsValidBrand(brand) ? brand : std::string("");
34 } 34 }
35 35
36 // Returns true if at least one item requires network encryption.
37 bool IsEncryptionRequired(const std::vector<CrxUpdateItem*>& items) {
38 for (const auto& item : items) {
39 if (item->component.requires_network_encryption)
40 return true;
41 }
42 return false;
43 }
44
36 // Builds an update check request for |components|. |additional_attributes| is 45 // Builds an update check request for |components|. |additional_attributes| is
37 // serialized as part of the <request> element of the request to customize it 46 // serialized as part of the <request> element of the request to customize it
38 // with data that is not platform or component specific. For each |item|, a 47 // with data that is not platform or component specific. For each |item|, a
39 // corresponding <app> element is created and inserted as a child node of 48 // corresponding <app> element is created and inserted as a child node of
40 // the <request>. 49 // the <request>.
41 // 50 //
42 // An app element looks like this: 51 // An app element looks like this:
43 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" 52 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc"
44 // version="0.1.2.3" installsource="ondemand"> 53 // version="0.1.2.3" installsource="ondemand">
45 // <updatecheck /> 54 // <updatecheck />
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 explicit UpdateCheckerImpl(const scoped_refptr<Configurator>& config); 95 explicit UpdateCheckerImpl(const scoped_refptr<Configurator>& config);
87 ~UpdateCheckerImpl() override; 96 ~UpdateCheckerImpl() override;
88 97
89 // Overrides for UpdateChecker. 98 // Overrides for UpdateChecker.
90 bool CheckForUpdates( 99 bool CheckForUpdates(
91 const std::vector<CrxUpdateItem*>& items_to_check, 100 const std::vector<CrxUpdateItem*>& items_to_check,
92 const std::string& additional_attributes, 101 const std::string& additional_attributes,
93 const UpdateCheckCallback& update_check_callback) override; 102 const UpdateCheckCallback& update_check_callback) override;
94 103
95 private: 104 private:
96 void OnRequestSenderComplete(int error, const std::string& response); 105 void OnRequestSenderComplete(int error,
106 const std::string& response,
107 int retry_after_sec);
97 base::ThreadChecker thread_checker_; 108 base::ThreadChecker thread_checker_;
98 109
99 const scoped_refptr<Configurator> config_; 110 const scoped_refptr<Configurator> config_;
100 UpdateCheckCallback update_check_callback_; 111 UpdateCheckCallback update_check_callback_;
101 scoped_ptr<RequestSender> request_sender_; 112 scoped_ptr<RequestSender> request_sender_;
102 113
103 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); 114 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl);
104 }; 115 };
105 116
106 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config) 117 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config)
107 : config_(config) {} 118 : config_(config) {}
108 119
109 UpdateCheckerImpl::~UpdateCheckerImpl() { 120 UpdateCheckerImpl::~UpdateCheckerImpl() {
110 DCHECK(thread_checker_.CalledOnValidThread()); 121 DCHECK(thread_checker_.CalledOnValidThread());
111 } 122 }
112 123
113 bool UpdateCheckerImpl::CheckForUpdates( 124 bool UpdateCheckerImpl::CheckForUpdates(
114 const std::vector<CrxUpdateItem*>& items_to_check, 125 const std::vector<CrxUpdateItem*>& items_to_check,
115 const std::string& additional_attributes, 126 const std::string& additional_attributes,
116 const UpdateCheckCallback& update_check_callback) { 127 const UpdateCheckCallback& update_check_callback) {
117 DCHECK(thread_checker_.CalledOnValidThread()); 128 DCHECK(thread_checker_.CalledOnValidThread());
118 129
119 if (request_sender_.get()) { 130 if (request_sender_.get()) {
120 NOTREACHED(); 131 NOTREACHED();
121 return false; // Another update check is in progress. 132 return false; // Another update check is in progress.
122 } 133 }
123 134
124 update_check_callback_ = update_check_callback; 135 update_check_callback_ = update_check_callback;
125 136
137 auto urls(config_->UpdateUrl());
138 if (IsEncryptionRequired(items_to_check))
139 RemoveUnsecureUrls(&urls);
140
126 request_sender_.reset(new RequestSender(config_)); 141 request_sender_.reset(new RequestSender(config_));
127 request_sender_->Send( 142 request_sender_->Send(
128 config_->UseCupSigning(), 143 config_->UseCupSigning(),
129 BuildUpdateCheckRequest(*config_, items_to_check, additional_attributes), 144 BuildUpdateCheckRequest(*config_, items_to_check, additional_attributes),
130 config_->UpdateUrl(), 145 urls, base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete,
131 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete, 146 base::Unretained(this)));
132 base::Unretained(this)));
133 return true; 147 return true;
134 } 148 }
135 149
136 void UpdateCheckerImpl::OnRequestSenderComplete(int error, 150 void UpdateCheckerImpl::OnRequestSenderComplete(int error,
137 const std::string& response) { 151 const std::string& response,
152 int retry_after_sec) {
138 DCHECK(thread_checker_.CalledOnValidThread()); 153 DCHECK(thread_checker_.CalledOnValidThread());
139 154
140 if (!error) { 155 if (!error) {
141 UpdateResponse update_response; 156 UpdateResponse update_response;
142 if (update_response.Parse(response)) { 157 if (update_response.Parse(response)) {
143 base::ThreadTaskRunnerHandle::Get()->PostTask( 158 base::ThreadTaskRunnerHandle::Get()->PostTask(
144 FROM_HERE, 159 FROM_HERE, base::Bind(update_check_callback_, error,
145 base::Bind(update_check_callback_, error, update_response.results())); 160 update_response.results(), retry_after_sec));
146 return; 161 return;
147 } 162 }
148 163
149 error = -1; 164 error = -1;
150 VLOG(1) << "Parse failed " << update_response.errors(); 165 VLOG(1) << "Parse failed " << update_response.errors();
151 } 166 }
152 167
153 base::ThreadTaskRunnerHandle::Get()->PostTask( 168 base::ThreadTaskRunnerHandle::Get()->PostTask(
154 FROM_HERE, 169 FROM_HERE, base::Bind(update_check_callback_, error,
155 base::Bind(update_check_callback_, error, UpdateResponse::Results())); 170 UpdateResponse::Results(), retry_after_sec));
156 } 171 }
157 172
158 } // namespace 173 } // namespace
159 174
160 scoped_ptr<UpdateChecker> UpdateChecker::Create( 175 scoped_ptr<UpdateChecker> UpdateChecker::Create(
161 const scoped_refptr<Configurator>& config) { 176 const scoped_refptr<Configurator>& config) {
162 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); 177 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config));
163 } 178 }
164 179
165 } // namespace update_client 180 } // namespace update_client
OLDNEW
« no previous file with comments | « components/update_client/update_checker.h ('k') | components/update_client/update_checker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698