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

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

Issue 1685323002: Implement CUP signing in UpdateClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase and remove duplicated code comment. Created 4 years, 10 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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/threading/thread_checker.h" 20 #include "base/threading/thread_checker.h"
21 #include "components/update_client/configurator.h" 21 #include "components/update_client/configurator.h"
22 #include "components/update_client/crx_update_item.h" 22 #include "components/update_client/crx_update_item.h"
23 #include "components/update_client/request_sender.h" 23 #include "components/update_client/request_sender.h"
24 #include "components/update_client/utils.h" 24 #include "components/update_client/utils.h"
25 #include "net/url_request/url_fetcher.h"
26 #include "url/gurl.h" 25 #include "url/gurl.h"
27 26
28 namespace update_client { 27 namespace update_client {
29 28
30 namespace { 29 namespace {
31 30
32 // Builds an update check request for |components|. |additional_attributes| is 31 // Builds an update check request for |components|. |additional_attributes| is
33 // serialized as part of the <request> element of the request to customize it 32 // serialized as part of the <request> element of the request to customize it
34 // with data that is not platform or component specific. For each |item|, a 33 // with data that is not platform or component specific. For each |item|, a
35 // corresponding <app> element is created and inserted as a child node of 34 // corresponding <app> element is created and inserted as a child node of
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 explicit UpdateCheckerImpl(const scoped_refptr<Configurator>& config); 78 explicit UpdateCheckerImpl(const scoped_refptr<Configurator>& config);
80 ~UpdateCheckerImpl() override; 79 ~UpdateCheckerImpl() override;
81 80
82 // Overrides for UpdateChecker. 81 // Overrides for UpdateChecker.
83 bool CheckForUpdates( 82 bool CheckForUpdates(
84 const std::vector<CrxUpdateItem*>& items_to_check, 83 const std::vector<CrxUpdateItem*>& items_to_check,
85 const std::string& additional_attributes, 84 const std::string& additional_attributes,
86 const UpdateCheckCallback& update_check_callback) override; 85 const UpdateCheckCallback& update_check_callback) override;
87 86
88 private: 87 private:
89 void OnRequestSenderComplete(const net::URLFetcher* source); 88 void OnRequestSenderComplete(int error, const std::string& response);
89 base::ThreadChecker thread_checker_;
90 90
91 const scoped_refptr<Configurator> config_; 91 const scoped_refptr<Configurator> config_;
92 UpdateCheckCallback update_check_callback_; 92 UpdateCheckCallback update_check_callback_;
93 scoped_ptr<RequestSender> request_sender_; 93 scoped_ptr<RequestSender> request_sender_;
94 94
95 base::ThreadChecker thread_checker_;
96
97 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); 95 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl);
98 }; 96 };
99 97
100 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config) 98 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config)
101 : config_(config) {} 99 : config_(config) {}
102 100
103 UpdateCheckerImpl::~UpdateCheckerImpl() { 101 UpdateCheckerImpl::~UpdateCheckerImpl() {
104 DCHECK(thread_checker_.CalledOnValidThread()); 102 DCHECK(thread_checker_.CalledOnValidThread());
105 } 103 }
106 104
107 bool UpdateCheckerImpl::CheckForUpdates( 105 bool UpdateCheckerImpl::CheckForUpdates(
108 const std::vector<CrxUpdateItem*>& items_to_check, 106 const std::vector<CrxUpdateItem*>& items_to_check,
109 const std::string& additional_attributes, 107 const std::string& additional_attributes,
110 const UpdateCheckCallback& update_check_callback) { 108 const UpdateCheckCallback& update_check_callback) {
111 DCHECK(thread_checker_.CalledOnValidThread()); 109 DCHECK(thread_checker_.CalledOnValidThread());
112 110
113 if (request_sender_.get()) { 111 if (request_sender_.get()) {
114 NOTREACHED(); 112 NOTREACHED();
115 return false; // Another update check is in progress. 113 return false; // Another update check is in progress.
116 } 114 }
117 115
118 update_check_callback_ = update_check_callback; 116 update_check_callback_ = update_check_callback;
119 117
120 request_sender_.reset(new RequestSender(config_)); 118 request_sender_.reset(new RequestSender(config_));
121 request_sender_->Send( 119 request_sender_->Send(
120 config_->UseCupSigning(),
122 BuildUpdateCheckRequest(*config_, items_to_check, additional_attributes), 121 BuildUpdateCheckRequest(*config_, items_to_check, additional_attributes),
123 config_->UpdateUrl(), 122 config_->UpdateUrl(),
124 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete, 123 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete,
125 base::Unretained(this))); 124 base::Unretained(this)));
126 return true; 125 return true;
127 } 126 }
128 127
129 void UpdateCheckerImpl::OnRequestSenderComplete(const net::URLFetcher* source) { 128 void UpdateCheckerImpl::OnRequestSenderComplete(int error,
129 const std::string& response) {
130 DCHECK(thread_checker_.CalledOnValidThread()); 130 DCHECK(thread_checker_.CalledOnValidThread());
131 131
132 GURL original_url; 132 if (!error) {
133 int error = 0; 133 UpdateResponse update_response;
134 std::string error_message; 134 if (update_response.Parse(response)) {
135 UpdateResponse update_response; 135 base::ThreadTaskRunnerHandle::Get()->PostTask(
136 FROM_HERE,
137 base::Bind(update_check_callback_, error, update_response.results()));
138 return;
139 }
136 140
137 if (source) {
138 original_url = source->GetOriginalURL();
139 VLOG(1) << "Update check request went to: " << original_url.spec();
140 if (FetchSuccess(*source)) {
141 std::string xml;
142 source->GetResponseAsString(&xml);
143 if (!update_response.Parse(xml)) {
144 error = -1;
145 error_message = update_response.errors();
146 }
147 } else {
148 error = GetFetchError(*source);
149 error_message.assign("network error");
150 }
151 } else {
152 error = -1; 141 error = -1;
153 error_message = "no fetcher"; 142 VLOG(1) << "Parse failed " << update_response.errors();
154 } 143 }
155 144
156 if (error) {
157 VLOG(1) << "Update request failed: " << error_message;
158 }
159
160 request_sender_.reset();
161
162 base::ThreadTaskRunnerHandle::Get()->PostTask( 145 base::ThreadTaskRunnerHandle::Get()->PostTask(
163 FROM_HERE, base::Bind(update_check_callback_, original_url, error, 146 FROM_HERE,
164 error_message, update_response.results())); 147 base::Bind(update_check_callback_, error, UpdateResponse::Results()));
165 } 148 }
166 149
167 } // namespace 150 } // namespace
168 151
169 scoped_ptr<UpdateChecker> UpdateChecker::Create( 152 scoped_ptr<UpdateChecker> UpdateChecker::Create(
170 const scoped_refptr<Configurator>& config) { 153 const scoped_refptr<Configurator>& config) {
171 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config)); 154 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config));
172 } 155 }
173 156
174 } // namespace update_client 157 } // 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