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

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

Issue 565363002: Implement support for fallback update check urls in the component updater (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Created 6 years, 3 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/component_updater/update_checker.h" 5 #include "components/component_updater/update_checker.h"
6 6
7 #include <string>
8 #include <vector>
9
7 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/location.h"
8 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
10 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
11 #include "components/component_updater/component_updater_configurator.h" 16 #include "components/component_updater/component_updater_configurator.h"
12 #include "components/component_updater/component_updater_utils.h" 17 #include "components/component_updater/component_updater_utils.h"
13 #include "components/component_updater/crx_update_item.h" 18 #include "components/component_updater/crx_update_item.h"
19 #include "components/component_updater/request_sender.h"
14 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
15 #include "net/url_request/url_fetcher_delegate.h"
16 #include "url/gurl.h" 21 #include "url/gurl.h"
17 22
18 namespace component_updater { 23 namespace component_updater {
19 24
25 namespace {
26
20 // Builds an update check request for |components|. |additional_attributes| is 27 // Builds an update check request for |components|. |additional_attributes| is
21 // serialized as part of the <request> element of the request to customize it 28 // serialized as part of the <request> element of the request to customize it
22 // with data that is not platform or component specific. For each |item|, a 29 // with data that is not platform or component specific. For each |item|, a
23 // corresponding <app> element is created and inserted as a child node of 30 // corresponding <app> element is created and inserted as a child node of
24 // the <request>. 31 // the <request>.
25 // 32 //
26 // An app element looks like this: 33 // An app element looks like this:
27 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" 34 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc"
28 // version="0.1.2.3" installsource="ondemand"> 35 // version="0.1.2.3" installsource="ondemand">
29 // <updatecheck /> 36 // <updatecheck />
(...skipping 29 matching lines...) Expand all
59 } 66 }
60 67
61 return BuildProtocolRequest(config.GetBrowserVersion().GetString(), 68 return BuildProtocolRequest(config.GetBrowserVersion().GetString(),
62 config.GetChannel(), 69 config.GetChannel(),
63 config.GetLang(), 70 config.GetLang(),
64 config.GetOSLongName(), 71 config.GetOSLongName(),
65 app_elements, 72 app_elements,
66 additional_attributes); 73 additional_attributes);
67 } 74 }
68 75
69 class UpdateCheckerImpl : public UpdateChecker, public net::URLFetcherDelegate { 76 class UpdateCheckerImpl : public UpdateChecker {
70 public: 77 public:
71 UpdateCheckerImpl(const Configurator& config, 78 explicit UpdateCheckerImpl(const Configurator& config);
72 const UpdateCheckCallback& update_check_callback);
73 virtual ~UpdateCheckerImpl(); 79 virtual ~UpdateCheckerImpl();
74 80
75 // Overrides for UpdateChecker. 81 // Overrides for UpdateChecker.
76 virtual bool CheckForUpdates( 82 virtual bool CheckForUpdates(
77 const std::vector<CrxUpdateItem*>& items_to_check, 83 const std::vector<CrxUpdateItem*>& items_to_check,
78 const std::string& additional_attributes) OVERRIDE; 84 const std::string& additional_attributes,
79 85 const UpdateCheckCallback& update_check_callback) OVERRIDE;
80 // Overrides for UrlFetcher.
81 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
82 86
83 private: 87 private:
88 void OnRequestSenderComplete(const net::URLFetcher* source);
89
84 const Configurator& config_; 90 const Configurator& config_;
85 const UpdateCheckCallback update_check_callback_; 91 UpdateCheckCallback update_check_callback_;
86 92 scoped_ptr<RequestSender> request_sender_;
87 scoped_ptr<net::URLFetcher> url_fetcher_;
88 93
89 base::ThreadChecker thread_checker_; 94 base::ThreadChecker thread_checker_;
90 95
91 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); 96 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl);
92 }; 97 };
93 98
94 scoped_ptr<UpdateChecker> UpdateChecker::Create( 99 UpdateCheckerImpl::UpdateCheckerImpl(const Configurator& config)
95 const Configurator& config, 100 : config_(config) {
96 const UpdateCheckCallback& update_check_callback) {
97 scoped_ptr<UpdateCheckerImpl> update_checker(
98 new UpdateCheckerImpl(config, update_check_callback));
99 return update_checker.PassAs<UpdateChecker>();
100 }
101
102 UpdateCheckerImpl::UpdateCheckerImpl(
103 const Configurator& config,
104 const UpdateCheckCallback& update_check_callback)
105 : config_(config), update_check_callback_(update_check_callback) {
106 } 101 }
107 102
108 UpdateCheckerImpl::~UpdateCheckerImpl() { 103 UpdateCheckerImpl::~UpdateCheckerImpl() {
109 DCHECK(thread_checker_.CalledOnValidThread()); 104 DCHECK(thread_checker_.CalledOnValidThread());
110 } 105 }
111 106
112 bool UpdateCheckerImpl::CheckForUpdates( 107 bool UpdateCheckerImpl::CheckForUpdates(
113 const std::vector<CrxUpdateItem*>& items_to_check, 108 const std::vector<CrxUpdateItem*>& items_to_check,
114 const std::string& additional_attributes) { 109 const std::string& additional_attributes,
110 const UpdateCheckCallback& update_check_callback) {
115 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
116 112
117 if (url_fetcher_) 113 if (request_sender_.get()) {
118 return false; // Another fetch is in progress. 114 NOTREACHED();
115 return false; // Another update check is in progress.
116 }
119 117
120 url_fetcher_.reset(SendProtocolRequest( 118 update_check_callback_ = update_check_callback;
119
120 request_sender_.reset(new RequestSender(config_));
121 request_sender_->Send(
122 BuildUpdateCheckRequest(config_, items_to_check, additional_attributes),
121 config_.UpdateUrl(), 123 config_.UpdateUrl(),
122 BuildUpdateCheckRequest(config_, items_to_check, additional_attributes), 124 base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete,
123 this, 125 base::Unretained(this)));
124 config_.RequestContext()));
125
126 return true; 126 return true;
127 } 127 }
128 128
129 void UpdateCheckerImpl::OnURLFetchComplete(const net::URLFetcher* source) { 129 void UpdateCheckerImpl::OnRequestSenderComplete(const net::URLFetcher* source) {
130 DCHECK(thread_checker_.CalledOnValidThread()); 130 DCHECK(thread_checker_.CalledOnValidThread());
131 DCHECK(url_fetcher_.get() == source); 131
132 const GURL original_url(source->GetOriginalURL());
133 VLOG(1) << "Update check request went to: " << original_url.spec();
132 134
133 int error = 0; 135 int error = 0;
134 std::string error_message; 136 std::string error_message;
135 UpdateResponse update_response; 137 UpdateResponse update_response;
136 138
137 if (FetchSuccess(*source)) { 139 if (FetchSuccess(*source)) {
138 std::string xml; 140 std::string xml;
139 source->GetResponseAsString(&xml); 141 source->GetResponseAsString(&xml);
140 if (!update_response.Parse(xml)) { 142 if (!update_response.Parse(xml)) {
141 error = -1; 143 error = -1;
142 error_message = update_response.errors(); 144 error_message = update_response.errors();
143 VLOG(1) << "Update request failed: " << error_message; 145 VLOG(1) << "Update request failed: " << error_message;
144 } 146 }
145 } else { 147 } else {
146 error = GetFetchError(*source); 148 error = GetFetchError(*source);
147 error_message.assign("network error"); 149 error_message.assign("network error");
148 VLOG(1) << "Update request failed: network error"; 150 VLOG(1) << "Update request failed: network error";
149 } 151 }
150 152
151 url_fetcher_.reset(); 153 request_sender_.reset();
152 update_check_callback_.Run(error, error_message, update_response.results()); 154 update_check_callback_.Run(
155 original_url, error, error_message, update_response.results());
156 }
157
158 } // namespace
159
160 scoped_ptr<UpdateChecker> UpdateChecker::Create(const Configurator& config) {
161 scoped_ptr<UpdateCheckerImpl> update_checker(new UpdateCheckerImpl(config));
erikwright (departed) 2014/09/15 18:37:11 Replace these two lines with: return scoped_ptr<U
Sorin Jianu 2014/09/15 22:17:58 Done.
162 return update_checker.PassAs<UpdateChecker>();
153 } 163 }
154 164
155 } // namespace component_updater 165 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698