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

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

Issue 2237153002: Use consistent values for enabled_component_updates throughout an update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix UT. Created 4 years, 4 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 <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" 65 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc"
66 // version="0.1.2.3" installsource="ondemand"> 66 // version="0.1.2.3" installsource="ondemand">
67 // <updatecheck /> 67 // <updatecheck />
68 // <packages> 68 // <packages>
69 // <package fp="abcd" /> 69 // <package fp="abcd" />
70 // </packages> 70 // </packages>
71 // </app> 71 // </app>
72 std::string BuildUpdateCheckRequest(const Configurator& config, 72 std::string BuildUpdateCheckRequest(const Configurator& config,
73 const std::vector<CrxUpdateItem*>& items, 73 const std::vector<CrxUpdateItem*>& items,
74 PersistedData* metadata, 74 PersistedData* metadata,
75 const std::string& additional_attributes) { 75 const std::string& additional_attributes,
76 bool enabled_component_updates) {
76 const std::string brand(SanitizeBrand(config.GetBrand())); 77 const std::string brand(SanitizeBrand(config.GetBrand()));
77 std::string app_elements; 78 std::string app_elements;
78 for (size_t i = 0; i != items.size(); ++i) { 79 for (size_t i = 0; i != items.size(); ++i) {
79 const CrxUpdateItem* item = items[i]; 80 const CrxUpdateItem* item = items[i];
80 const update_client::InstallerAttributes installer_attributes( 81 const update_client::InstallerAttributes installer_attributes(
81 SanitizeInstallerAttributes(item->component.installer_attributes)); 82 SanitizeInstallerAttributes(item->component.installer_attributes));
82 std::string app("<app "); 83 std::string app("<app ");
83 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(), 84 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(),
84 item->component.version.GetString().c_str()); 85 item->component.version.GetString().c_str());
85 if (!brand.empty()) 86 if (!brand.empty())
86 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str()); 87 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str());
87 if (item->on_demand) 88 if (item->on_demand)
88 base::StringAppendF(&app, " installsource=\"ondemand\""); 89 base::StringAppendF(&app, " installsource=\"ondemand\"");
89 for (const auto& attr : installer_attributes) { 90 for (const auto& attr : installer_attributes) {
90 base::StringAppendF(&app, " %s=\"%s\"", attr.first.c_str(), 91 base::StringAppendF(&app, " %s=\"%s\"", attr.first.c_str(),
91 attr.second.c_str()); 92 attr.second.c_str());
92 } 93 }
93 base::StringAppendF(&app, ">"); 94 base::StringAppendF(&app, ">");
94 95
95 base::StringAppendF(&app, "<updatecheck"); 96 base::StringAppendF(&app, "<updatecheck");
96 if (item->component.supports_group_policy_enable_component_updates && 97 if (item->component.supports_group_policy_enable_component_updates &&
97 !config.EnabledComponentUpdates()) { 98 !enabled_component_updates) {
98 base::StringAppendF(&app, " updatedisabled=\"true\""); 99 base::StringAppendF(&app, " updatedisabled=\"true\"");
99 } 100 }
100 base::StringAppendF(&app, "/>"); 101 base::StringAppendF(&app, "/>");
101 102
102 base::StringAppendF(&app, "<ping rd=\"%d\" ping_freshness=\"%s\" />", 103 base::StringAppendF(&app, "<ping rd=\"%d\" ping_freshness=\"%s\" />",
103 metadata->GetDateLastRollCall(item->id), 104 metadata->GetDateLastRollCall(item->id),
104 metadata->GetPingFreshness(item->id).c_str()); 105 metadata->GetPingFreshness(item->id).c_str());
105 if (!item->component.fingerprint.empty()) { 106 if (!item->component.fingerprint.empty()) {
106 base::StringAppendF(&app, 107 base::StringAppendF(&app,
107 "<packages>" 108 "<packages>"
(...skipping 15 matching lines...) Expand all
123 class UpdateCheckerImpl : public UpdateChecker { 124 class UpdateCheckerImpl : public UpdateChecker {
124 public: 125 public:
125 UpdateCheckerImpl(const scoped_refptr<Configurator>& config, 126 UpdateCheckerImpl(const scoped_refptr<Configurator>& config,
126 PersistedData* metadata); 127 PersistedData* metadata);
127 ~UpdateCheckerImpl() override; 128 ~UpdateCheckerImpl() override;
128 129
129 // Overrides for UpdateChecker. 130 // Overrides for UpdateChecker.
130 bool CheckForUpdates( 131 bool CheckForUpdates(
131 const std::vector<CrxUpdateItem*>& items_to_check, 132 const std::vector<CrxUpdateItem*>& items_to_check,
132 const std::string& additional_attributes, 133 const std::string& additional_attributes,
134 bool enabled_component_updates,
133 const UpdateCheckCallback& update_check_callback) override; 135 const UpdateCheckCallback& update_check_callback) override;
134 136
135 private: 137 private:
136 void OnRequestSenderComplete( 138 void OnRequestSenderComplete(
137 std::unique_ptr<std::vector<std::string>> ids_checked, 139 std::unique_ptr<std::vector<std::string>> ids_checked,
138 int error, 140 int error,
139 const std::string& response, 141 const std::string& response,
140 int retry_after_sec); 142 int retry_after_sec);
141 base::ThreadChecker thread_checker_; 143 base::ThreadChecker thread_checker_;
142 144
143 const scoped_refptr<Configurator> config_; 145 const scoped_refptr<Configurator> config_;
144 PersistedData* metadata_; 146 PersistedData* metadata_;
145 UpdateCheckCallback update_check_callback_; 147 UpdateCheckCallback update_check_callback_;
146 std::unique_ptr<RequestSender> request_sender_; 148 std::unique_ptr<RequestSender> request_sender_;
147 149
148 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); 150 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl);
149 }; 151 };
150 152
151 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config, 153 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config,
152 PersistedData* metadata) 154 PersistedData* metadata)
153 : config_(config), metadata_(metadata) {} 155 : config_(config), metadata_(metadata) {}
154 156
155 UpdateCheckerImpl::~UpdateCheckerImpl() { 157 UpdateCheckerImpl::~UpdateCheckerImpl() {
156 DCHECK(thread_checker_.CalledOnValidThread()); 158 DCHECK(thread_checker_.CalledOnValidThread());
157 } 159 }
158 160
159 bool UpdateCheckerImpl::CheckForUpdates( 161 bool UpdateCheckerImpl::CheckForUpdates(
160 const std::vector<CrxUpdateItem*>& items_to_check, 162 const std::vector<CrxUpdateItem*>& items_to_check,
161 const std::string& additional_attributes, 163 const std::string& additional_attributes,
164 bool enabled_component_updates,
162 const UpdateCheckCallback& update_check_callback) { 165 const UpdateCheckCallback& update_check_callback) {
163 DCHECK(thread_checker_.CalledOnValidThread()); 166 DCHECK(thread_checker_.CalledOnValidThread());
164 167
165 if (request_sender_.get()) { 168 if (request_sender_.get()) {
166 NOTREACHED(); 169 NOTREACHED();
167 return false; // Another update check is in progress. 170 return false; // Another update check is in progress.
168 } 171 }
169 172
170 update_check_callback_ = update_check_callback; 173 update_check_callback_ = update_check_callback;
171 174
172 auto urls(config_->UpdateUrl()); 175 auto urls(config_->UpdateUrl());
173 if (IsEncryptionRequired(items_to_check)) 176 if (IsEncryptionRequired(items_to_check))
174 RemoveUnsecureUrls(&urls); 177 RemoveUnsecureUrls(&urls);
175 178
176 std::unique_ptr<std::vector<std::string>> ids_checked( 179 std::unique_ptr<std::vector<std::string>> ids_checked(
177 new std::vector<std::string>()); 180 new std::vector<std::string>());
178 for (auto* crx : items_to_check) 181 for (auto* crx : items_to_check)
179 ids_checked->push_back(crx->id); 182 ids_checked->push_back(crx->id);
180 request_sender_.reset(new RequestSender(config_)); 183 request_sender_.reset(new RequestSender(config_));
181 request_sender_->Send( 184 request_sender_->Send(
182 config_->EnabledCupSigning(), 185 config_->EnabledCupSigning(),
183 BuildUpdateCheckRequest(*config_, items_to_check, metadata_, 186 BuildUpdateCheckRequest(*config_, items_to_check, metadata_,
184 additional_attributes), 187 additional_attributes, enabled_component_updates),
185 urls, base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete, 188 urls, base::Bind(&UpdateCheckerImpl::OnRequestSenderComplete,
186 base::Unretained(this), base::Passed(&ids_checked))); 189 base::Unretained(this), base::Passed(&ids_checked)));
187 return true; 190 return true;
188 } 191 }
189 192
190 void UpdateCheckerImpl::OnRequestSenderComplete( 193 void UpdateCheckerImpl::OnRequestSenderComplete(
191 std::unique_ptr<std::vector<std::string>> ids_checked, 194 std::unique_ptr<std::vector<std::string>> ids_checked,
192 int error, 195 int error,
193 const std::string& response, 196 const std::string& response,
194 int retry_after_sec) { 197 int retry_after_sec) {
(...skipping 23 matching lines...) Expand all
218 } // namespace 221 } // namespace
219 222
220 std::unique_ptr<UpdateChecker> UpdateChecker::Create( 223 std::unique_ptr<UpdateChecker> UpdateChecker::Create(
221 const scoped_refptr<Configurator>& config, 224 const scoped_refptr<Configurator>& config,
222 PersistedData* persistent) { 225 PersistedData* persistent) {
223 return std::unique_ptr<UpdateChecker>( 226 return std::unique_ptr<UpdateChecker>(
224 new UpdateCheckerImpl(config, persistent)); 227 new UpdateCheckerImpl(config, persistent));
225 } 228 }
226 229
227 } // namespace update_client 230 } // 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