OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/common/metrics_helpers.h" | 5 #include "chrome/common/metrics_helpers.h" |
6 | 6 |
7 #if defined(USE_SYSTEM_LIBBZ2) | 7 #if defined(USE_SYSTEM_LIBBZ2) |
8 #include <bzlib.h> | 8 #include <bzlib.h> |
9 #else | 9 #else |
10 #include "third_party/bzip2/bzlib.h" | 10 #include "third_party/bzip2/bzlib.h" |
11 #endif | 11 #endif |
12 | 12 |
13 #include "base/base64.h" | 13 #include "base/base64.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/md5.h" | 17 #include "base/md5.h" |
18 #include "base/perftimer.h" | 18 #include "base/perftimer.h" |
19 #include "base/scoped_ptr.h" | 19 #include "base/scoped_ptr.h" |
20 #include "base/string_util.h" | 20 #include "base/string_number_conversions.h" |
| 21 #include "base/string_util.h" // TODO(brettw) remove when ASCIIToUTF16 moves. |
21 #include "base/sys_info.h" | 22 #include "base/sys_info.h" |
22 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
23 #include "base/third_party/nspr/prtime.h" | 24 #include "base/third_party/nspr/prtime.h" |
24 #include "chrome/common/logging_chrome.h" | 25 #include "chrome/common/logging_chrome.h" |
25 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
26 #include "libxml/xmlwriter.h" | 27 #include "libxml/xmlwriter.h" |
27 | 28 |
28 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) | 29 #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
29 | 30 |
30 using base::Time; | 31 using base::Time; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 xmlTextWriterPtr writer_; | 94 xmlTextWriterPtr writer_; |
94 }; | 95 }; |
95 | 96 |
96 // static | 97 // static |
97 std::string MetricsLogBase::version_extension_; | 98 std::string MetricsLogBase::version_extension_; |
98 | 99 |
99 MetricsLogBase::MetricsLogBase(const std::string& client_id, int session_id, | 100 MetricsLogBase::MetricsLogBase(const std::string& client_id, int session_id, |
100 const std::string& version_string) | 101 const std::string& version_string) |
101 : start_time_(Time::Now()), | 102 : start_time_(Time::Now()), |
102 client_id_(client_id), | 103 client_id_(client_id), |
103 session_id_(IntToString(session_id)), | 104 session_id_(base::IntToString(session_id)), |
104 locked_(false), | 105 locked_(false), |
105 xml_wrapper_(new XmlWrapper), | 106 xml_wrapper_(new XmlWrapper), |
106 num_events_(0) { | 107 num_events_(0) { |
107 | 108 |
108 StartElement("log"); | 109 StartElement("log"); |
109 WriteAttribute("clientid", client_id_); | 110 WriteAttribute("clientid", client_id_); |
110 WriteInt64Attribute("buildtime", GetBuildTime()); | 111 WriteInt64Attribute("buildtime", GetBuildTime()); |
111 WriteAttribute("appversion", version_string); | 112 WriteAttribute("appversion", version_string); |
112 } | 113 } |
113 | 114 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 const GURL& url, | 232 const GURL& url, |
232 PageTransition::Type origin, | 233 PageTransition::Type origin, |
233 int session_index, | 234 int session_index, |
234 TimeDelta load_time) { | 235 TimeDelta load_time) { |
235 DCHECK(!locked_); | 236 DCHECK(!locked_); |
236 | 237 |
237 OPEN_ELEMENT_FOR_SCOPE("document"); | 238 OPEN_ELEMENT_FOR_SCOPE("document"); |
238 WriteAttribute("action", "load"); | 239 WriteAttribute("action", "load"); |
239 WriteIntAttribute("docid", session_index); | 240 WriteIntAttribute("docid", session_index); |
240 WriteIntAttribute("window", window_id); | 241 WriteIntAttribute("window", window_id); |
241 WriteAttribute("loadtime", Int64ToString(load_time.InMilliseconds())); | 242 WriteAttribute("loadtime", base::Int64ToString(load_time.InMilliseconds())); |
242 | 243 |
243 std::string origin_string; | 244 std::string origin_string; |
244 | 245 |
245 switch (PageTransition::StripQualifier(origin)) { | 246 switch (PageTransition::StripQualifier(origin)) { |
246 // TODO(jhughes): Some of these mappings aren't right... we need to add | 247 // TODO(jhughes): Some of these mappings aren't right... we need to add |
247 // some values to the server's enum. | 248 // some values to the server's enum. |
248 case PageTransition::LINK: | 249 case PageTransition::LINK: |
249 case PageTransition::MANUAL_SUBFRAME: | 250 case PageTransition::MANUAL_SUBFRAME: |
250 origin_string = "link"; | 251 origin_string = "link"; |
251 break; | 252 break; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 ++num_events_; | 289 ++num_events_; |
289 } | 290 } |
290 | 291 |
291 void MetricsLogBase::RecordWindowEvent(WindowEventType type, | 292 void MetricsLogBase::RecordWindowEvent(WindowEventType type, |
292 int window_id, | 293 int window_id, |
293 int parent_id) { | 294 int parent_id) { |
294 DCHECK(!locked_); | 295 DCHECK(!locked_); |
295 | 296 |
296 OPEN_ELEMENT_FOR_SCOPE("window"); | 297 OPEN_ELEMENT_FOR_SCOPE("window"); |
297 WriteAttribute("action", WindowEventTypeToString(type)); | 298 WriteAttribute("action", WindowEventTypeToString(type)); |
298 WriteAttribute("windowid", IntToString(window_id)); | 299 WriteAttribute("windowid", base::IntToString(window_id)); |
299 if (parent_id >= 0) | 300 if (parent_id >= 0) |
300 WriteAttribute("parent", IntToString(parent_id)); | 301 WriteAttribute("parent", base::IntToString(parent_id)); |
301 WriteCommonEventAttributes(); | 302 WriteCommonEventAttributes(); |
302 | 303 |
303 ++num_events_; | 304 ++num_events_; |
304 } | 305 } |
305 | 306 |
306 std::string MetricsLogBase::GetCurrentTimeString() { | 307 std::string MetricsLogBase::GetCurrentTimeString() { |
307 return Uint64ToString(Time::Now().ToTimeT()); | 308 return base::Uint64ToString(Time::Now().ToTimeT()); |
308 } | 309 } |
309 | 310 |
310 // These are the attributes that are common to every event. | 311 // These are the attributes that are common to every event. |
311 void MetricsLogBase::WriteCommonEventAttributes() { | 312 void MetricsLogBase::WriteCommonEventAttributes() { |
312 WriteAttribute("session", session_id_); | 313 WriteAttribute("session", session_id_); |
313 WriteAttribute("time", GetCurrentTimeString()); | 314 WriteAttribute("time", GetCurrentTimeString()); |
314 } | 315 } |
315 | 316 |
316 void MetricsLogBase::WriteAttribute(const std::string& name, | 317 void MetricsLogBase::WriteAttribute(const std::string& name, |
317 const std::string& value) { | 318 const std::string& value) { |
318 DCHECK(!locked_); | 319 DCHECK(!locked_); |
319 DCHECK(!name.empty()); | 320 DCHECK(!name.empty()); |
320 | 321 |
321 int result = xmlTextWriterWriteAttribute(xml_wrapper_->writer(), | 322 int result = xmlTextWriterWriteAttribute(xml_wrapper_->writer(), |
322 UnsignedChar(name.c_str()), | 323 UnsignedChar(name.c_str()), |
323 UnsignedChar(value.c_str())); | 324 UnsignedChar(value.c_str())); |
324 DCHECK_GE(result, 0); | 325 DCHECK_GE(result, 0); |
325 } | 326 } |
326 | 327 |
327 void MetricsLogBase::WriteIntAttribute(const std::string& name, int value) { | 328 void MetricsLogBase::WriteIntAttribute(const std::string& name, int value) { |
328 WriteAttribute(name, IntToString(value)); | 329 WriteAttribute(name, base::IntToString(value)); |
329 } | 330 } |
330 | 331 |
331 void MetricsLogBase::WriteInt64Attribute(const std::string& name, int64 value) { | 332 void MetricsLogBase::WriteInt64Attribute(const std::string& name, int64 value) { |
332 WriteAttribute(name, Int64ToString(value)); | 333 WriteAttribute(name, base::Int64ToString(value)); |
333 } | 334 } |
334 | 335 |
335 // static | 336 // static |
336 const char* MetricsLogBase::WindowEventTypeToString(WindowEventType type) { | 337 const char* MetricsLogBase::WindowEventTypeToString(WindowEventType type) { |
337 switch (type) { | 338 switch (type) { |
338 case WINDOW_CREATE: return "create"; | 339 case WINDOW_CREATE: return "create"; |
339 case WINDOW_OPEN: return "open"; | 340 case WINDOW_OPEN: return "open"; |
340 case WINDOW_CLOSE: return "close"; | 341 case WINDOW_CLOSE: return "close"; |
341 case WINDOW_DESTROY: return "destroy"; | 342 case WINDOW_DESTROY: return "destroy"; |
342 | 343 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 } | 508 } |
508 } | 509 } |
509 | 510 |
510 void MetricsServiceBase::DiscardPendingLog() { | 511 void MetricsServiceBase::DiscardPendingLog() { |
511 if (pending_log_) { // Shutdown might have deleted it! | 512 if (pending_log_) { // Shutdown might have deleted it! |
512 delete pending_log_; | 513 delete pending_log_; |
513 pending_log_ = NULL; | 514 pending_log_ = NULL; |
514 } | 515 } |
515 compressed_log_.clear(); | 516 compressed_log_.clear(); |
516 } | 517 } |
OLD | NEW |