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

Side by Side Diff: chrome/browser/component_updater/component_updater_ping_manager.cc

Issue 74893002: Changed the update protocol for component updater from v2 to v3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/component_updater/component_updater_ping_manager.h" 5 #include "chrome/browser/component_updater/component_updater_ping_manager.h"
6 #include "base/guid.h" 6 #include "base/guid.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "base/sys_info.h" 11 #include "chrome/browser/component_updater/component_updater_utils.h"
11 #include "base/win/windows_version.h"
12 #include "chrome/browser/component_updater/crx_update_item.h" 12 #include "chrome/browser/component_updater/crx_update_item.h"
13 #include "chrome/common/chrome_version_info.h"
14 #include "chrome/common/omaha_query_params/omaha_query_params.h"
15 #include "net/base/load_flags.h"
16 #include "net/base/net_errors.h"
17 #include "net/url_request/url_fetcher.h" 13 #include "net/url_request/url_fetcher.h"
18 #include "net/url_request/url_fetcher_delegate.h" 14 #include "net/url_request/url_fetcher_delegate.h"
19 #include "net/url_request/url_request_status.h"
20 15
21 namespace { 16 namespace {
22 17
23 // Returns true if the |update_item| contains a valid differential update url. 18 // Returns true if the |update_item| contains a valid differential update url.
24 bool HasDiffUpdate(const CrxUpdateItem* update_item) { 19 bool HasDiffUpdate(const CrxUpdateItem* update_item) {
25 return update_item->diff_crx_url.is_valid(); 20 return update_item->diff_crx_url.is_valid();
26 } 21 }
27 22
28 } // namespace 23 } // namespace
29 24
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 57
63 void PingSender::SendPing( 58 void PingSender::SendPing(
64 const GURL& ping_url, 59 const GURL& ping_url,
65 net::URLRequestContextGetter* url_request_context_getter, 60 net::URLRequestContextGetter* url_request_context_getter,
66 const CrxUpdateItem* item) { 61 const CrxUpdateItem* item) {
67 DCHECK(item); 62 DCHECK(item);
68 63
69 if (!ping_url.is_valid()) 64 if (!ping_url.is_valid())
70 return; 65 return;
71 66
72 url_fetcher_.reset(net::URLFetcher::Create(0, 67 url_fetcher_.reset(SendProtocolRequest(ping_url,
73 ping_url, 68 BuildPing(item),
74 net::URLFetcher::POST, 69 this,
75 this)); 70 url_request_context_getter));
76
77 url_fetcher_->SetUploadData("application/xml", BuildPing(item));
78 url_fetcher_->SetRequestContext(url_request_context_getter);
79 url_fetcher_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
80 net::LOAD_DO_NOT_SAVE_COOKIES |
81 net::LOAD_DISABLE_CACHE);
82 url_fetcher_->SetAutomaticallyRetryOn5xx(false);
83 url_fetcher_->Start();
84 } 71 }
85 72
86 // Builds a ping message for the specified update item. 73 // Builds a ping message for the specified update item.
87 std::string PingSender::BuildPing(const CrxUpdateItem* item) { 74 std::string PingSender::BuildPing(const CrxUpdateItem* item) {
88 const std::string prod_id(chrome::OmahaQueryParams::GetProdIdString( 75 const char app_element_format[] =
89 chrome::OmahaQueryParams::CHROME)); 76 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">"
77 "%s"
78 "</app>";
79 const std::string app_element(base::StringPrintf(
80 app_element_format,
81 item->id.c_str(), // "appid"
82 item->previous_version.GetString().c_str(), // "version"
83 item->next_version.GetString().c_str(), // "nextversion"
waffles 2013/11/18 22:15:59 What is the benefit of sending previous_version an
Sorin Jianu 2013/11/19 04:25:45 Let's discuss and see if there is a way to fix tha
84 BuildPingEventElement(item).c_str()));
90 85
91 const char request_format[] = 86 return BuildProtocolRequest(app_element);
92 "<o:gupdate xmlns:o=\"http://www.google.com/update2/request\" "
93 "protocol=\"2.0\" version=\"%s-%s\" requestid=\"{%s}\" "
94 "updaterchannel=\"%s\"> "
95 "<o:os platform=\"%s\" version=\"%s\"/> "
96 "<o:app appid=\"%s\" version=\"%s\">"
97 "%s"
98 "</o:app></o:gupdate>";
99 const std::string request(
100 base::StringPrintf(request_format,
101 prod_id.c_str(),
102 chrome::VersionInfo().Version().c_str(),
103 base::GenerateGUID().c_str(),
104 chrome::OmahaQueryParams::GetChannelString(),
105 chrome::VersionInfo().OSType().c_str(),
106 base::SysInfo().OperatingSystemVersion().c_str(),
107 item->id.c_str(),
108 item->component.version.GetString().c_str(),
109 BuildPingEventElement(item).c_str()));
110 return request;
111 } 87 }
112 88
113 // Returns a string representing one ping event xml element for an update item. 89 // Returns a string representing one ping event xml element for an update item.
114 std::string PingSender::BuildPingEventElement(const CrxUpdateItem* item) { 90 std::string PingSender::BuildPingEventElement(const CrxUpdateItem* item) {
115 DCHECK(item->status == CrxUpdateItem::kNoUpdate || 91 DCHECK(item->status == CrxUpdateItem::kNoUpdate ||
116 item->status == CrxUpdateItem::kUpdated); 92 item->status == CrxUpdateItem::kUpdated);
117 93
118 using base::StringAppendF; 94 using base::StringAppendF;
119 95
120 std::string ping_event("<o:event eventtype=\"3\""); 96 std::string ping_event("<event eventtype=\"3\"");
waffles 2013/11/18 22:15:59 Any thoughts about sending eventtype="2" for updat
Sorin Jianu 2013/11/19 04:25:45 If could add that is you think it can help with th
waffles 2013/11/19 18:33:58 Let's avoid it for now. The distinction between in
121 const int event_result = item->status == CrxUpdateItem::kUpdated; 97 const int event_result = item->status == CrxUpdateItem::kUpdated;
122 StringAppendF(&ping_event, " eventresult=\"%d\"", event_result); 98 StringAppendF(&ping_event, " eventresult=\"%d\"", event_result);
123 StringAppendF(&ping_event, " previousversion=\"%s\"",
124 item->previous_version.GetString().c_str());
125 StringAppendF(&ping_event, " nextversion=\"%s\"",
126 item->next_version.GetString().c_str());
127 if (item->error_category) 99 if (item->error_category)
128 StringAppendF(&ping_event, " errorcat=\"%d\"", item->error_category); 100 StringAppendF(&ping_event, " errorcat=\"%d\"", item->error_category);
129 if (item->error_code) 101 if (item->error_code)
130 StringAppendF(&ping_event, " errorcode=\"%d\"", item->error_code); 102 StringAppendF(&ping_event, " errorcode=\"%d\"", item->error_code);
131 if (item->extra_code1) 103 if (item->extra_code1)
132 StringAppendF(&ping_event, " extracode1=\"%d\"", item->extra_code1); 104 StringAppendF(&ping_event, " extracode1=\"%d\"", item->extra_code1);
133 if (HasDiffUpdate(item)) 105 if (HasDiffUpdate(item))
134 StringAppendF(&ping_event, " diffresult=\"%d\"", !item->diff_update_failed); 106 StringAppendF(&ping_event, " diffresult=\"%d\"", !item->diff_update_failed);
135 if (item->diff_error_category) 107 if (item->diff_error_category)
136 StringAppendF(&ping_event, 108 StringAppendF(&ping_event,
(...skipping 26 matching lines...) Expand all
163 135
164 // Sends a fire and forget ping when the updates are complete. The ping 136 // Sends a fire and forget ping when the updates are complete. The ping
165 // sender object self-deletes after sending the ping. 137 // sender object self-deletes after sending the ping.
166 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { 138 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) {
167 component_updater::PingSender* ping_sender(new PingSender); 139 component_updater::PingSender* ping_sender(new PingSender);
168 ping_sender->SendPing(ping_url_, url_request_context_getter_, item); 140 ping_sender->SendPing(ping_url_, url_request_context_getter_, item);
169 } 141 }
170 142
171 } // namespace component_updater 143 } // namespace component_updater
172 144
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698