OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/update_client/ping_manager.h" | 5 #include "components/update_client/ping_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 StringAppendF(&event, " download_time_ms=\"%s\"", | 74 StringAppendF(&event, " download_time_ms=\"%s\"", |
75 base::Uint64ToString(metrics.download_time_ms).c_str()); | 75 base::Uint64ToString(metrics.download_time_ms).c_str()); |
76 } | 76 } |
77 StringAppendF(&event, "/>"); | 77 StringAppendF(&event, "/>"); |
78 | 78 |
79 download_events += event; | 79 download_events += event; |
80 } | 80 } |
81 return download_events; | 81 return download_events; |
82 } | 82 } |
83 | 83 |
84 // Returns a string representing one ping event xml element for an update item. | 84 // Returns a string representing one ping event for the update of an item. |
| 85 // The event type for this ping event is 3. |
85 std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item) { | 86 std::string BuildUpdateCompleteEventElement(const CrxUpdateItem* item) { |
86 DCHECK(item->state == CrxUpdateItem::State::kNoUpdate || | 87 DCHECK(item->state == CrxUpdateItem::State::kNoUpdate || |
87 item->state == CrxUpdateItem::State::kUpdated); | 88 item->state == CrxUpdateItem::State::kUpdated); |
88 | 89 |
89 using base::StringAppendF; | 90 using base::StringAppendF; |
90 | 91 |
91 std::string ping_event("<event eventtype=\"3\""); | 92 std::string ping_event("<event eventtype=\"3\""); |
92 const int event_result = item->state == CrxUpdateItem::State::kUpdated; | 93 const int event_result = item->state == CrxUpdateItem::State::kUpdated; |
93 StringAppendF(&ping_event, " eventresult=\"%d\"", event_result); | 94 StringAppendF(&ping_event, " eventresult=\"%d\"", event_result); |
94 if (item->error_category) | 95 if (item->error_category) |
(...skipping 15 matching lines...) Expand all Loading... |
110 item->diff_extra_code1); | 111 item->diff_extra_code1); |
111 } | 112 } |
112 if (!item->previous_fp.empty()) | 113 if (!item->previous_fp.empty()) |
113 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); | 114 StringAppendF(&ping_event, " previousfp=\"%s\"", item->previous_fp.c_str()); |
114 if (!item->next_fp.empty()) | 115 if (!item->next_fp.empty()) |
115 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); | 116 StringAppendF(&ping_event, " nextfp=\"%s\"", item->next_fp.c_str()); |
116 StringAppendF(&ping_event, "/>"); | 117 StringAppendF(&ping_event, "/>"); |
117 return ping_event; | 118 return ping_event; |
118 } | 119 } |
119 | 120 |
| 121 // Returns a string representing one ping event for the uninstall of an item. |
| 122 // The event type for this ping event is 4. |
| 123 std::string BuildUninstalledEventElement(const CrxUpdateItem* item) { |
| 124 DCHECK(item->state == CrxUpdateItem::State::kUninstalled); |
| 125 |
| 126 using base::StringAppendF; |
| 127 |
| 128 std::string ping_event("<event eventtype=\"4\" eventresult=\"1\""); |
| 129 if (item->extra_code1) |
| 130 StringAppendF(&ping_event, " extracode1=\"%d\"", item->extra_code1); |
| 131 StringAppendF(&ping_event, "/>"); |
| 132 return ping_event; |
| 133 } |
| 134 |
120 // Builds a ping message for the specified update item. | 135 // Builds a ping message for the specified update item. |
121 std::string BuildPing(const Configurator& config, const CrxUpdateItem* item) { | 136 std::string BuildPing(const Configurator& config, const CrxUpdateItem* item) { |
122 const char app_element_format[] = | 137 const char app_element_format[] = |
123 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" | 138 "<app appid=\"%s\" version=\"%s\" nextversion=\"%s\">" |
124 "%s" | 139 "%s" |
125 "%s" | 140 "%s" |
126 "</app>"; | 141 "</app>"; |
| 142 |
| 143 std::string ping_event; |
| 144 switch (item->state) { |
| 145 case CrxUpdateItem::State::kNoUpdate: // Fall through. |
| 146 case CrxUpdateItem::State::kUpdated: |
| 147 ping_event = BuildUpdateCompleteEventElement(item); |
| 148 break; |
| 149 case CrxUpdateItem::State::kUninstalled: |
| 150 ping_event = BuildUninstalledEventElement(item); |
| 151 break; |
| 152 default: |
| 153 NOTREACHED(); |
| 154 break; |
| 155 } |
| 156 |
127 const std::string app_element(base::StringPrintf( | 157 const std::string app_element(base::StringPrintf( |
128 app_element_format, | 158 app_element_format, |
129 item->id.c_str(), // "appid" | 159 item->id.c_str(), // "appid" |
130 item->previous_version.GetString().c_str(), // "version" | 160 item->previous_version.GetString().c_str(), // "version" |
131 item->next_version.GetString().c_str(), // "nextversion" | 161 item->next_version.GetString().c_str(), // "nextversion" |
132 BuildUpdateCompleteEventElement(item).c_str(), // update event | 162 ping_event.c_str(), // ping event |
133 BuildDownloadCompleteEventElements(item).c_str())); // download events | 163 BuildDownloadCompleteEventElements(item).c_str())); // download events |
134 | 164 |
135 return BuildProtocolRequest(config.GetBrowserVersion().GetString(), | 165 return BuildProtocolRequest(config.GetBrowserVersion().GetString(), |
136 config.GetChannel(), config.GetLang(), | 166 config.GetChannel(), config.GetLang(), |
137 config.GetOSLongName(), app_element, ""); | 167 config.GetOSLongName(), app_element, ""); |
138 } | 168 } |
139 | 169 |
140 // Sends a fire and forget ping. The instances of this class have no | 170 // Sends a fire and forget ping. The instances of this class have no |
141 // ownership and they self-delete upon completion. One instance of this class | 171 // ownership and they self-delete upon completion. One instance of this class |
142 // can send only one ping. | 172 // can send only one ping. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } // namespace | 218 } // namespace |
189 | 219 |
190 PingManager::PingManager(const scoped_refptr<Configurator>& config) | 220 PingManager::PingManager(const scoped_refptr<Configurator>& config) |
191 : config_(config) {} | 221 : config_(config) {} |
192 | 222 |
193 PingManager::~PingManager() { | 223 PingManager::~PingManager() { |
194 } | 224 } |
195 | 225 |
196 // Sends a fire and forget ping when the updates are complete. The ping | 226 // Sends a fire and forget ping when the updates are complete. The ping |
197 // sender object self-deletes after sending the ping has completed asynchrously. | 227 // sender object self-deletes after sending the ping has completed asynchrously. |
198 void PingManager::OnUpdateComplete(const CrxUpdateItem* item) { | 228 void PingManager::SendPing(const CrxUpdateItem* item) { |
199 PingSender* ping_sender(new PingSender(config_)); | 229 PingSender* ping_sender(new PingSender(config_)); |
200 if (!ping_sender->SendPing(item)) | 230 if (!ping_sender->SendPing(item)) |
201 delete ping_sender; | 231 delete ping_sender; |
202 } | 232 } |
203 | 233 |
204 } // namespace update_client | 234 } // namespace update_client |
OLD | NEW |