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 #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/memory/scoped_ptr.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/component_updater/component_updater_utils.h" | 12 #include "chrome/browser/component_updater/component_updater_utils.h" |
13 #include "chrome/browser/component_updater/crx_update_item.h" | 13 #include "chrome/browser/component_updater/crx_update_item.h" |
14 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
15 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
16 | 16 |
17 namespace component_updater { | 17 namespace component_updater { |
18 | 18 |
19 // Returns true if the |update_item| contains a valid differential update url. | |
20 bool HasDiffUpdate(const CrxUpdateItem* update_item) { | |
21 return update_item->diff_crx_url.is_valid(); | |
22 } | |
23 | |
24 // Returns a string literal corresponding to the value of the downloader |d|. | 19 // Returns a string literal corresponding to the value of the downloader |d|. |
25 const char* DownloaderToString(CrxDownloader::DownloadMetrics::Downloader d) { | 20 const char* DownloaderToString(CrxDownloader::DownloadMetrics::Downloader d) { |
26 switch (d) { | 21 switch (d) { |
27 case CrxDownloader::DownloadMetrics::kUrlFetcher: | 22 case CrxDownloader::DownloadMetrics::kUrlFetcher: |
28 return "direct"; | 23 return "direct"; |
29 case CrxDownloader::DownloadMetrics::kBits: | 24 case CrxDownloader::DownloadMetrics::kBits: |
30 return "bits"; | 25 return "bits"; |
31 default: | 26 default: |
32 return "unknown"; | 27 return "unknown"; |
33 } | 28 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 95 } |
101 | 96 |
102 // Returns a string representing a sequence of download complete events | 97 // Returns a string representing a sequence of download complete events |
103 // corresponding to each download metrics in |item|. | 98 // corresponding to each download metrics in |item|. |
104 std::string PingSender::BuildDownloadCompleteEventElements( | 99 std::string PingSender::BuildDownloadCompleteEventElements( |
105 const CrxUpdateItem* item) { | 100 const CrxUpdateItem* item) { |
106 using base::StringAppendF; | 101 using base::StringAppendF; |
107 std::string download_events; | 102 std::string download_events; |
108 for (size_t i = 0; i != item->download_metrics.size(); ++i) { | 103 for (size_t i = 0; i != item->download_metrics.size(); ++i) { |
109 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; | 104 const CrxDownloader::DownloadMetrics& metrics = item->download_metrics[i]; |
110 std::string event("<event eventtype=\"14\" "); | 105 std::string event("<event eventtype=\"14\""); |
111 StringAppendF(&event, "eventresult=\"%d\"", metrics.error == 0); | 106 StringAppendF(&event, " eventresult=\"%d\"", metrics.error == 0); |
112 StringAppendF(&event, | 107 StringAppendF(&event, |
113 " downloader=\"%s\"", DownloaderToString(metrics.downloader)); | 108 " downloader=\"%s\"", DownloaderToString(metrics.downloader)); |
114 if (metrics.error) | 109 if (metrics.error) |
115 StringAppendF(&event, " errorcode=\"%d\"", metrics.error); | 110 StringAppendF(&event, " errorcode=\"%d\"", metrics.error); |
116 StringAppendF(&event, " url=\"%s\"", metrics.url.spec().c_str()); | 111 StringAppendF(&event, " url=\"%s\"", metrics.url.spec().c_str()); |
117 if (metrics.bytes_downloaded) { | 112 if (metrics.bytes_downloaded) { |
118 StringAppendF(&event, " downloaded=\"%s\"", | 113 StringAppendF(&event, " downloaded=\"%s\"", |
119 base::Uint64ToString(metrics.bytes_downloaded).c_str()); | 114 base::Uint64ToString(metrics.bytes_downloaded).c_str()); |
120 } | 115 } |
121 if (metrics.bytes_total) | 116 if (metrics.bytes_total) { |
122 StringAppendF(&event, " total=\"%s\"", | 117 StringAppendF(&event, " total=\"%s\"", |
123 base::Uint64ToString(metrics.bytes_total).c_str()); | 118 base::Uint64ToString(metrics.bytes_total).c_str()); |
| 119 } |
124 if (metrics.download_time_ms) { | 120 if (metrics.download_time_ms) { |
125 StringAppendF(&event, " download_time_ms=\"%s\"", | 121 StringAppendF(&event, " download_time_ms=\"%s\"", |
126 base::Uint64ToString(metrics.download_time_ms).c_str()); | 122 base::Uint64ToString(metrics.download_time_ms).c_str()); |
127 } | 123 } |
128 StringAppendF(&event, "/>"); | 124 StringAppendF(&event, "/>"); |
129 | 125 |
130 download_events += event; | 126 download_events += event; |
131 } | 127 } |
132 return download_events; | 128 return download_events; |
133 } | 129 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 178 |
183 // Sends a fire and forget ping when the updates are complete. The ping | 179 // Sends a fire and forget ping when the updates are complete. The ping |
184 // sender object self-deletes after sending the ping. | 180 // sender object self-deletes after sending the ping. |
185 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { | 181 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { |
186 component_updater::PingSender* ping_sender(new PingSender); | 182 component_updater::PingSender* ping_sender(new PingSender); |
187 ping_sender->SendPing(ping_url_, url_request_context_getter_, item); | 183 ping_sender->SendPing(ping_url_, url_request_context_getter_, item); |
188 } | 184 } |
189 | 185 |
190 } // namespace component_updater | 186 } // namespace component_updater |
191 | 187 |
OLD | NEW |