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

Side by Side Diff: chrome/browser/metrics/metrics_log.cc

Issue 9559017: [UMA] Include field trial tuples in the UMA upload. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 months 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/metrics/metrics_log.h" 5 #include "chrome/browser/metrics/metrics_log.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #endif 46 #endif
47 47
48 using content::GpuDataManager; 48 using content::GpuDataManager;
49 using metrics::OmniboxEventProto; 49 using metrics::OmniboxEventProto;
50 using metrics::SystemProfileProto; 50 using metrics::SystemProfileProto;
51 51
52 namespace { 52 namespace {
53 53
54 // Returns the date at which the current metrics client ID was created as 54 // Returns the date at which the current metrics client ID was created as
55 // a string containing milliseconds since the epoch, or "0" if none was found. 55 // a string containing milliseconds since the epoch, or "0" if none was found.
56 std::string GetInstallDate() { 56 std::string GetInstallDate(PrefService* pref) {
57 PrefService* pref = g_browser_process->local_state(); 57 if (!pref) {
58 if (pref) {
59 return pref->GetString(prefs::kMetricsClientIDTimestamp);
60 } else {
61 NOTREACHED(); 58 NOTREACHED();
62 return "0"; 59 return "0";
63 } 60 }
61
62 return pref->GetString(prefs::kMetricsClientIDTimestamp);
64 } 63 }
65 64
66 OmniboxEventProto::InputType AsOmniboxEventInputType( 65 OmniboxEventProto::InputType AsOmniboxEventInputType(
67 AutocompleteInput::Type type) { 66 AutocompleteInput::Type type) {
68 switch (type) { 67 switch (type) {
69 case AutocompleteInput::INVALID: 68 case AutocompleteInput::INVALID:
70 return OmniboxEventProto::INVALID; 69 return OmniboxEventProto::INVALID;
71 case AutocompleteInput::UNKNOWN: 70 case AutocompleteInput::UNKNOWN:
72 return OmniboxEventProto::UNKNOWN; 71 return OmniboxEventProto::UNKNOWN;
73 case AutocompleteInput::REQUESTED_URL: 72 case AutocompleteInput::REQUESTED_URL:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 void SetPluginInfo(const webkit::WebPluginInfo& plugin_info, 163 void SetPluginInfo(const webkit::WebPluginInfo& plugin_info,
165 const PluginPrefs* plugin_prefs, 164 const PluginPrefs* plugin_prefs,
166 SystemProfileProto::Plugin* plugin) { 165 SystemProfileProto::Plugin* plugin) {
167 plugin->set_name(UTF16ToUTF8(plugin_info.name)); 166 plugin->set_name(UTF16ToUTF8(plugin_info.name));
168 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe()); 167 plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe());
169 plugin->set_version(UTF16ToUTF8(plugin_info.version)); 168 plugin->set_version(UTF16ToUTF8(plugin_info.version));
170 if (plugin_prefs) 169 if (plugin_prefs)
171 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info)); 170 plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info));
172 } 171 }
173 172
173 void WriteFieldTrials(
174 const std::vector<base::FieldTrial::NameGroupId>& field_trial_ids,
175 SystemProfileProto* system_profile) {
176 for (std::vector<base::FieldTrial::NameGroupId>::const_iterator it =
177 field_trial_ids.begin(); it != field_trial_ids.end(); ++it) {
178 SystemProfileProto::FieldTrial* field_trial =
179 system_profile->add_field_trial();
jar (doing other things) 2012/03/01 05:32:42 personal style nit: This API seems strange to me.
Ilya Sherman 2012/03/01 06:41:50 Alas, this is just how the C++ protocol buffer API
180 field_trial->set_name_id(it->name);
181 field_trial->set_group_id(it->group);
182 }
183 }
184
174 } // namespace 185 } // namespace
175 186
176 static base::LazyInstance<std::string>::Leaky 187 static base::LazyInstance<std::string>::Leaky
177 g_version_extension = LAZY_INSTANCE_INITIALIZER; 188 g_version_extension = LAZY_INSTANCE_INITIALIZER;
178 189
179 MetricsLog::MetricsLog(const std::string& client_id, int session_id) 190 MetricsLog::MetricsLog(const std::string& client_id, int session_id)
180 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} 191 : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {}
181 192
182 MetricsLog::~MetricsLog() {} 193 MetricsLog::~MetricsLog() {}
183 194
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 g_version_extension.Get() = extension; 234 g_version_extension.Get() = extension;
224 } 235 }
225 236
226 // static 237 // static
227 const std::string& MetricsLog::version_extension() { 238 const std::string& MetricsLog::version_extension() {
228 return g_version_extension.Get(); 239 return g_version_extension.Get();
229 } 240 }
230 241
231 void MetricsLog::RecordIncrementalStabilityElements( 242 void MetricsLog::RecordIncrementalStabilityElements(
232 const std::vector<webkit::WebPluginInfo>& plugin_list) { 243 const std::vector<webkit::WebPluginInfo>& plugin_list) {
233 DCHECK(!locked_); 244 DCHECK(!locked());
234 245
235 PrefService* pref = g_browser_process->local_state(); 246 PrefService* pref = GetPrefService();
236 DCHECK(pref); 247 DCHECK(pref);
237 248
238 OPEN_ELEMENT_FOR_SCOPE("profile"); 249 OPEN_ELEMENT_FOR_SCOPE("profile");
239 WriteCommonEventAttributes(); 250 WriteCommonEventAttributes();
240 251
241 WriteInstallElement(); 252 WriteInstallElement();
242 253
243 { 254 {
244 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. 255 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements.
245 WriteRequiredStabilityAttributes(pref); 256 WriteRequiredStabilityAttributes(pref);
246 WriteRealtimeStabilityAttributes(pref); 257 WriteRealtimeStabilityAttributes(pref);
247 258
248 WritePluginStabilityElements(plugin_list, pref); 259 WritePluginStabilityElements(plugin_list, pref);
249 } 260 }
250 } 261 }
251 262
263 PrefService* MetricsLog::GetPrefService() {
264 return g_browser_process->local_state();
265 }
266
267 void MetricsLog::GetFieldTrialIds(
268 std::vector<base::FieldTrial::NameGroupId>* field_trial_ids) const {
269 base::FieldTrialList::GetFieldTrialNameGroupIds(field_trial_ids);
270 }
271
272
273
252 void MetricsLog::WriteStabilityElement( 274 void MetricsLog::WriteStabilityElement(
253 const std::vector<webkit::WebPluginInfo>& plugin_list, 275 const std::vector<webkit::WebPluginInfo>& plugin_list,
254 PrefService* pref) { 276 PrefService* pref) {
255 DCHECK(!locked_); 277 DCHECK(!locked());
256 278
257 // Get stability attributes out of Local State, zeroing out stored values. 279 // Get stability attributes out of Local State, zeroing out stored values.
258 // NOTE: This could lead to some data loss if this report isn't successfully 280 // NOTE: This could lead to some data loss if this report isn't successfully
259 // sent, but that's true for all the metrics. 281 // sent, but that's true for all the metrics.
260 282
261 OPEN_ELEMENT_FOR_SCOPE("stability"); 283 OPEN_ELEMENT_FOR_SCOPE("stability");
262 WriteRequiredStabilityAttributes(pref); 284 WriteRequiredStabilityAttributes(pref);
263 WriteRealtimeStabilityAttributes(pref); 285 WriteRealtimeStabilityAttributes(pref);
264 286
265 int incomplete_shutdown_count = 287 int incomplete_shutdown_count =
(...skipping 19 matching lines...) Expand all
285 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count); 307 WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count);
286 WriteIntAttribute("breakpadregistrationok", 308 WriteIntAttribute("breakpadregistrationok",
287 breakpad_registration_success_count); 309 breakpad_registration_success_count);
288 WriteIntAttribute("breakpadregistrationfail", 310 WriteIntAttribute("breakpadregistrationfail",
289 breakpad_registration_failure_count); 311 breakpad_registration_failure_count);
290 WriteIntAttribute("debuggerpresent", debugger_present_count); 312 WriteIntAttribute("debuggerpresent", debugger_present_count);
291 WriteIntAttribute("debuggernotpresent", debugger_not_present_count); 313 WriteIntAttribute("debuggernotpresent", debugger_not_present_count);
292 314
293 // Write the protobuf version. 315 // Write the protobuf version.
294 SystemProfileProto::Stability* stability = 316 SystemProfileProto::Stability* stability =
295 uma_proto_.mutable_system_profile()->mutable_stability(); 317 uma_proto()->mutable_system_profile()->mutable_stability();
296 stability->set_incomplete_shutdown_count(incomplete_shutdown_count); 318 stability->set_incomplete_shutdown_count(incomplete_shutdown_count);
297 stability->set_breakpad_registration_success_count( 319 stability->set_breakpad_registration_success_count(
298 breakpad_registration_success_count); 320 breakpad_registration_success_count);
299 stability->set_breakpad_registration_failure_count( 321 stability->set_breakpad_registration_failure_count(
300 breakpad_registration_failure_count); 322 breakpad_registration_failure_count);
301 stability->set_debugger_present_count(debugger_present_count); 323 stability->set_debugger_present_count(debugger_present_count);
302 stability->set_debugger_not_present_count(debugger_not_present_count); 324 stability->set_debugger_not_present_count(debugger_not_present_count);
303 325
304 WritePluginStabilityElements(plugin_list, pref); 326 WritePluginStabilityElements(plugin_list, pref);
305 } 327 }
306 328
307 void MetricsLog::WritePluginStabilityElements( 329 void MetricsLog::WritePluginStabilityElements(
308 const std::vector<webkit::WebPluginInfo>& plugin_list, 330 const std::vector<webkit::WebPluginInfo>& plugin_list,
309 PrefService* pref) { 331 PrefService* pref) {
310 // Now log plugin stability info. 332 // Now log plugin stability info.
311 const ListValue* plugin_stats_list = pref->GetList( 333 const ListValue* plugin_stats_list = pref->GetList(
312 prefs::kStabilityPluginStats); 334 prefs::kStabilityPluginStats);
313 if (!plugin_stats_list) 335 if (!plugin_stats_list)
314 return; 336 return;
315 337
316 OPEN_ELEMENT_FOR_SCOPE("plugins"); 338 OPEN_ELEMENT_FOR_SCOPE("plugins");
317 SystemProfileProto::Stability* stability = 339 SystemProfileProto::Stability* stability =
318 uma_proto_.mutable_system_profile()->mutable_stability(); 340 uma_proto()->mutable_system_profile()->mutable_stability();
319 PluginPrefs* plugin_prefs = GetPluginPrefs(); 341 PluginPrefs* plugin_prefs = GetPluginPrefs();
320 for (ListValue::const_iterator iter = plugin_stats_list->begin(); 342 for (ListValue::const_iterator iter = plugin_stats_list->begin();
321 iter != plugin_stats_list->end(); ++iter) { 343 iter != plugin_stats_list->end(); ++iter) {
322 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { 344 if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) {
323 NOTREACHED(); 345 NOTREACHED();
324 continue; 346 continue;
325 } 347 }
326 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); 348 DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter);
327 349
328 std::string plugin_name; 350 std::string plugin_name;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 pref->SetInteger(prefs::kStabilityLaunchCount, 0); 415 pref->SetInteger(prefs::kStabilityLaunchCount, 0);
394 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); 416 int crash_count = pref->GetInteger(prefs::kStabilityCrashCount);
395 pref->SetInteger(prefs::kStabilityCrashCount, 0); 417 pref->SetInteger(prefs::kStabilityCrashCount, 0);
396 418
397 // Write the XML version. 419 // Write the XML version.
398 WriteIntAttribute("launchcount", launch_count); 420 WriteIntAttribute("launchcount", launch_count);
399 WriteIntAttribute("crashcount", crash_count); 421 WriteIntAttribute("crashcount", crash_count);
400 422
401 // Write the protobuf version. 423 // Write the protobuf version.
402 SystemProfileProto::Stability* stability = 424 SystemProfileProto::Stability* stability =
403 uma_proto_.mutable_system_profile()->mutable_stability(); 425 uma_proto()->mutable_system_profile()->mutable_stability();
404 stability->set_launch_count(launch_count); 426 stability->set_launch_count(launch_count);
405 stability->set_crash_count(crash_count); 427 stability->set_crash_count(crash_count);
406 } 428 }
407 429
408 void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { 430 void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) {
409 // Update the stats which are critical for real-time stability monitoring. 431 // Update the stats which are critical for real-time stability monitoring.
410 // Since these are "optional," only list ones that are non-zero, as the counts 432 // Since these are "optional," only list ones that are non-zero, as the counts
411 // are aggergated (summed) server side. 433 // are aggergated (summed) server side.
412 434
413 SystemProfileProto::Stability* stability = 435 SystemProfileProto::Stability* stability =
414 uma_proto_.mutable_system_profile()->mutable_stability(); 436 uma_proto()->mutable_system_profile()->mutable_stability();
415 int count = pref->GetInteger(prefs::kStabilityPageLoadCount); 437 int count = pref->GetInteger(prefs::kStabilityPageLoadCount);
416 if (count) { 438 if (count) {
417 WriteIntAttribute("pageloadcount", count); 439 WriteIntAttribute("pageloadcount", count);
418 stability->set_page_load_count(count); 440 stability->set_page_load_count(count);
419 pref->SetInteger(prefs::kStabilityPageLoadCount, 0); 441 pref->SetInteger(prefs::kStabilityPageLoadCount, 0);
420 } 442 }
421 443
422 count = pref->GetInteger(prefs::kStabilityRendererCrashCount); 444 count = pref->GetInteger(prefs::kStabilityRendererCrashCount);
423 if (count) { 445 if (count) {
424 WriteIntAttribute("renderercrashcount", count); 446 WriteIntAttribute("renderercrashcount", count);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 491
470 int64 recent_duration = GetIncrementalUptime(pref); 492 int64 recent_duration = GetIncrementalUptime(pref);
471 if (recent_duration) { 493 if (recent_duration) {
472 WriteInt64Attribute("uptimesec", recent_duration); 494 WriteInt64Attribute("uptimesec", recent_duration);
473 stability->set_uptime_sec(recent_duration); 495 stability->set_uptime_sec(recent_duration);
474 } 496 }
475 } 497 }
476 498
477 void MetricsLog::WritePluginList( 499 void MetricsLog::WritePluginList(
478 const std::vector<webkit::WebPluginInfo>& plugin_list) { 500 const std::vector<webkit::WebPluginInfo>& plugin_list) {
479 DCHECK(!locked_); 501 DCHECK(!locked());
480 502
481 PluginPrefs* plugin_prefs = GetPluginPrefs(); 503 PluginPrefs* plugin_prefs = GetPluginPrefs();
482 504
483 OPEN_ELEMENT_FOR_SCOPE("plugins"); 505 OPEN_ELEMENT_FOR_SCOPE("plugins");
484 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile(); 506 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
485 for (std::vector<webkit::WebPluginInfo>::const_iterator iter = 507 for (std::vector<webkit::WebPluginInfo>::const_iterator iter =
486 plugin_list.begin(); 508 plugin_list.begin();
487 iter != plugin_list.end(); ++iter) { 509 iter != plugin_list.end(); ++iter) {
488 std::string base64_name_hash; 510 std::string base64_name_hash;
489 uint64 numeric_name_hash_ignored; 511 uint64 numeric_name_hash_ignored;
490 CreateHashes(UTF16ToUTF8(iter->name), 512 CreateHashes(UTF16ToUTF8(iter->name),
491 &base64_name_hash, 513 &base64_name_hash,
492 &numeric_name_hash_ignored); 514 &numeric_name_hash_ignored);
493 515
494 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe(); 516 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe();
(...skipping 14 matching lines...) Expand all
509 if (plugin_prefs) 531 if (plugin_prefs)
510 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); 532 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter));
511 533
512 // Write the protobuf version. 534 // Write the protobuf version.
513 SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); 535 SystemProfileProto::Plugin* plugin = system_profile->add_plugin();
514 SetPluginInfo(*iter, plugin_prefs, plugin); 536 SetPluginInfo(*iter, plugin_prefs, plugin);
515 } 537 }
516 } 538 }
517 539
518 void MetricsLog::WriteInstallElement() { 540 void MetricsLog::WriteInstallElement() {
519 std::string install_date = GetInstallDate(); 541 std::string install_date = GetInstallDate(GetPrefService());
520 542
521 // Write the XML version. 543 // Write the XML version.
522 OPEN_ELEMENT_FOR_SCOPE("install"); 544 OPEN_ELEMENT_FOR_SCOPE("install");
523 WriteAttribute("installdate", install_date); 545 WriteAttribute("installdate", install_date);
524 WriteIntAttribute("buildid", 0); // We're using appversion instead. 546 WriteIntAttribute("buildid", 0); // We're using appversion instead.
525 547
526 // Write the protobuf version. 548 // Write the protobuf version.
527 int numeric_install_date; 549 int numeric_install_date;
528 bool success = base::StringToInt(install_date, &numeric_install_date); 550 bool success = base::StringToInt(install_date, &numeric_install_date);
529 DCHECK(success); 551 DCHECK(success);
530 uma_proto_.mutable_system_profile()->set_install_date(numeric_install_date); 552 uma_proto()->mutable_system_profile()->set_install_date(numeric_install_date);
531 } 553 }
532 554
533 void MetricsLog::RecordEnvironment( 555 void MetricsLog::RecordEnvironment(
534 const std::vector<webkit::WebPluginInfo>& plugin_list, 556 const std::vector<webkit::WebPluginInfo>& plugin_list,
535 const DictionaryValue* profile_metrics) { 557 const DictionaryValue* profile_metrics) {
536 DCHECK(!locked_); 558 DCHECK(!locked());
537 559
538 PrefService* pref = g_browser_process->local_state(); 560 PrefService* pref = GetPrefService();
539 561
540 OPEN_ELEMENT_FOR_SCOPE("profile"); 562 OPEN_ELEMENT_FOR_SCOPE("profile");
541 WriteCommonEventAttributes(); 563 WriteCommonEventAttributes();
542 564
543 WriteInstallElement(); 565 WriteInstallElement();
544 566
545 WritePluginList(plugin_list); 567 WritePluginList(plugin_list);
546 568
547 WriteStabilityElement(plugin_list, pref); 569 WriteStabilityElement(plugin_list, pref);
548 570
549 SystemProfileProto* system_profile = uma_proto_.mutable_system_profile(); 571 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile();
550 system_profile->set_application_locale( 572 system_profile->set_application_locale(
551 content::GetContentClient()->browser()->GetApplicationLocale()); 573 content::GetContentClient()->browser()->GetApplicationLocale());
552 574
553 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); 575 SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware();
554 { 576 {
555 std::string cpu_architecture = base::SysInfo::CPUArchitecture(); 577 std::string cpu_architecture = base::SysInfo::CPUArchitecture();
556 578
557 // Write the XML version. 579 // Write the XML version.
558 OPEN_ELEMENT_FOR_SCOPE("cpu"); 580 OPEN_ELEMENT_FOR_SCOPE("cpu");
559 WriteAttribute("arch", cpu_architecture); 581 WriteAttribute("arch", cpu_architecture);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 } 685 }
664 } 686 }
665 687
666 { 688 {
667 OPEN_ELEMENT_FOR_SCOPE("keywords"); 689 OPEN_ELEMENT_FOR_SCOPE("keywords");
668 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords)); 690 WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords));
669 } 691 }
670 692
671 if (profile_metrics) 693 if (profile_metrics)
672 WriteAllProfilesMetrics(*profile_metrics); 694 WriteAllProfilesMetrics(*profile_metrics);
695
696 std::vector<base::FieldTrial::NameGroupId> field_trial_ids;
697 GetFieldTrialIds(&field_trial_ids);
698 WriteFieldTrials(field_trial_ids, system_profile);
jar (doing other things) 2012/03/01 05:32:42 This is tempting to make a method on system_profil
Ilya Sherman 2012/03/01 06:41:50 Again, system_profile is a protocol buffer, so I h
673 } 699 }
674 700
675 void MetricsLog::WriteAllProfilesMetrics( 701 void MetricsLog::WriteAllProfilesMetrics(
676 const DictionaryValue& all_profiles_metrics) { 702 const DictionaryValue& all_profiles_metrics) {
677 const std::string profile_prefix(prefs::kProfilePrefix); 703 const std::string profile_prefix(prefs::kProfilePrefix);
678 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys(); 704 for (DictionaryValue::key_iterator i = all_profiles_metrics.begin_keys();
679 i != all_profiles_metrics.end_keys(); ++i) { 705 i != all_profiles_metrics.end_keys(); ++i) {
680 const std::string& key_name = *i; 706 const std::string& key_name = *i;
681 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) { 707 if (key_name.compare(0, profile_prefix.size(), profile_prefix) == 0) {
682 DictionaryValue* profile; 708 DictionaryValue* profile;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 755
730 default: 756 default:
731 NOTREACHED(); 757 NOTREACHED();
732 break; 758 break;
733 } 759 }
734 } 760 }
735 } 761 }
736 } 762 }
737 763
738 void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { 764 void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) {
739 DCHECK(!locked_); 765 DCHECK(!locked());
740 766
741 // Write the XML version. 767 // Write the XML version.
742 OPEN_ELEMENT_FOR_SCOPE("uielement"); 768 OPEN_ELEMENT_FOR_SCOPE("uielement");
743 WriteAttribute("action", "autocomplete"); 769 WriteAttribute("action", "autocomplete");
744 WriteAttribute("targetidhash", ""); 770 WriteAttribute("targetidhash", "");
745 // TODO(kochi): Properly track windows. 771 // TODO(kochi): Properly track windows.
746 WriteIntAttribute("window", 0); 772 WriteIntAttribute("window", 0);
747 if (log.tab_id != -1) { 773 if (log.tab_id != -1) {
748 // If we know what tab the autocomplete URL was opened in, log it. 774 // If we know what tab the autocomplete URL was opened in, log it.
749 WriteIntAttribute("tab", static_cast<int>(log.tab_id)); 775 WriteIntAttribute("tab", static_cast<int>(log.tab_id));
(...skipping 28 matching lines...) Expand all
778 WriteAttribute("provider", i->provider->name()); 804 WriteAttribute("provider", i->provider->name());
779 const std::string result_type(AutocompleteMatch::TypeToString(i->type)); 805 const std::string result_type(AutocompleteMatch::TypeToString(i->type));
780 if (!result_type.empty()) 806 if (!result_type.empty())
781 WriteAttribute("resulttype", result_type); 807 WriteAttribute("resulttype", result_type);
782 WriteIntAttribute("relevance", i->relevance); 808 WriteIntAttribute("relevance", i->relevance);
783 WriteIntAttribute("isstarred", i->starred ? 1 : 0); 809 WriteIntAttribute("isstarred", i->starred ? 1 : 0);
784 } 810 }
785 } 811 }
786 812
787 // Write the protobuf version. 813 // Write the protobuf version.
788 OmniboxEventProto* omnibox_event = uma_proto_.add_omnibox_event(); 814 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event();
789 omnibox_event->set_time(MetricsLogBase::GetCurrentTime()); 815 omnibox_event->set_time(MetricsLogBase::GetCurrentTime());
jar (doing other things) 2012/03/01 05:32:42 I think this is the same pattern that had me wonde
790 if (log.tab_id != -1) { 816 if (log.tab_id != -1) {
791 // If we know what tab the autocomplete URL was opened in, log it. 817 // If we know what tab the autocomplete URL was opened in, log it.
792 omnibox_event->set_tab_id(log.tab_id); 818 omnibox_event->set_tab_id(log.tab_id);
793 } 819 }
794 omnibox_event->set_typed_length(log.text.length()); 820 omnibox_event->set_typed_length(log.text.length());
795 omnibox_event->set_selected_index(log.selected_index); 821 omnibox_event->set_selected_index(log.selected_index);
796 omnibox_event->set_completed_length(log.inline_autocompleted_length); 822 omnibox_event->set_completed_length(log.inline_autocompleted_length);
797 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type)); 823 omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type));
798 for (AutocompleteResult::const_iterator i(log.result.begin()); 824 for (AutocompleteResult::const_iterator i(log.result.begin());
799 i != log.result.end(); ++i) { 825 i != log.result.end(); ++i) {
800 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); 826 OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion();
801 suggestion->set_provider(AsOmniboxEventProviderType(i->provider)); 827 suggestion->set_provider(AsOmniboxEventProviderType(i->provider));
802 suggestion->set_result_type(AsOmniboxEventResultType(i->type)); 828 suggestion->set_result_type(AsOmniboxEventResultType(i->type));
803 suggestion->set_relevance(i->relevance); 829 suggestion->set_relevance(i->relevance);
804 suggestion->set_is_starred(i->starred); 830 suggestion->set_is_starred(i->starred);
805 } 831 }
806 832
807 ++num_events_; 833 ++num_events_;
808 } 834 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698