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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 output_object.needs_admin = | 463 output_object.needs_admin = |
459 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; | 464 XmlGetProperty(updatecheck_node, "needsadmin") == "true"; |
460 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; | 465 output_object.prompt = XmlGetProperty(updatecheck_node, "Prompt") == "true"; |
461 output_object.is_delta = | 466 output_object.is_delta = |
462 XmlGetProperty(updatecheck_node, "IsDelta") == "true"; | 467 XmlGetProperty(updatecheck_node, "IsDelta") == "true"; |
463 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline"); | 468 output_object.deadline = XmlGetProperty(updatecheck_node, "deadline"); |
464 SetOutputObject(output_object); | 469 SetOutputObject(output_object); |
465 } | 470 } |
466 | 471 |
467 }; // namespace chromeos_update_engine | 472 }; // namespace chromeos_update_engine |
OLD | NEW |