OLD | NEW |
---|---|
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 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 return "unknown"; | 31 return "unknown"; |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 // Sends a fire and forget ping. The instances of this class have no | 35 // Sends a fire and forget ping. The instances of this class have no |
36 // ownership and they self-delete upon completion. | 36 // ownership and they self-delete upon completion. |
37 class PingSender : public net::URLFetcherDelegate { | 37 class PingSender : public net::URLFetcherDelegate { |
38 public: | 38 public: |
39 PingSender(); | 39 PingSender(); |
40 | 40 |
41 void SendPing(const GURL& ping_url, | 41 void SendPing(const std::string& application_version, |
42 const std::string& platform_name, | |
43 const GURL& ping_url, | |
42 net::URLRequestContextGetter* url_request_context_getter, | 44 net::URLRequestContextGetter* url_request_context_getter, |
43 const CrxUpdateItem* item); | 45 const CrxUpdateItem* item); |
44 | 46 |
45 private: | 47 private: |
46 virtual ~PingSender(); | 48 virtual ~PingSender(); |
47 | 49 |
48 // Overrides for URLFetcherDelegate. | 50 // Overrides for URLFetcherDelegate. |
49 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 51 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
50 | 52 |
51 static std::string BuildPing(const CrxUpdateItem* item); | 53 static std::string BuildPing(const std::string& application_version, |
54 const std::string& platform_name, | |
55 const CrxUpdateItem* item); | |
52 static std::string BuildDownloadCompleteEventElements( | 56 static std::string BuildDownloadCompleteEventElements( |
53 const CrxUpdateItem* item); | 57 const CrxUpdateItem* item); |
54 static std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item); | 58 static std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item); |
55 | 59 |
56 scoped_ptr<net::URLFetcher> url_fetcher_; | 60 scoped_ptr<net::URLFetcher> url_fetcher_; |
57 | 61 |
58 DISALLOW_COPY_AND_ASSIGN(PingSender); | 62 DISALLOW_COPY_AND_ASSIGN(PingSender); |
59 }; | 63 }; |
60 | 64 |
61 PingSender::PingSender() { | 65 PingSender::PingSender() { |
62 } | 66 } |
63 | 67 |
64 PingSender::~PingSender() { | 68 PingSender::~PingSender() { |
65 } | 69 } |
66 | 70 |
67 void PingSender::OnURLFetchComplete(const net::URLFetcher* source) { | 71 void PingSender::OnURLFetchComplete(const net::URLFetcher* source) { |
68 delete this; | 72 delete this; |
69 } | 73 } |
70 | 74 |
71 void PingSender::SendPing( | 75 void PingSender::SendPing( |
76 const std::string& application_version, | |
77 const std::string& platform_name, | |
72 const GURL& ping_url, | 78 const GURL& ping_url, |
73 net::URLRequestContextGetter* url_request_context_getter, | 79 net::URLRequestContextGetter* url_request_context_getter, |
74 const CrxUpdateItem* item) { | 80 const CrxUpdateItem* item) { |
75 DCHECK(item); | 81 DCHECK(item); |
76 | 82 |
77 if (!ping_url.is_valid()) | 83 if (!ping_url.is_valid()) |
78 return; | 84 return; |
79 | 85 |
80 url_fetcher_.reset(SendProtocolRequest( | 86 url_fetcher_.reset( |
81 ping_url, BuildPing(item), this, url_request_context_getter)); | 87 SendProtocolRequest(ping_url, |
88 BuildPing(application_version, platform_name, item), | |
89 this, | |
90 url_request_context_getter)); | |
82 } | 91 } |
83 | 92 |
84 // Builds a ping message for the specified update item. | 93 // Builds a ping message for the specified update item. |
85 std::string PingSender::BuildPing(const CrxUpdateItem* item) { | 94 std::string PingSender::BuildPing(const std::string& application_version, |
95 const std::string& platform_name, | |
96 const CrxUpdateItem* item) { | |
86 const char app_element_format[] = | 97 const char app_element_format[] = |
87 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" | 98 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" |
88 "%s" | 99 "%s" |
89 "%s" | 100 "%s" |
90 "</app>"; | 101 "</app>"; |
91 const std::string app_element(base::StringPrintf( | 102 const std::string app_element(base::StringPrintf( |
92 app_element_format, | 103 app_element_format, |
93 item->id.c_str(), // "appid" | 104 item->id.c_str(), // "appid" |
94 item->previous_version.GetString().c_str(), // "version" | 105 item->previous_version.GetString().c_str(), // "version" |
95 item->next_version.GetString().c_str(), // "nextversion" | 106 item->next_version.GetString().c_str(), // "nextversion" |
96 BuildUpdateCompleteEventElement(item).c_str(), // update event | 107 BuildUpdateCompleteEventElement(item).c_str(), // update event |
97 BuildDownloadCompleteEventElements(item).c_str())); // download events | 108 BuildDownloadCompleteEventElements(item).c_str())); // download events |
98 | 109 |
99 return BuildProtocolRequest(app_element, ""); | 110 return BuildProtocolRequest( |
111 application_version, platform_name, app_element, ""); | |
Sorin Jianu
2014/06/19 00:48:22
It looks to me that the additional member variable
| |
100 } | 112 } |
101 | 113 |
102 // Returns a string representing a sequence of download complete events | 114 // Returns a string representing a sequence of download complete events |
103 // corresponding to each download metrics in |item|. | 115 // corresponding to each download metrics in |item|. |
104 std::string PingSender::BuildDownloadCompleteEventElements( | 116 std::string PingSender::BuildDownloadCompleteEventElements( |
105 const CrxUpdateItem* item) { | 117 const CrxUpdateItem* item) { |
106 using base::StringAppendF; | 118 using base::StringAppendF; |
107 std::string download_events; | 119 std::string download_events; |
108 for (size_t i = 0; i != item->download_metrics.size(); ++i) { | 120 for (size_t i = 0; i != item->download_metrics.size(); ++i) { |
109 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; | 121 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 } | 184 } |
173 if (!item->previous_fp.empty()) | 185 if (!item->previous_fp.empty()) |
174 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); | 186 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); |
175 if (!item->next_fp.empty()) | 187 if (!item->next_fp.empty()) |
176 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); | 188 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); |
177 StringAppendF(&ping_event, "/>"); | 189 StringAppendF(&ping_event, "/>"); |
178 return ping_event; | 190 return ping_event; |
179 } | 191 } |
180 | 192 |
181 PingManager::PingManager( | 193 PingManager::PingManager( |
194 const std::string& application_version, | |
195 const std::string& platform_name, | |
182 const GURL& ping_url, | 196 const GURL& ping_url, |
183 net::URLRequestContextGetter* url_request_context_getter) | 197 net::URLRequestContextGetter* url_request_context_getter) |
184 : ping_url_(ping_url), | 198 : application_version_(application_version), |
199 platform_name_(platform_name), | |
200 ping_url_(ping_url), | |
185 url_request_context_getter_(url_request_context_getter) { | 201 url_request_context_getter_(url_request_context_getter) { |
186 } | 202 } |
187 | 203 |
188 PingManager::~PingManager() { | 204 PingManager::~PingManager() { |
189 } | 205 } |
190 | 206 |
191 // Sends a fire and forget ping when the updates are complete. The ping | 207 // Sends a fire and forget ping when the updates are complete. The ping |
192 // sender object self-deletes after sending the ping. | 208 // sender object self-deletes after sending the ping. |
193 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { | 209 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { |
194 PingSender* ping_sender(new PingSender); | 210 PingSender* ping_sender(new PingSender); |
195 ping_sender->SendPing(ping_url_, url_request_context_getter_, item); | 211 ping_sender->SendPing(application_version_, |
212 platform_name_, | |
213 ping_url_, | |
214 url_request_context_getter_, | |
215 item); | |
196 } | 216 } |
197 | 217 |
198 } // namespace component_updater | 218 } // namespace component_updater |
OLD | NEW |