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

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

Issue 1899043002: Implement ping_freshness for update_client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // An app element looks like this: 57 // An app element looks like this:
58 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc" 58 // <app appid="hnimpnehoodheedghdeeijklkeaacbdc"
59 // version="0.1.2.3" installsource="ondemand"> 59 // version="0.1.2.3" installsource="ondemand">
60 // <updatecheck /> 60 // <updatecheck />
61 // <packages> 61 // <packages>
62 // <package fp="abcd" /> 62 // <package fp="abcd" />
63 // </packages> 63 // </packages>
64 // </app> 64 // </app>
65 std::string BuildUpdateCheckRequest(const Configurator& config, 65 std::string BuildUpdateCheckRequest(const Configurator& config,
66 const std::vector<CrxUpdateItem*>& items, 66 const std::vector<CrxUpdateItem*>& items,
67 const PersistedData& metadata, 67 PersistedData* metadata,
68 const std::string& additional_attributes) { 68 const std::string& additional_attributes) {
69 const std::string brand(SanitizeBrand(config.GetBrand())); 69 const std::string brand(SanitizeBrand(config.GetBrand()));
70 std::string app_elements; 70 std::string app_elements;
71 for (size_t i = 0; i != items.size(); ++i) { 71 for (size_t i = 0; i != items.size(); ++i) {
72 const CrxUpdateItem* item = items[i]; 72 const CrxUpdateItem* item = items[i];
73 const std::string ap(SanitizeAp(item->component.ap)); 73 const std::string ap(SanitizeAp(item->component.ap));
74 std::string app("<app "); 74 std::string app("<app ");
75 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(), 75 base::StringAppendF(&app, "appid=\"%s\" version=\"%s\"", item->id.c_str(),
76 item->component.version.GetString().c_str()); 76 item->component.version.GetString().c_str());
77 if (!brand.empty()) 77 if (!brand.empty())
78 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str()); 78 base::StringAppendF(&app, " brand=\"%s\"", brand.c_str());
79 if (item->on_demand) 79 if (item->on_demand)
80 base::StringAppendF(&app, " installsource=\"ondemand\""); 80 base::StringAppendF(&app, " installsource=\"ondemand\"");
81 if (!ap.empty()) 81 if (!ap.empty())
82 base::StringAppendF(&app, " ap=\"%s\"", ap.c_str()); 82 base::StringAppendF(&app, " ap=\"%s\"", ap.c_str());
83 base::StringAppendF(&app, ">"); 83 base::StringAppendF(&app, ">");
84 base::StringAppendF(&app, "<updatecheck />"); 84 base::StringAppendF(&app, "<updatecheck />");
85 base::StringAppendF(&app, "<ping rd=\"%d\" />", 85 base::StringAppendF(&app, "<ping rd=\"%d\" ping_freshness=\"%s\" />",
86 metadata.GetDateLastRollCall(item->id)); 86 metadata->GetDateLastRollCall(item->id),
87 metadata->GetPingFreshness(item->id).c_str());
87 if (!item->component.fingerprint.empty()) { 88 if (!item->component.fingerprint.empty()) {
88 base::StringAppendF(&app, 89 base::StringAppendF(&app,
89 "<packages>" 90 "<packages>"
90 "<package fp=\"%s\"/>" 91 "<package fp=\"%s\"/>"
91 "</packages>", 92 "</packages>",
92 item->component.fingerprint.c_str()); 93 item->component.fingerprint.c_str());
93 } 94 }
94 base::StringAppendF(&app, "</app>"); 95 base::StringAppendF(&app, "</app>");
95 app_elements.append(app); 96 app_elements.append(app);
96 VLOG(1) << "Appending to update request: " << app; 97 VLOG(1) << "Appending to update request: " << app;
97 } 98 }
98 99
99 return BuildProtocolRequest( 100 return BuildProtocolRequest(
100 config.GetBrowserVersion().GetString(), config.GetChannel(), 101 config.GetBrowserVersion().GetString(), config.GetChannel(),
101 config.GetLang(), config.GetOSLongName(), config.GetDownloadPreference(), 102 config.GetLang(), config.GetOSLongName(), config.GetDownloadPreference(),
102 app_elements, additional_attributes); 103 app_elements, additional_attributes);
103 } 104 }
104 105
105 class UpdateCheckerImpl : public UpdateChecker { 106 class UpdateCheckerImpl : public UpdateChecker {
106 public: 107 public:
107 UpdateCheckerImpl(const scoped_refptr<Configurator>& config, 108 UpdateCheckerImpl(const scoped_refptr<Configurator>& config,
108 const PersistedData& metadata); 109 PersistedData* metadata);
109 ~UpdateCheckerImpl() override; 110 ~UpdateCheckerImpl() override;
110 111
111 // Overrides for UpdateChecker. 112 // Overrides for UpdateChecker.
112 bool CheckForUpdates( 113 bool CheckForUpdates(
113 const std::vector<CrxUpdateItem*>& items_to_check, 114 const std::vector<CrxUpdateItem*>& items_to_check,
114 const std::string& additional_attributes, 115 const std::string& additional_attributes,
115 const UpdateCheckCallback& update_check_callback) override; 116 const UpdateCheckCallback& update_check_callback) override;
116 117
117 private: 118 private:
118 void OnRequestSenderComplete(scoped_ptr<std::vector<std::string>> ids_checked, 119 void OnRequestSenderComplete(scoped_ptr<std::vector<std::string>> ids_checked,
119 int error, 120 int error,
120 const std::string& response, 121 const std::string& response,
121 int retry_after_sec); 122 int retry_after_sec);
122 base::ThreadChecker thread_checker_; 123 base::ThreadChecker thread_checker_;
123 124
124 const scoped_refptr<Configurator> config_; 125 const scoped_refptr<Configurator> config_;
125 const PersistedData& metadata_; 126 PersistedData* metadata_;
126 UpdateCheckCallback update_check_callback_; 127 UpdateCheckCallback update_check_callback_;
127 scoped_ptr<RequestSender> request_sender_; 128 scoped_ptr<RequestSender> request_sender_;
128 129
129 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl); 130 DISALLOW_COPY_AND_ASSIGN(UpdateCheckerImpl);
130 }; 131 };
131 132
132 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config, 133 UpdateCheckerImpl::UpdateCheckerImpl(const scoped_refptr<Configurator>& config,
133 const PersistedData& metadata) 134 PersistedData* metadata)
134 : config_(config), metadata_(metadata) {} 135 : config_(config), metadata_(metadata) {}
135 136
136 UpdateCheckerImpl::~UpdateCheckerImpl() { 137 UpdateCheckerImpl::~UpdateCheckerImpl() {
137 DCHECK(thread_checker_.CalledOnValidThread()); 138 DCHECK(thread_checker_.CalledOnValidThread());
138 } 139 }
139 140
140 bool UpdateCheckerImpl::CheckForUpdates( 141 bool UpdateCheckerImpl::CheckForUpdates(
141 const std::vector<CrxUpdateItem*>& items_to_check, 142 const std::vector<CrxUpdateItem*>& items_to_check,
142 const std::string& additional_attributes, 143 const std::string& additional_attributes,
143 const UpdateCheckCallback& update_check_callback) { 144 const UpdateCheckCallback& update_check_callback) {
(...skipping 29 matching lines...) Expand all
173 int error, 174 int error,
174 const std::string& response, 175 const std::string& response,
175 int retry_after_sec) { 176 int retry_after_sec) {
176 DCHECK(thread_checker_.CalledOnValidThread()); 177 DCHECK(thread_checker_.CalledOnValidThread());
177 178
178 if (!error) { 179 if (!error) {
179 UpdateResponse update_response; 180 UpdateResponse update_response;
180 if (update_response.Parse(response)) { 181 if (update_response.Parse(response)) {
181 int daynum = update_response.results().daystart_elapsed_days; 182 int daynum = update_response.results().daystart_elapsed_days;
182 if (daynum != UpdateResponse::kNoDaystart) 183 if (daynum != UpdateResponse::kNoDaystart)
183 metadata_.SetDateLastRollCall(*ids_checked, daynum); 184 metadata_->SetDateLastRollCall(*ids_checked, daynum);
184 base::ThreadTaskRunnerHandle::Get()->PostTask( 185 base::ThreadTaskRunnerHandle::Get()->PostTask(
185 FROM_HERE, base::Bind(update_check_callback_, error, 186 FROM_HERE, base::Bind(update_check_callback_, error,
186 update_response.results(), retry_after_sec)); 187 update_response.results(), retry_after_sec));
187 return; 188 return;
188 } 189 }
189 190
190 error = -1; 191 error = -1;
191 VLOG(1) << "Parse failed " << update_response.errors(); 192 VLOG(1) << "Parse failed " << update_response.errors();
192 } 193 }
193 194
194 base::ThreadTaskRunnerHandle::Get()->PostTask( 195 base::ThreadTaskRunnerHandle::Get()->PostTask(
195 FROM_HERE, base::Bind(update_check_callback_, error, 196 FROM_HERE, base::Bind(update_check_callback_, error,
196 UpdateResponse::Results(), retry_after_sec)); 197 UpdateResponse::Results(), retry_after_sec));
197 } 198 }
198 199
199 } // namespace 200 } // namespace
200 201
201 scoped_ptr<UpdateChecker> UpdateChecker::Create( 202 scoped_ptr<UpdateChecker> UpdateChecker::Create(
202 const scoped_refptr<Configurator>& config, 203 const scoped_refptr<Configurator>& config,
203 const PersistedData& persistent) { 204 PersistedData* persistent) {
204 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config, persistent)); 205 return scoped_ptr<UpdateChecker>(new UpdateCheckerImpl(config, persistent));
205 } 206 }
206 207
207 } // namespace update_client 208 } // 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