OLD | NEW |
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 return StringPrintf(" <o:ping%s%s></o:ping>\n", | 86 return StringPrintf(" <o:ping%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 int ping_active_days, | 95 int ping_active_days, |
96 int ping_roll_call_days) { | 96 int ping_roll_call_days, |
| 97 PrefsInterface* prefs) { |
97 string body; | 98 string body; |
98 if (event == NULL) { | 99 if (event == NULL) { |
99 body = GetPingBody(ping_active_days, ping_roll_call_days) + | 100 body = GetPingBody(ping_active_days, ping_roll_call_days) + |
100 " <o:updatecheck></o:updatecheck>\n"; | 101 " <o:updatecheck></o:updatecheck>\n"; |
| 102 // 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 |
| 104 // 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 |
| 106 // older clients or new installs. |
| 107 string prev_version; |
| 108 if (!prefs->GetString(kPrefsPreviousVersion, &prev_version)) { |
| 109 prev_version = "0.0.0.0"; |
| 110 } |
| 111 if (!prev_version.empty()) { |
| 112 body += StringPrintf( |
| 113 " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 114 "previousversion=\"%s\"></o:event>\n", |
| 115 OmahaEvent::kTypeUpdateComplete, |
| 116 OmahaEvent::kResultSuccessReboot, |
| 117 prev_version.c_str()); |
| 118 LOG_IF(WARNING, !prefs->SetString(kPrefsPreviousVersion, "")) |
| 119 << "Unable to reset the previous version."; |
| 120 } |
101 } else { | 121 } else { |
102 // The error code is an optional attribute so append it only if | 122 // The error code is an optional attribute so append it only if |
103 // the result is not success. | 123 // the result is not success. |
104 string error_code; | 124 string error_code; |
105 if (event->result != OmahaEvent::kResultSuccess) { | 125 if (event->result != OmahaEvent::kResultSuccess) { |
106 error_code = StringPrintf(" errorcode=\"%d\"", event->error_code); | 126 error_code = StringPrintf(" errorcode=\"%d\"", event->error_code); |
107 } | 127 } |
108 body = StringPrintf( | 128 body = StringPrintf( |
109 " <o:event eventtype=\"%d\" eventresult=\"%d\"%s></o:event>\n", | 129 " <o:event eventtype=\"%d\" eventresult=\"%d\"%s></o:event>\n", |
110 event->type, event->result, error_code.c_str()); | 130 event->type, event->result, error_code.c_str()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 ping_active_days_ = CalculatePingDays(kPrefsLastActivePingDay); | 210 ping_active_days_ = CalculatePingDays(kPrefsLastActivePingDay); |
191 ping_roll_call_days_ = CalculatePingDays(kPrefsLastRollCallPingDay); | 211 ping_roll_call_days_ = CalculatePingDays(kPrefsLastRollCallPingDay); |
192 } | 212 } |
193 | 213 |
194 void OmahaRequestAction::PerformAction() { | 214 void OmahaRequestAction::PerformAction() { |
195 http_fetcher_->set_delegate(this); | 215 http_fetcher_->set_delegate(this); |
196 InitPingDays(); | 216 InitPingDays(); |
197 string request_post(FormatRequest(event_.get(), | 217 string request_post(FormatRequest(event_.get(), |
198 params_, | 218 params_, |
199 ping_active_days_, | 219 ping_active_days_, |
200 ping_roll_call_days_)); | 220 ping_roll_call_days_, |
| 221 prefs_)); |
201 http_fetcher_->SetPostData(request_post.data(), request_post.size()); | 222 http_fetcher_->SetPostData(request_post.data(), request_post.size()); |
202 LOG(INFO) << "Posting an Omaha request to " << params_.update_url; | 223 LOG(INFO) << "Posting an Omaha request to " << params_.update_url; |
203 LOG(INFO) << "Request: " << request_post; | 224 LOG(INFO) << "Request: " << request_post; |
204 http_fetcher_->BeginTransfer(params_.update_url); | 225 http_fetcher_->BeginTransfer(params_.update_url); |
205 } | 226 } |
206 | 227 |
207 void OmahaRequestAction::TerminateProcessing() { | 228 void OmahaRequestAction::TerminateProcessing() { |
208 http_fetcher_->TerminateTransfer(); | 229 http_fetcher_->TerminateTransfer(); |
209 } | 230 } |
210 | 231 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 output_object.needs_admin = | 444 output_object.needs_admin = |
424 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; | 445 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; |
425 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; | 446 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; |
426 output_object.is_delta = | 447 output_object.is_delta = |
427 XmlGetProperty(updatecheck_node, "IsDelta") == "true"; | 448 XmlGetProperty(updatecheck_node, "IsDelta") == "true"; |
428 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline"); | 449 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline"); |
429 SetOutputObject(output_object); | 450 SetOutputObject(output_object); |
430 } | 451 } |
431 | 452 |
432 }; // namespace chromeos_update_engine | 453 }; // namespace chromeos_update_engine |
OLD | NEW |