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

Side by Side Diff: omaha_request_action.cc

Issue 6836025: Add support to update_engine to poke Omaha after an update has been applied (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: Fixed bug where last ping day was not properly updated Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 "update_engine/omaha_request_action.h" 5 #include "update_engine/omaha_request_action.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 76 }
77 return ""; 77 return "";
78 } 78 }
79 79
80 // Returns an XML ping element if any of the elapsed days need to be 80 // Returns an XML ping element if any of the elapsed days need to be
81 // sent, or an empty string otherwise. 81 // sent, or an empty string otherwise.
82 string GetPingBody(int ping_active_days, int ping_roll_call_days) { 82 string GetPingBody(int ping_active_days, int ping_roll_call_days) {
83 string ping_active = GetPingAttribute("a", ping_active_days); 83 string ping_active = GetPingAttribute("a", ping_active_days);
84 string ping_roll_call = GetPingAttribute("r", ping_roll_call_days); 84 string ping_roll_call = GetPingAttribute("r", ping_roll_call_days);
85 if (!ping_active.empty() || !ping_roll_call.empty()) { 85 if (!ping_active.empty() || !ping_roll_call.empty()) {
86 return StringPrintf(" <o:ping%s%s></o:ping>\n", 86 return StringPrintf(" <o:ping active=\"1\"%s%s></o:ping>\n",
87 ping_active.c_str(), 87 ping_active.c_str(),
88 ping_roll_call.c_str()); 88 ping_roll_call.c_str());
89 } 89 }
90 return ""; 90 return "";
91 } 91 }
92 92
93 string FormatRequest(const OmahaEvent* event, 93 string FormatRequest(const OmahaEvent* event,
94 const OmahaRequestParams& params, 94 const OmahaRequestParams& params,
95 bool ping_only,
95 int ping_active_days, 96 int ping_active_days,
96 int ping_roll_call_days, 97 int ping_roll_call_days,
97 PrefsInterface* prefs) { 98 PrefsInterface* prefs) {
98 string body; 99 string body;
99 if (event == NULL) { 100 if (event == NULL) {
100 body = GetPingBody(ping_active_days, ping_roll_call_days) + 101 body = GetPingBody(ping_active_days, ping_roll_call_days);
101 " <o:updatecheck></o:updatecheck>\n"; 102 if (!ping_only)
103 body += " <o:updatecheck></o:updatecheck>\n";
102 // If this is the first update check after a reboot following a previous 104 // If this is the first update check after a reboot following a previous
103 // update, generate an event containing the previous version number. If the 105 // update, generate an event containing the previous version number. If the
104 // previous version preference file doesn't exist the event is still 106 // previous version preference file doesn't exist the event is still
105 // generated with a previous version of 0.0.0.0 -- this is relevant for 107 // generated with a previous version of 0.0.0.0 -- this is relevant for
106 // older clients or new installs. 108 // older clients or new installs.
107 string prev_version; 109 string prev_version;
108 if (!prefs->GetString(kPrefsPreviousVersion, &prev_version)) { 110 if (!prefs->GetString(kPrefsPreviousVersion, &prev_version)) {
109 prev_version = "0.0.0.0"; 111 prev_version = "0.0.0.0";
110 } 112 }
111 if (!prev_version.empty()) { 113 if (!prev_version.empty()) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 // return ""; 168 // return "";
167 // } 169 // }
168 scoped_ptr_malloc<xmlChar, ScopedPtrXmlFree> str( 170 scoped_ptr_malloc<xmlChar, ScopedPtrXmlFree> str(
169 xmlEncodeEntitiesReentrant(NULL, ConstXMLStr(input.c_str()))); 171 xmlEncodeEntitiesReentrant(NULL, ConstXMLStr(input.c_str())));
170 return string(reinterpret_cast<const char *>(str.get())); 172 return string(reinterpret_cast<const char *>(str.get()));
171 } 173 }
172 174
173 OmahaRequestAction::OmahaRequestAction(PrefsInterface* prefs, 175 OmahaRequestAction::OmahaRequestAction(PrefsInterface* prefs,
174 const OmahaRequestParams& params, 176 const OmahaRequestParams& params,
175 OmahaEvent* event, 177 OmahaEvent* event,
176 HttpFetcher* http_fetcher) 178 HttpFetcher* http_fetcher,
179 bool ping_only)
177 : prefs_(prefs), 180 : prefs_(prefs),
178 params_(params), 181 params_(params),
179 event_(event), 182 event_(event),
180 http_fetcher_(http_fetcher), 183 http_fetcher_(http_fetcher),
184 ping_only_(ping_only),
181 ping_active_days_(0), 185 ping_active_days_(0),
182 ping_roll_call_days_(0), 186 ping_roll_call_days_(0),
183 should_skip_(false) {} 187 should_skip_(false) {}
184 188
185 OmahaRequestAction::~OmahaRequestAction() {} 189 OmahaRequestAction::~OmahaRequestAction() {}
186 190
187 // Calculates the value to use for the ping days parameter. 191 // Calculates the value to use for the ping days parameter.
188 int OmahaRequestAction::CalculatePingDays(const string& key) { 192 int OmahaRequestAction::CalculatePingDays(const string& key) {
189 int days = kNeverPinged; 193 int days = kNeverPinged;
190 int64_t last_ping = 0; 194 int64_t last_ping = 0;
(...skipping 27 matching lines...) Expand all
218 222
219 void OmahaRequestAction::PerformAction() { 223 void OmahaRequestAction::PerformAction() {
220 if (should_skip_) { 224 if (should_skip_) {
221 processor_->ActionComplete(this, kActionCodeSuccess); 225 processor_->ActionComplete(this, kActionCodeSuccess);
222 return; 226 return;
223 } 227 }
224 http_fetcher_->set_delegate(this); 228 http_fetcher_->set_delegate(this);
225 InitPingDays(); 229 InitPingDays();
226 string request_post(FormatRequest(event_.get(), 230 string request_post(FormatRequest(event_.get(),
227 params_, 231 params_,
232 ping_only_,
228 ping_active_days_, 233 ping_active_days_,
229 ping_roll_call_days_, 234 ping_roll_call_days_,
230 prefs_)); 235 prefs_));
231 http_fetcher_->SetPostData(request_post.data(), request_post.size()); 236 http_fetcher_->SetPostData(request_post.data(), request_post.size());
232 LOG(INFO) << "Posting an Omaha request to " << params_.update_url; 237 LOG(INFO) << "Posting an Omaha request to " << params_.update_url;
233 LOG(INFO) << "Request: " << request_post; 238 LOG(INFO) << "Request: " << request_post;
234 http_fetcher_->BeginTransfer(params_.update_url); 239 http_fetcher_->BeginTransfer(params_.update_url);
235 } 240 }
236 241
237 void OmahaRequestAction::TerminateProcessing() { 242 void OmahaRequestAction::TerminateProcessing() {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 LOG(ERROR) << "Omaha request network transfer failed."; 371 LOG(ERROR) << "Omaha request network transfer failed.";
367 int code = GetHTTPResponseCode(); 372 int code = GetHTTPResponseCode();
368 // Makes sure we send sane error values. 373 // Makes sure we send sane error values.
369 if (code < 0 || code >= 1000) { 374 if (code < 0 || code >= 1000) {
370 code = 999; 375 code = 999;
371 } 376 }
372 completer.set_code(static_cast<ActionExitCode>( 377 completer.set_code(static_cast<ActionExitCode>(
373 kActionCodeOmahaRequestHTTPResponseBase + code)); 378 kActionCodeOmahaRequestHTTPResponseBase + code));
374 return; 379 return;
375 } 380 }
376 if (!HasOutputPipe()) {
377 // Just set success to whether or not the http transfer succeeded,
378 // which must be true at this point in the code.
379 completer.set_code(kActionCodeSuccess);
380 return;
381 }
382 381
383 // parse our response and fill the fields in the output object 382 // parse our response and fill the fields in the output object
384 scoped_ptr_malloc<xmlDoc, ScopedPtrXmlDocFree> doc( 383 scoped_ptr_malloc<xmlDoc, ScopedPtrXmlDocFree> doc(
385 xmlParseMemory(&response_buffer_[0], response_buffer_.size())); 384 xmlParseMemory(&response_buffer_[0], response_buffer_.size()));
386 if (!doc.get()) { 385 if (!doc.get()) {
387 LOG(ERROR) << "Omaha response not valid XML"; 386 LOG(ERROR) << "Omaha response not valid XML";
388 completer.set_code(response_buffer_.empty() ? 387 completer.set_code(response_buffer_.empty() ?
389 kActionCodeOmahaRequestEmptyResponseError : 388 kActionCodeOmahaRequestEmptyResponseError :
390 kActionCodeOmahaRequestXMLParseError); 389 kActionCodeOmahaRequestXMLParseError);
391 return; 390 return;
392 } 391 }
393 392
394 // If a ping was sent, update the last ping day preferences based on 393 // If a ping was sent, update the last ping day preferences based on
395 // the server daystart response. 394 // the server daystart response.
396 if (ShouldPing(ping_active_days_) || 395 if (ShouldPing(ping_active_days_) ||
397 ShouldPing(ping_roll_call_days_) || 396 ShouldPing(ping_roll_call_days_) ||
398 ping_active_days_ == kPingTimeJump || 397 ping_active_days_ == kPingTimeJump ||
399 ping_roll_call_days_ == kPingTimeJump) { 398 ping_roll_call_days_ == kPingTimeJump) {
400 LOG_IF(ERROR, !UpdateLastPingDays(doc.get(), prefs_)) 399 LOG_IF(ERROR, !UpdateLastPingDays(doc.get(), prefs_))
401 << "Failed to update the last ping day preferences!"; 400 << "Failed to update the last ping day preferences!";
402 } 401 }
403 402
403 if (!HasOutputPipe()) {
404 // Just set success to whether or not the http transfer succeeded,
405 // which must be true at this point in the code.
406 completer.set_code(kActionCodeSuccess);
407 return;
408 }
409
404 static const char* kNamespace("x"); 410 static const char* kNamespace("x");
405 static const char* kUpdatecheckNodeXpath("/x:gupdate/x:app/x:updatecheck"); 411 static const char* kUpdatecheckNodeXpath("/x:gupdate/x:app/x:updatecheck");
406 static const char* kNsUrl("http://www.google.com/update2/response"); 412 static const char* kNsUrl("http://www.google.com/update2/response");
407 413
408 scoped_ptr_malloc<xmlXPathObject, ScopedPtrXmlXPathObjectFree> 414 scoped_ptr_malloc<xmlXPathObject, ScopedPtrXmlXPathObjectFree>
409 xpath_nodeset(GetNodeSet(doc.get(), 415 xpath_nodeset(GetNodeSet(doc.get(),
410 ConstXMLStr(kUpdatecheckNodeXpath), 416 ConstXMLStr(kUpdatecheckNodeXpath),
411 ConstXMLStr(kNamespace), 417 ConstXMLStr(kNamespace),
412 ConstXMLStr(kNsUrl))); 418 ConstXMLStr(kNsUrl)));
413 if (!xpath_nodeset.get()) { 419 if (!xpath_nodeset.get()) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 output_object.needs_admin = 464 output_object.needs_admin =
459 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; 465 XmlGetProperty(updatecheck_node, "needsadmin") == "true";
460 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; 466 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true";
461 output_object.is_delta = 467 output_object.is_delta =
462 XmlGetProperty(updatecheck_node, "IsDelta") == "true"; 468 XmlGetProperty(updatecheck_node, "IsDelta") == "true";
463 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline"); 469 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline");
464 SetOutputObject(output_object); 470 SetOutputObject(output_object);
465 } 471 }
466 472
467 }; // namespace chromeos_update_engine 473 }; // namespace chromeos_update_engine
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698