[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | cd1adc2 | 2009-01-16 01:29:22 | [diff] [blame] | 5 | #include "chrome/browser/metrics/metrics_log.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 12 | #include "base/bind.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include "base/file_util.h" |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 14 | #include "base/lazy_instance.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 15 | #include "base/memory/scoped_ptr.h" |
[email protected] | 85ed9d4 | 2010-06-08 22:37:44 | [diff] [blame] | 16 | #include "base/perftimer.h" |
[email protected] | 3853a4c | 2013-02-11 17:15:57 | [diff] [blame] | 17 | #include "base/prefs/pref_registry_simple.h" |
| 18 | #include "base/prefs/pref_service.h" |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 19 | #include "base/profiler/alternate_timer.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | #include "base/string_util.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 21 | #include "base/strings/string_number_conversions.h" |
[email protected] | fadf97f | 2008-09-18 12:18:14 | [diff] [blame] | 22 | #include "base/sys_info.h" |
[email protected] | 37f39e4 | 2010-01-06 17:35:17 | [diff] [blame] | 23 | #include "base/third_party/nspr/prtime.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 24 | #include "base/time.h" |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 25 | #include "base/tracked_objects.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 26 | #include "base/utf_string_conversions.h" |
[email protected] | 9f8bc2f | 2012-07-03 16:26:53 | [diff] [blame] | 27 | #include "chrome/browser/autocomplete/autocomplete_input.h" |
[email protected] | 19871a9 | 2012-06-27 19:50:32 | [diff] [blame] | 28 | #include "chrome/browser/autocomplete/autocomplete_log.h" |
[email protected] | 9ac4009 | 2010-10-27 23:05:26 | [diff] [blame] | 29 | #include "chrome/browser/autocomplete/autocomplete_match.h" |
[email protected] | 30f5bc9 | 2012-06-26 04:14:55 | [diff] [blame] | 30 | #include "chrome/browser/autocomplete/autocomplete_provider.h" |
[email protected] | 73c2b163 | 2012-07-02 22:51:38 | [diff] [blame] | 31 | #include "chrome/browser/autocomplete/autocomplete_result.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | #include "chrome/browser/browser_process.h" |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 33 | #include "chrome/browser/google/google_util.h" |
[email protected] | 0f5e57f5 | 2012-09-20 20:53:18 | [diff] [blame] | 34 | #include "chrome/browser/plugins/plugin_prefs.h" |
[email protected] | 1008498 | 2011-08-19 17:56:56 | [diff] [blame] | 35 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 36 | #include "chrome/common/chrome_process_type.h" |
[email protected] | 1eeb5e0 | 2010-07-20 23:02:11 | [diff] [blame] | 37 | #include "chrome/common/chrome_version_info.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 38 | #include "chrome/common/logging_chrome.h" |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 39 | #include "chrome/common/metrics/proto/omnibox_event.pb.h" |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 40 | #include "chrome/common/metrics/proto/profiler_event.pb.h" |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 41 | #include "chrome/common/metrics/proto/system_profile.pb.h" |
[email protected] | cf265dc0 | 2012-08-15 01:01:16 | [diff] [blame] | 42 | #include "chrome/common/metrics/variations/variations_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | #include "chrome/common/pref_names.h" |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 44 | #include "chrome/installer/util/google_update_settings.h" |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 45 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 1a838cc | 2012-04-24 22:06:49 | [diff] [blame] | 46 | #include "content/public/common/content_client.h" |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 47 | #include "content/public/common/gpu_info.h" |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 48 | #include "device/bluetooth/bluetooth_adapter.h" |
| 49 | #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 50 | #include "device/bluetooth/bluetooth_device.h" |
[email protected] | 46072d4 | 2008-07-28 14:49:35 | [diff] [blame] | 51 | #include "googleurl/src/gurl.h" |
[email protected] | 6b7d954ff | 2011-10-25 00:39:35 | [diff] [blame] | 52 | #include "ui/gfx/screen.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 53 | #include "webkit/plugins/webplugininfo.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | |
[email protected] | 5106b3a | 2012-10-03 20:10:44 | [diff] [blame] | 55 | #if defined(OS_ANDROID) |
| 56 | #include "base/android/build_info.h" |
| 57 | #endif |
| 58 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | #define OPEN_ELEMENT_FOR_SCOPE(name) ScopedElement scoped_element(this, name) |
| 60 | |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 61 | #if defined(OS_WIN) |
[email protected] | 1bb25e0 | 2012-08-03 22:39:39 | [diff] [blame] | 62 | #include "base/win/metro.h" |
[email protected] | e245ace9 | 2013-05-07 00:37:41 | [diff] [blame^] | 63 | #include "ui/base/win/dpi.h" |
[email protected] | 1bb25e0 | 2012-08-03 22:39:39 | [diff] [blame] | 64 | |
| 65 | // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 66 | extern "C" IMAGE_DOS_HEADER __ImageBase; |
| 67 | #endif |
| 68 | |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 69 | using content::GpuDataManager; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 70 | using metrics::OmniboxEventProto; |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 71 | using metrics::PerfDataProto; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 72 | using metrics::ProfilerEventProto; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 73 | using metrics::SystemProfileProto; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 74 | using tracked_objects::ProcessDataSnapshot; |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 75 | typedef chrome_variations::ActiveGroupId ActiveGroupId; |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 76 | typedef SystemProfileProto::GoogleUpdate::ProductInfo ProductInfo; |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 77 | typedef SystemProfileProto::Hardware::Bluetooth::PairedDevice PairedDevice; |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 78 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 79 | namespace { |
| 80 | |
| 81 | // Returns the date at which the current metrics client ID was created as |
[email protected] | ca5ac4b | 2012-12-14 07:46:40 | [diff] [blame] | 82 | // a string containing seconds since the epoch, or "0" if none was found. |
[email protected] | cc5d7f4 | 2012-10-30 00:30:09 | [diff] [blame] | 83 | std::string GetMetricsEnabledDate(PrefService* pref) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 84 | if (!pref) { |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 85 | NOTREACHED(); |
| 86 | return "0"; |
| 87 | } |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 88 | |
| 89 | return pref->GetString(prefs::kMetricsClientIDTimestamp); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 90 | } |
| 91 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 92 | OmniboxEventProto::InputType AsOmniboxEventInputType( |
| 93 | AutocompleteInput::Type type) { |
| 94 | switch (type) { |
| 95 | case AutocompleteInput::INVALID: |
| 96 | return OmniboxEventProto::INVALID; |
| 97 | case AutocompleteInput::UNKNOWN: |
| 98 | return OmniboxEventProto::UNKNOWN; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 99 | case AutocompleteInput::URL: |
| 100 | return OmniboxEventProto::URL; |
| 101 | case AutocompleteInput::QUERY: |
| 102 | return OmniboxEventProto::QUERY; |
| 103 | case AutocompleteInput::FORCED_QUERY: |
| 104 | return OmniboxEventProto::FORCED_QUERY; |
| 105 | default: |
| 106 | NOTREACHED(); |
| 107 | return OmniboxEventProto::INVALID; |
| 108 | } |
| 109 | } |
| 110 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 111 | OmniboxEventProto::Suggestion::ResultType AsOmniboxEventResultType( |
| 112 | AutocompleteMatch::Type type) { |
| 113 | switch (type) { |
| 114 | case AutocompleteMatch::URL_WHAT_YOU_TYPED: |
| 115 | return OmniboxEventProto::Suggestion::URL_WHAT_YOU_TYPED; |
| 116 | case AutocompleteMatch::HISTORY_URL: |
| 117 | return OmniboxEventProto::Suggestion::HISTORY_URL; |
| 118 | case AutocompleteMatch::HISTORY_TITLE: |
| 119 | return OmniboxEventProto::Suggestion::HISTORY_TITLE; |
| 120 | case AutocompleteMatch::HISTORY_BODY: |
| 121 | return OmniboxEventProto::Suggestion::HISTORY_BODY; |
| 122 | case AutocompleteMatch::HISTORY_KEYWORD: |
| 123 | return OmniboxEventProto::Suggestion::HISTORY_KEYWORD; |
| 124 | case AutocompleteMatch::NAVSUGGEST: |
| 125 | return OmniboxEventProto::Suggestion::NAVSUGGEST; |
| 126 | case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: |
| 127 | return OmniboxEventProto::Suggestion::SEARCH_WHAT_YOU_TYPED; |
| 128 | case AutocompleteMatch::SEARCH_HISTORY: |
| 129 | return OmniboxEventProto::Suggestion::SEARCH_HISTORY; |
| 130 | case AutocompleteMatch::SEARCH_SUGGEST: |
| 131 | return OmniboxEventProto::Suggestion::SEARCH_SUGGEST; |
| 132 | case AutocompleteMatch::SEARCH_OTHER_ENGINE: |
| 133 | return OmniboxEventProto::Suggestion::SEARCH_OTHER_ENGINE; |
| 134 | case AutocompleteMatch::EXTENSION_APP: |
| 135 | return OmniboxEventProto::Suggestion::EXTENSION_APP; |
[email protected] | dbacefb | 2012-09-12 03:32:06 | [diff] [blame] | 136 | case AutocompleteMatch::CONTACT: |
| 137 | return OmniboxEventProto::Suggestion::CONTACT; |
[email protected] | 2532060 | 2012-10-18 22:05:56 | [diff] [blame] | 138 | case AutocompleteMatch::BOOKMARK_TITLE: |
| 139 | return OmniboxEventProto::Suggestion::BOOKMARK_TITLE; |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 140 | default: |
| 141 | NOTREACHED(); |
| 142 | return OmniboxEventProto::Suggestion::UNKNOWN_RESULT_TYPE; |
| 143 | } |
| 144 | } |
| 145 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 146 | ProfilerEventProto::TrackedObject::ProcessType AsProtobufProcessType( |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 147 | int process_type) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 148 | switch (process_type) { |
| 149 | case content::PROCESS_TYPE_BROWSER: |
| 150 | return ProfilerEventProto::TrackedObject::BROWSER; |
| 151 | case content::PROCESS_TYPE_RENDERER: |
| 152 | return ProfilerEventProto::TrackedObject::RENDERER; |
| 153 | case content::PROCESS_TYPE_PLUGIN: |
| 154 | return ProfilerEventProto::TrackedObject::PLUGIN; |
| 155 | case content::PROCESS_TYPE_WORKER: |
| 156 | return ProfilerEventProto::TrackedObject::WORKER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 157 | case content::PROCESS_TYPE_UTILITY: |
| 158 | return ProfilerEventProto::TrackedObject::UTILITY; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 159 | case content::PROCESS_TYPE_ZYGOTE: |
| 160 | return ProfilerEventProto::TrackedObject::ZYGOTE; |
| 161 | case content::PROCESS_TYPE_SANDBOX_HELPER: |
| 162 | return ProfilerEventProto::TrackedObject::SANDBOX_HELPER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 163 | case content::PROCESS_TYPE_GPU: |
| 164 | return ProfilerEventProto::TrackedObject::GPU; |
| 165 | case content::PROCESS_TYPE_PPAPI_PLUGIN: |
| 166 | return ProfilerEventProto::TrackedObject::PPAPI_PLUGIN; |
| 167 | case content::PROCESS_TYPE_PPAPI_BROKER: |
| 168 | return ProfilerEventProto::TrackedObject::PPAPI_BROKER; |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 169 | case PROCESS_TYPE_PROFILE_IMPORT: |
| 170 | return ProfilerEventProto::TrackedObject::PROFILE_IMPORT; |
| 171 | case PROCESS_TYPE_NACL_LOADER: |
| 172 | return ProfilerEventProto::TrackedObject::NACL_LOADER; |
| 173 | case PROCESS_TYPE_NACL_BROKER: |
| 174 | return ProfilerEventProto::TrackedObject::NACL_BROKER; |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 175 | default: |
| 176 | NOTREACHED(); |
| 177 | return ProfilerEventProto::TrackedObject::UNKNOWN; |
| 178 | } |
| 179 | } |
| 180 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 181 | // Returns the plugin preferences corresponding for this user, if available. |
| 182 | // If multiple user profiles are loaded, returns the preferences corresponding |
| 183 | // to an arbitrary one of the profiles. |
| 184 | PluginPrefs* GetPluginPrefs() { |
| 185 | ProfileManager* profile_manager = g_browser_process->profile_manager(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 186 | |
| 187 | if (!profile_manager) { |
| 188 | // The profile manager can be NULL when testing. |
| 189 | return NULL; |
| 190 | } |
| 191 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 192 | std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 193 | if (profiles.empty()) |
| 194 | return NULL; |
| 195 | |
| 196 | return PluginPrefs::GetForProfile(profiles.front()); |
| 197 | } |
| 198 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 199 | // Fills |plugin| with the info contained in |plugin_info| and |plugin_prefs|. |
| 200 | void SetPluginInfo(const webkit::WebPluginInfo& plugin_info, |
| 201 | const PluginPrefs* plugin_prefs, |
| 202 | SystemProfileProto::Plugin* plugin) { |
| 203 | plugin->set_name(UTF16ToUTF8(plugin_info.name)); |
| 204 | plugin->set_filename(plugin_info.path.BaseName().AsUTF8Unsafe()); |
| 205 | plugin->set_version(UTF16ToUTF8(plugin_info.version)); |
| 206 | if (plugin_prefs) |
| 207 | plugin->set_is_disabled(!plugin_prefs->IsPluginEnabled(plugin_info)); |
| 208 | } |
| 209 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 210 | void WriteFieldTrials(const std::vector<ActiveGroupId>& field_trial_ids, |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 211 | SystemProfileProto* system_profile) { |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 212 | for (std::vector<ActiveGroupId>::const_iterator it = |
[email protected] | ad2461c | 2012-04-27 21:11:03 | [diff] [blame] | 213 | field_trial_ids.begin(); it != field_trial_ids.end(); ++it) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 214 | SystemProfileProto::FieldTrial* field_trial = |
| 215 | system_profile->add_field_trial(); |
| 216 | field_trial->set_name_id(it->name); |
| 217 | field_trial->set_group_id(it->group); |
| 218 | } |
| 219 | } |
| 220 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 221 | void WriteProfilerData(const ProcessDataSnapshot& profiler_data, |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 222 | int process_type, |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 223 | ProfilerEventProto* performance_profile) { |
| 224 | for (std::vector<tracked_objects::TaskSnapshot>::const_iterator it = |
| 225 | profiler_data.tasks.begin(); |
| 226 | it != profiler_data.tasks.end(); ++it) { |
| 227 | std::string ignored; |
| 228 | uint64 birth_thread_name_hash; |
| 229 | uint64 exec_thread_name_hash; |
| 230 | uint64 source_file_name_hash; |
| 231 | uint64 source_function_name_hash; |
| 232 | MetricsLogBase::CreateHashes(it->birth.thread_name, |
| 233 | &ignored, &birth_thread_name_hash); |
| 234 | MetricsLogBase::CreateHashes(it->death_thread_name, |
| 235 | &ignored, &exec_thread_name_hash); |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 236 | MetricsLogBase::CreateHashes(it->birth.location.file_name, |
[email protected] | 0416226 | 2012-10-23 01:17:25 | [diff] [blame] | 237 | &ignored, &source_file_name_hash); |
| 238 | MetricsLogBase::CreateHashes(it->birth.location.function_name, |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 239 | &ignored, &source_function_name_hash); |
| 240 | |
| 241 | const tracked_objects::DeathDataSnapshot& death_data = it->death_data; |
| 242 | ProfilerEventProto::TrackedObject* tracked_object = |
| 243 | performance_profile->add_tracked_object(); |
| 244 | tracked_object->set_birth_thread_name_hash(birth_thread_name_hash); |
| 245 | tracked_object->set_exec_thread_name_hash(exec_thread_name_hash); |
| 246 | tracked_object->set_source_file_name_hash(source_file_name_hash); |
| 247 | tracked_object->set_source_function_name_hash(source_function_name_hash); |
| 248 | tracked_object->set_source_line_number(it->birth.location.line_number); |
| 249 | tracked_object->set_exec_count(death_data.count); |
| 250 | tracked_object->set_exec_time_total(death_data.run_duration_sum); |
| 251 | tracked_object->set_exec_time_sampled(death_data.run_duration_sample); |
| 252 | tracked_object->set_queue_time_total(death_data.queue_duration_sum); |
| 253 | tracked_object->set_queue_time_sampled(death_data.queue_duration_sample); |
| 254 | tracked_object->set_process_type(AsProtobufProcessType(process_type)); |
| 255 | tracked_object->set_process_id(profiler_data.process_id); |
| 256 | } |
| 257 | } |
| 258 | |
[email protected] | 59a7ae4e | 2012-10-01 23:54:44 | [diff] [blame] | 259 | #if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 260 | void ProductDataToProto(const GoogleUpdateSettings::ProductData& product_data, |
| 261 | ProductInfo* product_info) { |
| 262 | product_info->set_version(product_data.version); |
| 263 | product_info->set_last_update_success_timestamp( |
| 264 | product_data.last_success.ToTimeT()); |
| 265 | product_info->set_last_error(product_data.last_error_code); |
| 266 | product_info->set_last_extra_error(product_data.last_extra_code); |
| 267 | if (ProductInfo::InstallResult_IsValid(product_data.last_result)) { |
| 268 | product_info->set_last_result( |
| 269 | static_cast<ProductInfo::InstallResult>(product_data.last_result)); |
| 270 | } |
| 271 | } |
[email protected] | 59a7ae4e | 2012-10-01 23:54:44 | [diff] [blame] | 272 | #endif |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 273 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 274 | #if defined(OS_WIN) |
| 275 | struct ScreenDPIInformation{ |
| 276 | double max_dpi_x; |
| 277 | double max_dpi_y; |
| 278 | }; |
| 279 | |
| 280 | // Called once for each connected monitor. |
| 281 | BOOL CALLBACK GetMonitorDPICallback(HMONITOR, HDC hdc, LPRECT, LPARAM dwData) { |
| 282 | const double kMillimetersPerInch = 25.4; |
| 283 | ScreenDPIInformation* screen_info = |
| 284 | reinterpret_cast<ScreenDPIInformation*>(dwData); |
| 285 | // Size of screen, in mm. |
| 286 | DWORD size_x = GetDeviceCaps(hdc, HORZSIZE); |
| 287 | DWORD size_y = GetDeviceCaps(hdc, VERTSIZE); |
| 288 | double dpi_x = (size_x > 0) ? |
| 289 | GetDeviceCaps(hdc, HORZRES) / (size_x / kMillimetersPerInch) : 0; |
| 290 | double dpi_y = (size_y > 0) ? |
| 291 | GetDeviceCaps(hdc, VERTRES) / (size_y / kMillimetersPerInch) : 0; |
[email protected] | e245ace9 | 2013-05-07 00:37:41 | [diff] [blame^] | 292 | dpi_x *= ui::win::GetUndocumentedDPIScale(); |
| 293 | dpi_y *= ui::win::GetUndocumentedDPIScale(); |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 294 | screen_info->max_dpi_x = std::max(dpi_x, screen_info->max_dpi_x); |
| 295 | screen_info->max_dpi_y = std::max(dpi_y, screen_info->max_dpi_y); |
| 296 | return TRUE; |
| 297 | } |
| 298 | |
| 299 | void WriteScreenDPIInformationProto(SystemProfileProto::Hardware* hardware) { |
| 300 | HDC desktop_dc = GetDC(NULL); |
| 301 | if (desktop_dc) { |
| 302 | ScreenDPIInformation si = {0,0}; |
| 303 | if (EnumDisplayMonitors(desktop_dc, NULL, GetMonitorDPICallback, |
| 304 | reinterpret_cast<LPARAM>(&si))) { |
| 305 | hardware->set_max_dpi_x(si.max_dpi_x); |
| 306 | hardware->set_max_dpi_y(si.max_dpi_y); |
| 307 | } |
| 308 | ReleaseDC(GetDesktopWindow(), desktop_dc); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | #endif // defined(OS_WIN) |
| 313 | |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 314 | #if defined(OS_CHROMEOS) |
| 315 | PairedDevice::Type AsBluetoothDeviceType( |
| 316 | enum device::BluetoothDevice::DeviceType device_type) { |
| 317 | switch (device_type) { |
| 318 | case device::BluetoothDevice::DEVICE_UNKNOWN: |
| 319 | return PairedDevice::DEVICE_UNKNOWN; |
| 320 | case device::BluetoothDevice::DEVICE_COMPUTER: |
| 321 | return PairedDevice::DEVICE_COMPUTER; |
| 322 | case device::BluetoothDevice::DEVICE_PHONE: |
| 323 | return PairedDevice::DEVICE_PHONE; |
| 324 | case device::BluetoothDevice::DEVICE_MODEM: |
| 325 | return PairedDevice::DEVICE_MODEM; |
| 326 | case device::BluetoothDevice::DEVICE_AUDIO: |
| 327 | return PairedDevice::DEVICE_AUDIO; |
| 328 | case device::BluetoothDevice::DEVICE_CAR_AUDIO: |
| 329 | return PairedDevice::DEVICE_CAR_AUDIO; |
| 330 | case device::BluetoothDevice::DEVICE_VIDEO: |
| 331 | return PairedDevice::DEVICE_VIDEO; |
| 332 | case device::BluetoothDevice::DEVICE_PERIPHERAL: |
| 333 | return PairedDevice::DEVICE_PERIPHERAL; |
| 334 | case device::BluetoothDevice::DEVICE_JOYSTICK: |
| 335 | return PairedDevice::DEVICE_JOYSTICK; |
| 336 | case device::BluetoothDevice::DEVICE_GAMEPAD: |
| 337 | return PairedDevice::DEVICE_GAMEPAD; |
| 338 | case device::BluetoothDevice::DEVICE_KEYBOARD: |
| 339 | return PairedDevice::DEVICE_KEYBOARD; |
| 340 | case device::BluetoothDevice::DEVICE_MOUSE: |
| 341 | return PairedDevice::DEVICE_MOUSE; |
| 342 | case device::BluetoothDevice::DEVICE_TABLET: |
| 343 | return PairedDevice::DEVICE_TABLET; |
| 344 | case device::BluetoothDevice::DEVICE_KEYBOARD_MOUSE_COMBO: |
| 345 | return PairedDevice::DEVICE_KEYBOARD_MOUSE_COMBO; |
| 346 | } |
| 347 | |
| 348 | NOTREACHED(); |
| 349 | return PairedDevice::DEVICE_UNKNOWN; |
| 350 | } |
| 351 | #endif // defined(OS_CHROMEOS) |
| 352 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 353 | } // namespace |
| 354 | |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 355 | GoogleUpdateMetrics::GoogleUpdateMetrics() : is_system_install(false) {} |
| 356 | |
| 357 | GoogleUpdateMetrics::~GoogleUpdateMetrics() {} |
| 358 | |
[email protected] | 67f92bc3 | 2012-01-26 01:56:19 | [diff] [blame] | 359 | static base::LazyInstance<std::string>::Leaky |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 360 | g_version_extension = LAZY_INSTANCE_INITIALIZER; |
| 361 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 362 | MetricsLog::MetricsLog(const std::string& client_id, int session_id) |
[email protected] | 5eae204c | 2013-02-13 15:53:42 | [diff] [blame] | 363 | : MetricsLogBase(client_id, session_id, MetricsLog::GetVersionString()) {} |
[email protected] | 5ed7d457 | 2009-12-23 17:42:41 | [diff] [blame] | 364 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 365 | MetricsLog::~MetricsLog() {} |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 366 | |
| 367 | // static |
[email protected] | b1de2c7 | 2013-02-06 02:45:47 | [diff] [blame] | 368 | void MetricsLog::RegisterPrefs(PrefRegistrySimple* registry) { |
| 369 | registry->RegisterListPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 370 | } |
| 371 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 372 | // static |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 373 | int64 MetricsLog::GetIncrementalUptime(PrefService* pref) { |
| 374 | base::TimeTicks now = base::TimeTicks::Now(); |
| 375 | static base::TimeTicks last_updated_time(now); |
| 376 | int64 incremental_time = (now - last_updated_time).InSeconds(); |
| 377 | last_updated_time = now; |
| 378 | |
| 379 | if (incremental_time > 0) { |
| 380 | int64 metrics_uptime = pref->GetInt64(prefs::kUninstallMetricsUptimeSec); |
| 381 | metrics_uptime += incremental_time; |
| 382 | pref->SetInt64(prefs::kUninstallMetricsUptimeSec, metrics_uptime); |
| 383 | } |
| 384 | |
| 385 | return incremental_time; |
| 386 | } |
| 387 | |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 388 | // static |
| 389 | std::string MetricsLog::GetVersionString() { |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 390 | chrome::VersionInfo version_info; |
[email protected] | 30c9180 | 2010-12-18 00:40:17 | [diff] [blame] | 391 | if (!version_info.is_valid()) { |
| 392 | NOTREACHED() << "Unable to retrieve version info."; |
| 393 | return std::string(); |
| 394 | } |
| 395 | |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 396 | std::string version = version_info.Version(); |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 397 | if (!version_extension().empty()) |
| 398 | version += version_extension(); |
[email protected] | 0211f57e | 2010-08-27 20:28:42 | [diff] [blame] | 399 | if (!version_info.IsOfficialBuild()) |
| 400 | version.append("-devel"); |
| 401 | return version; |
[email protected] | 1226abb | 2010-06-10 18:01:28 | [diff] [blame] | 402 | } |
| 403 | |
[email protected] | 054c801 | 2011-11-16 00:12:42 | [diff] [blame] | 404 | // static |
| 405 | void MetricsLog::set_version_extension(const std::string& extension) { |
| 406 | g_version_extension.Get() = extension; |
| 407 | } |
| 408 | |
| 409 | // static |
| 410 | const std::string& MetricsLog::version_extension() { |
| 411 | return g_version_extension.Get(); |
| 412 | } |
| 413 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 414 | void MetricsLog::RecordIncrementalStabilityElements( |
| 415 | const std::vector<webkit::WebPluginInfo>& plugin_list) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 416 | DCHECK(!locked()); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 417 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 418 | PrefService* pref = GetPrefService(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 419 | DCHECK(pref); |
| 420 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 421 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
| 422 | WriteCommonEventAttributes(); |
| 423 | |
[email protected] | 9958a32 | 2011-03-08 20:04:17 | [diff] [blame] | 424 | WriteInstallElement(); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 425 | |
| 426 | { |
| 427 | OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. |
| 428 | WriteRequiredStabilityAttributes(pref); |
| 429 | WriteRealtimeStabilityAttributes(pref); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 430 | WritePluginStabilityElements(plugin_list, pref); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 431 | } |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 434 | PrefService* MetricsLog::GetPrefService() { |
| 435 | return g_browser_process->local_state(); |
| 436 | } |
| 437 | |
| 438 | gfx::Size MetricsLog::GetScreenSize() const { |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 439 | return gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 440 | } |
| 441 | |
[email protected] | aa9641797 | 2012-08-22 03:16:44 | [diff] [blame] | 442 | float MetricsLog::GetScreenDeviceScaleFactor() const { |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 443 | return gfx::Screen::GetNativeScreen()-> |
| 444 | GetPrimaryDisplay().device_scale_factor(); |
[email protected] | aa9641797 | 2012-08-22 03:16:44 | [diff] [blame] | 445 | } |
| 446 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 447 | int MetricsLog::GetScreenCount() const { |
[email protected] | ffabb1e | 2012-10-12 19:51:17 | [diff] [blame] | 448 | // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312 |
| 449 | return gfx::Screen::GetNativeScreen()->GetNumDisplays(); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 450 | } |
| 451 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 452 | void MetricsLog::GetFieldTrialIds( |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 453 | std::vector<ActiveGroupId>* field_trial_ids) const { |
| 454 | chrome_variations::GetFieldTrialActiveGroupIds(field_trial_ids); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 457 | void MetricsLog::WriteStabilityElement( |
| 458 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 459 | PrefService* pref) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 460 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 461 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 462 | // Get stability attributes out of Local State, zeroing out stored values. |
| 463 | // NOTE: This could lead to some data loss if this report isn't successfully |
| 464 | // sent, but that's true for all the metrics. |
| 465 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 466 | OPEN_ELEMENT_FOR_SCOPE("stability"); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 467 | WriteRequiredStabilityAttributes(pref); |
| 468 | WriteRealtimeStabilityAttributes(pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 469 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 470 | int incomplete_shutdown_count = |
| 471 | pref->GetInteger(prefs::kStabilityIncompleteSessionEndCount); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 472 | pref->SetInteger(prefs::kStabilityIncompleteSessionEndCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 473 | int breakpad_registration_success_count = |
| 474 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationSuccess); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 475 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationSuccess, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 476 | int breakpad_registration_failure_count = |
| 477 | pref->GetInteger(prefs::kStabilityBreakpadRegistrationFail); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 478 | pref->SetInteger(prefs::kStabilityBreakpadRegistrationFail, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 479 | int debugger_present_count = |
| 480 | pref->GetInteger(prefs::kStabilityDebuggerPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 481 | pref->SetInteger(prefs::kStabilityDebuggerPresent, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 482 | int debugger_not_present_count = |
| 483 | pref->GetInteger(prefs::kStabilityDebuggerNotPresent); |
[email protected] | e324f6b | 2012-02-28 05:43:37 | [diff] [blame] | 484 | pref->SetInteger(prefs::kStabilityDebuggerNotPresent, 0); |
[email protected] | b2a4812d | 2012-02-28 05:31:31 | [diff] [blame] | 485 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 486 | // TODO(jar): The following are all optional, so we *could* optimize them for |
| 487 | // values of zero (and not include them). |
| 488 | |
| 489 | // Write the XML version. |
| 490 | WriteIntAttribute("incompleteshutdowncount", incomplete_shutdown_count); |
| 491 | WriteIntAttribute("breakpadregistrationok", |
| 492 | breakpad_registration_success_count); |
| 493 | WriteIntAttribute("breakpadregistrationfail", |
| 494 | breakpad_registration_failure_count); |
| 495 | WriteIntAttribute("debuggerpresent", debugger_present_count); |
| 496 | WriteIntAttribute("debuggernotpresent", debugger_not_present_count); |
| 497 | |
| 498 | // Write the protobuf version. |
| 499 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 500 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 501 | stability->set_incomplete_shutdown_count(incomplete_shutdown_count); |
| 502 | stability->set_breakpad_registration_success_count( |
| 503 | breakpad_registration_success_count); |
| 504 | stability->set_breakpad_registration_failure_count( |
| 505 | breakpad_registration_failure_count); |
| 506 | stability->set_debugger_present_count(debugger_present_count); |
| 507 | stability->set_debugger_not_present_count(debugger_not_present_count); |
| 508 | |
| 509 | WritePluginStabilityElements(plugin_list, pref); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 510 | } |
| 511 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 512 | void MetricsLog::WritePluginStabilityElements( |
| 513 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 514 | PrefService* pref) { |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 515 | // Now log plugin stability info. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 516 | const ListValue* plugin_stats_list = pref->GetList( |
| 517 | prefs::kStabilityPluginStats); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 518 | if (!plugin_stats_list) |
| 519 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 520 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 521 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 522 | |
| 523 | #if defined(ENABLE_PLUGINS) |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 524 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 525 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 526 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 527 | for (ListValue::const_iterator iter = plugin_stats_list->begin(); |
| 528 | iter != plugin_stats_list->end(); ++iter) { |
| 529 | if (!(*iter)->IsType(Value::TYPE_DICTIONARY)) { |
| 530 | NOTREACHED(); |
| 531 | continue; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 532 | } |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 533 | DictionaryValue* plugin_dict = static_cast<DictionaryValue*>(*iter); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 534 | |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 535 | std::string plugin_name; |
| 536 | plugin_dict->GetString(prefs::kStabilityPluginName, &plugin_name); |
| 537 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 538 | std::string base64_name_hash; |
| 539 | uint64 numeric_name_hash_ignored; |
| 540 | CreateHashes(plugin_name, &base64_name_hash, &numeric_name_hash_ignored); |
| 541 | |
| 542 | // Write the XML verison. |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 543 | OPEN_ELEMENT_FOR_SCOPE("pluginstability"); |
| 544 | // Use "filename" instead of "name", otherwise we need to update the |
| 545 | // UMA servers. |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 546 | WriteAttribute("filename", base64_name_hash); |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 547 | |
| 548 | int launches = 0; |
| 549 | plugin_dict->GetInteger(prefs::kStabilityPluginLaunches, &launches); |
| 550 | WriteIntAttribute("launchcount", launches); |
| 551 | |
| 552 | int instances = 0; |
| 553 | plugin_dict->GetInteger(prefs::kStabilityPluginInstances, &instances); |
| 554 | WriteIntAttribute("instancecount", instances); |
| 555 | |
| 556 | int crashes = 0; |
| 557 | plugin_dict->GetInteger(prefs::kStabilityPluginCrashes, &crashes); |
| 558 | WriteIntAttribute("crashcount", crashes); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 559 | |
| 560 | // Write the protobuf version. |
| 561 | // Note that this search is potentially a quadratic operation, but given the |
| 562 | // low number of plugins installed on a "reasonable" setup, this should be |
| 563 | // fine. |
| 564 | // TODO(isherman): Verify that this does not show up as a hotspot in |
| 565 | // profiler runs. |
| 566 | const webkit::WebPluginInfo* plugin_info = NULL; |
| 567 | const string16 plugin_name_utf16 = UTF8ToUTF16(plugin_name); |
| 568 | for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
| 569 | plugin_list.begin(); |
| 570 | iter != plugin_list.end(); ++iter) { |
| 571 | if (iter->name == plugin_name_utf16) { |
| 572 | plugin_info = &(*iter); |
| 573 | break; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | if (!plugin_info) { |
| 578 | NOTREACHED(); |
| 579 | continue; |
| 580 | } |
[email protected] | cd93707 | 2012-07-02 09:00:29 | [diff] [blame] | 581 | int loading_errors = 0; |
| 582 | plugin_dict->GetInteger(prefs::kStabilityPluginLoadingErrors, |
| 583 | &loading_errors); |
| 584 | WriteIntAttribute("loadingerrorcount", loading_errors); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 585 | |
[email protected] | cd93707 | 2012-07-02 09:00:29 | [diff] [blame] | 586 | // Write the protobuf version. |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 587 | SystemProfileProto::Stability::PluginStability* plugin_stability = |
| 588 | stability->add_plugin_stability(); |
| 589 | SetPluginInfo(*plugin_info, plugin_prefs, |
| 590 | plugin_stability->mutable_plugin()); |
| 591 | plugin_stability->set_launch_count(launches); |
| 592 | plugin_stability->set_instance_count(instances); |
| 593 | plugin_stability->set_crash_count(crashes); |
[email protected] | cd93707 | 2012-07-02 09:00:29 | [diff] [blame] | 594 | plugin_stability->set_loading_error_count(loading_errors); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 595 | } |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 596 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | 1df44b7 | 2012-01-19 05:20:34 | [diff] [blame] | 597 | |
| 598 | pref->ClearPref(prefs::kStabilityPluginStats); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 599 | } |
| 600 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 601 | // The server refuses data that doesn't have certain values. crashcount and |
| 602 | // launchcount are currently "required" in the "stability" group. |
| 603 | // TODO(isherman): Stop writing these attributes specially once the migration to |
| 604 | // protobufs is complete. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 605 | void MetricsLog::WriteRequiredStabilityAttributes(PrefService* pref) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 606 | int launch_count = pref->GetInteger(prefs::kStabilityLaunchCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 607 | pref->SetInteger(prefs::kStabilityLaunchCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 608 | int crash_count = pref->GetInteger(prefs::kStabilityCrashCount); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 609 | pref->SetInteger(prefs::kStabilityCrashCount, 0); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 610 | |
| 611 | // Write the XML version. |
| 612 | WriteIntAttribute("launchcount", launch_count); |
| 613 | WriteIntAttribute("crashcount", crash_count); |
| 614 | |
| 615 | // Write the protobuf version. |
| 616 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 617 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 618 | stability->set_launch_count(launch_count); |
| 619 | stability->set_crash_count(crash_count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 620 | } |
| 621 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 622 | void MetricsLog::WriteRealtimeStabilityAttributes(PrefService* pref) { |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 623 | // Update the stats which are critical for real-time stability monitoring. |
| 624 | // Since these are "optional," only list ones that are non-zero, as the counts |
| 625 | // are aggergated (summed) server side. |
| 626 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 627 | SystemProfileProto::Stability* stability = |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 628 | uma_proto()->mutable_system_profile()->mutable_stability(); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 629 | int count = pref->GetInteger(prefs::kStabilityPageLoadCount); |
| 630 | if (count) { |
| 631 | WriteIntAttribute("pageloadcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 632 | stability->set_page_load_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 633 | pref->SetInteger(prefs::kStabilityPageLoadCount, 0); |
| 634 | } |
| 635 | |
| 636 | count = pref->GetInteger(prefs::kStabilityRendererCrashCount); |
| 637 | if (count) { |
| 638 | WriteIntAttribute("renderercrashcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 639 | stability->set_renderer_crash_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 640 | pref->SetInteger(prefs::kStabilityRendererCrashCount, 0); |
| 641 | } |
| 642 | |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 643 | count = pref->GetInteger(prefs::kStabilityExtensionRendererCrashCount); |
| 644 | if (count) { |
| 645 | WriteIntAttribute("extensionrenderercrashcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 646 | stability->set_extension_renderer_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 647 | pref->SetInteger(prefs::kStabilityExtensionRendererCrashCount, 0); |
| 648 | } |
| 649 | |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 650 | count = pref->GetInteger(prefs::kStabilityRendererHangCount); |
| 651 | if (count) { |
| 652 | WriteIntAttribute("rendererhangcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 653 | stability->set_renderer_hang_count(count); |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 654 | pref->SetInteger(prefs::kStabilityRendererHangCount, 0); |
| 655 | } |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 656 | |
| 657 | count = pref->GetInteger(prefs::kStabilityChildProcessCrashCount); |
| 658 | if (count) { |
| 659 | WriteIntAttribute("childprocesscrashcount", count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 660 | stability->set_child_process_crash_count(count); |
[email protected] | 1f08562 | 2009-12-04 05:33:45 | [diff] [blame] | 661 | pref->SetInteger(prefs::kStabilityChildProcessCrashCount, 0); |
| 662 | } |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 663 | |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 664 | #if defined(OS_CHROMEOS) |
| 665 | count = pref->GetInteger(prefs::kStabilityOtherUserCrashCount); |
| 666 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 667 | stability->set_other_user_crash_count(count); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 668 | pref->SetInteger(prefs::kStabilityOtherUserCrashCount, 0); |
| 669 | } |
| 670 | |
| 671 | count = pref->GetInteger(prefs::kStabilityKernelCrashCount); |
| 672 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 673 | stability->set_kernel_crash_count(count); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 674 | pref->SetInteger(prefs::kStabilityKernelCrashCount, 0); |
| 675 | } |
| 676 | |
| 677 | count = pref->GetInteger(prefs::kStabilitySystemUncleanShutdownCount); |
| 678 | if (count) { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 679 | stability->set_unclean_system_shutdown_count(count); |
[email protected] | c1834a9 | 2011-01-21 18:21:03 | [diff] [blame] | 680 | pref->SetInteger(prefs::kStabilitySystemUncleanShutdownCount, 0); |
| 681 | } |
| 682 | #endif // OS_CHROMEOS |
| 683 | |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 684 | int64 recent_duration = GetIncrementalUptime(pref); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 685 | if (recent_duration) { |
[email protected] | 9165f74 | 2010-03-10 22:55:01 | [diff] [blame] | 686 | WriteInt64Attribute("uptimesec", recent_duration); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 687 | stability->set_uptime_sec(recent_duration); |
| 688 | } |
[email protected] | 0b33f80b | 2008-12-17 21:34:36 | [diff] [blame] | 689 | } |
| 690 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 691 | void MetricsLog::WritePluginList( |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 692 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 693 | bool write_as_xml) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 694 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 695 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 696 | OPEN_ELEMENT_FOR_SCOPE("plugins"); |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 697 | |
| 698 | #if defined(ENABLE_PLUGINS) |
| 699 | PluginPrefs* plugin_prefs = GetPluginPrefs(); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 700 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 701 | for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 702 | plugin_list.begin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 703 | iter != plugin_list.end(); ++iter) { |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 704 | if (write_as_xml) { |
| 705 | std::string base64_name_hash; |
| 706 | uint64 numeric_hash_ignored; |
| 707 | CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash, |
| 708 | &numeric_hash_ignored); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 709 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 710 | std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe(); |
| 711 | std::string base64_filename_hash; |
| 712 | CreateHashes(filename_bytes, &base64_filename_hash, |
| 713 | &numeric_hash_ignored); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 714 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 715 | // Write the XML version. |
| 716 | OPEN_ELEMENT_FOR_SCOPE("plugin"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 717 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 718 | // Plugin name and filename are hashed for the privacy of those |
| 719 | // testing unreleased new extensions. |
| 720 | WriteAttribute("name", base64_name_hash); |
| 721 | WriteAttribute("filename", base64_filename_hash); |
| 722 | WriteAttribute("version", UTF16ToUTF8(iter->version)); |
| 723 | if (plugin_prefs) |
| 724 | WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); |
| 725 | } else { |
| 726 | // Write the protobuf version. |
| 727 | SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); |
| 728 | SetPluginInfo(*iter, plugin_prefs, plugin); |
| 729 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 730 | } |
[email protected] | ebd7196 | 2012-12-20 02:56:55 | [diff] [blame] | 731 | #endif // defined(ENABLE_PLUGINS) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 732 | } |
| 733 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 734 | void MetricsLog::WriteInstallElement() { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 735 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 736 | // We'll write the protobuf version in RecordEnvironmentProto(). |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 737 | OPEN_ELEMENT_FOR_SCOPE("install"); |
[email protected] | cc5d7f4 | 2012-10-30 00:30:09 | [diff] [blame] | 738 | WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService())); |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 739 | WriteIntAttribute("buildid", 0); // We're using appversion instead. |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 740 | } |
| 741 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 742 | void MetricsLog::RecordEnvironment( |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 743 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 744 | const GoogleUpdateMetrics& google_update_metrics, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 745 | const DictionaryValue* profile_metrics) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 746 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 747 | |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 748 | PrefService* pref = GetPrefService(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 749 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 750 | OPEN_ELEMENT_FOR_SCOPE("profile"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 751 | WriteCommonEventAttributes(); |
| 752 | |
[email protected] | 147bbc0b | 2009-01-06 19:37:40 | [diff] [blame] | 753 | WriteInstallElement(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 754 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 755 | // Write the XML version. |
| 756 | // We'll write the protobuf version in RecordEnvironmentProto(). |
| 757 | bool write_as_xml = true; |
| 758 | WritePluginList(plugin_list, write_as_xml); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 759 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 760 | WriteStabilityElement(plugin_list, pref); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 761 | |
| 762 | { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 763 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 764 | // We'll write the protobuf version in RecordEnvironmentProto(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 765 | OPEN_ELEMENT_FOR_SCOPE("cpu"); |
[email protected] | 0b6a4fb | 2012-10-16 01:58:21 | [diff] [blame] | 766 | WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 770 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 771 | // We'll write the protobuf version in RecordEnvironmentProto(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 772 | OPEN_ELEMENT_FOR_SCOPE("memory"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 773 | WriteIntAttribute("mb", base::SysInfo::AmountOfPhysicalMemoryMB()); |
[email protected] | d1be67b | 2008-11-19 20:28:38 | [diff] [blame] | 774 | #if defined(OS_WIN) |
| 775 | WriteIntAttribute("dllbase", reinterpret_cast<int>(&__ImageBase)); |
| 776 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | { |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 780 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 781 | // We'll write the protobuf version in RecordEnvironmentProto(). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 782 | OPEN_ELEMENT_FOR_SCOPE("os"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 783 | WriteAttribute("name", base::SysInfo::OperatingSystemName()); |
| 784 | WriteAttribute("version", base::SysInfo::OperatingSystemVersion()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | { |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 788 | OPEN_ELEMENT_FOR_SCOPE("gpu"); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 789 | const content::GPUInfo& gpu_info = |
| 790 | GpuDataManager::GetInstance()->GetGPUInfo(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 791 | |
| 792 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 793 | // We'll write the protobuf version in RecordEnvironmentProto(). |
[email protected] | a094e2c | 2012-05-10 23:02:42 | [diff] [blame] | 794 | WriteIntAttribute("vendorid", gpu_info.gpu.vendor_id); |
| 795 | WriteIntAttribute("deviceid", gpu_info.gpu.device_id); |
[email protected] | e8c287c87 | 2010-07-20 00:49:42 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 799 | const gfx::Size display_size = GetScreenSize(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 800 | |
| 801 | // Write the XML version. |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 802 | // We'll write the protobuf version in RecordEnvironmentProto(). |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 803 | OPEN_ELEMENT_FOR_SCOPE("display"); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 804 | WriteIntAttribute("xsize", display_size.width()); |
| 805 | WriteIntAttribute("ysize", display_size.height()); |
| 806 | WriteIntAttribute("screens", GetScreenCount()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | { |
| 810 | OPEN_ELEMENT_FOR_SCOPE("bookmarks"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 811 | { |
| 812 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 813 | WriteAttribute("name", "full-tree"); |
[email protected] | 8542bcc | 2013-01-30 00:15:36 | [diff] [blame] | 814 | WriteIntAttribute("foldercount", 0); |
| 815 | WriteIntAttribute("itemcount", 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 816 | } |
| 817 | { |
| 818 | OPEN_ELEMENT_FOR_SCOPE("bookmarklocation"); |
| 819 | WriteAttribute("name", "toolbar"); |
[email protected] | 8542bcc | 2013-01-30 00:15:36 | [diff] [blame] | 820 | WriteIntAttribute("foldercount", 0); |
| 821 | WriteIntAttribute("itemcount", 0); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | |
| 825 | { |
| 826 | OPEN_ELEMENT_FOR_SCOPE("keywords"); |
| 827 | WriteIntAttribute("count", pref->GetInteger(prefs::kNumKeywords)); |
| 828 | } |
| 829 | |
| 830 | if (profile_metrics) |
| 831 | WriteAllProfilesMetrics(*profile_metrics); |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 832 | |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 833 | RecordEnvironmentProto(plugin_list, google_update_metrics); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | void MetricsLog::RecordEnvironmentProto( |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 837 | const std::vector<webkit::WebPluginInfo>& plugin_list, |
| 838 | const GoogleUpdateMetrics& google_update_metrics) { |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 839 | SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
[email protected] | 24b9bb39 | 2013-01-29 20:29:29 | [diff] [blame] | 840 | |
| 841 | std::string brand_code; |
| 842 | if (google_util::GetBrand(&brand_code)) |
| 843 | system_profile->set_brand_code(brand_code); |
| 844 | |
[email protected] | cc5d7f4 | 2012-10-30 00:30:09 | [diff] [blame] | 845 | int enabled_date; |
| 846 | bool success = base::StringToInt(GetMetricsEnabledDate(GetPrefService()), |
| 847 | &enabled_date); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 848 | DCHECK(success); |
[email protected] | cc5d7f4 | 2012-10-30 00:30:09 | [diff] [blame] | 849 | system_profile->set_uma_enabled_date(enabled_date); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 850 | |
| 851 | system_profile->set_application_locale( |
[email protected] | eabbfb1 | 2013-04-05 23:28:35 | [diff] [blame] | 852 | g_browser_process->GetApplicationLocale()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 853 | |
| 854 | SystemProfileProto::Hardware* hardware = system_profile->mutable_hardware(); |
[email protected] | 0b6a4fb | 2012-10-16 01:58:21 | [diff] [blame] | 855 | hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 856 | hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB()); |
| 857 | #if defined(OS_WIN) |
| 858 | hardware->set_dll_base(reinterpret_cast<uint64>(&__ImageBase)); |
| 859 | #endif |
| 860 | |
[email protected] | 74b299e | 2013-01-29 01:24:42 | [diff] [blame] | 861 | SystemProfileProto::Network* network = system_profile->mutable_network(); |
| 862 | network->set_connection_type_is_ambiguous( |
[email protected] | 5eae204c | 2013-02-13 15:53:42 | [diff] [blame] | 863 | network_observer_.connection_type_is_ambiguous()); |
| 864 | network->set_connection_type(network_observer_.connection_type()); |
| 865 | network->set_wifi_phy_layer_protocol_is_ambiguous( |
| 866 | network_observer_.wifi_phy_layer_protocol_is_ambiguous()); |
| 867 | network->set_wifi_phy_layer_protocol( |
| 868 | network_observer_.wifi_phy_layer_protocol()); |
| 869 | network_observer_.Reset(); |
[email protected] | 74b299e | 2013-01-29 01:24:42 | [diff] [blame] | 870 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 871 | SystemProfileProto::OS* os = system_profile->mutable_os(); |
[email protected] | 1bb25e0 | 2012-08-03 22:39:39 | [diff] [blame] | 872 | std::string os_name = base::SysInfo::OperatingSystemName(); |
| 873 | #if defined(OS_WIN) |
| 874 | // TODO(mad): This only checks whether the main process is a Metro process at |
| 875 | // upload time; not whether the collected metrics were all gathered from |
| 876 | // Metro. This is ok as an approximation for now, since users will rarely be |
| 877 | // switching from Metro to Desktop mode; but we should re-evaluate whether we |
| 878 | // can distinguish metrics more cleanly in the future: http://crbug.com/140568 |
| 879 | if (base::win::IsMetroProcess()) |
| 880 | os_name += " (Metro)"; |
| 881 | #endif |
| 882 | os->set_name(os_name); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 883 | os->set_version(base::SysInfo::OperatingSystemVersion()); |
[email protected] | 5106b3a | 2012-10-03 20:10:44 | [diff] [blame] | 884 | #if defined(OS_ANDROID) |
| 885 | os->set_fingerprint( |
| 886 | base::android::BuildInfo::GetInstance()->android_build_fp()); |
| 887 | #endif |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 888 | |
| 889 | const content::GPUInfo& gpu_info = |
| 890 | GpuDataManager::GetInstance()->GetGPUInfo(); |
| 891 | SystemProfileProto::Hardware::Graphics* gpu = hardware->mutable_gpu(); |
[email protected] | a094e2c | 2012-05-10 23:02:42 | [diff] [blame] | 892 | gpu->set_vendor_id(gpu_info.gpu.vendor_id); |
| 893 | gpu->set_device_id(gpu_info.gpu.device_id); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 894 | gpu->set_driver_version(gpu_info.driver_version); |
| 895 | gpu->set_driver_date(gpu_info.driver_date); |
| 896 | SystemProfileProto::Hardware::Graphics::PerformanceStatistics* |
| 897 | gpu_performance = gpu->mutable_performance_statistics(); |
| 898 | gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); |
| 899 | gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); |
| 900 | gpu_performance->set_overall_score(gpu_info.performance_stats.overall); |
[email protected] | d6bdfae | 2013-01-18 20:23:01 | [diff] [blame] | 901 | gpu->set_gl_vendor(gpu_info.gl_vendor); |
| 902 | gpu->set_gl_renderer(gpu_info.gl_renderer); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 903 | |
| 904 | const gfx::Size display_size = GetScreenSize(); |
| 905 | hardware->set_primary_screen_width(display_size.width()); |
| 906 | hardware->set_primary_screen_height(display_size.height()); |
[email protected] | aa9641797 | 2012-08-22 03:16:44 | [diff] [blame] | 907 | hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 908 | hardware->set_screen_count(GetScreenCount()); |
| 909 | |
[email protected] | 76869ff | 2013-01-15 16:13:47 | [diff] [blame] | 910 | #if defined(OS_WIN) |
| 911 | WriteScreenDPIInformationProto(hardware); |
| 912 | #endif |
| 913 | |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 914 | WriteGoogleUpdateProto(google_update_metrics); |
| 915 | |
[email protected] | bc66d53 | 2012-03-23 01:57:05 | [diff] [blame] | 916 | bool write_as_xml = false; |
| 917 | WritePluginList(plugin_list, write_as_xml); |
| 918 | |
[email protected] | 0c8b7ad | 2012-11-06 07:08:14 | [diff] [blame] | 919 | std::vector<ActiveGroupId> field_trial_ids; |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 920 | GetFieldTrialIds(&field_trial_ids); |
| 921 | WriteFieldTrials(field_trial_ids, system_profile); |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 922 | |
| 923 | #if defined(OS_CHROMEOS) |
| 924 | PerfDataProto perf_data_proto; |
| 925 | if (perf_provider_.GetPerfData(&perf_data_proto)) |
| 926 | uma_proto()->add_perf_data()->Swap(&perf_data_proto); |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 927 | |
| 928 | // BluetoothAdapterFactory::GetAdapter is synchronous on Chrome OS; if that |
| 929 | // changes this will fail at the DCHECK(). |
| 930 | device::BluetoothAdapterFactory::GetAdapter( |
| 931 | base::Bind(&MetricsLog::SetBluetoothAdapter, |
| 932 | base::Unretained(this))); |
| 933 | DCHECK(adapter_.get()); |
| 934 | WriteBluetoothProto(hardware); |
[email protected] | f65859e | 2013-02-04 20:00:25 | [diff] [blame] | 935 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 936 | } |
| 937 | |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 938 | void MetricsLog::RecordProfilerData( |
| 939 | const tracked_objects::ProcessDataSnapshot& process_data, |
[email protected] | f3b35769 | 2013-03-22 05:16:13 | [diff] [blame] | 940 | int process_type) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 941 | DCHECK(!locked()); |
| 942 | |
[email protected] | 8f82968 | 2012-04-27 00:36:49 | [diff] [blame] | 943 | if (tracked_objects::GetTimeSourceType() != |
| 944 | tracked_objects::TIME_SOURCE_TYPE_WALL_TIME) { |
[email protected] | ed0fd00 | 2012-04-25 23:10:34 | [diff] [blame] | 945 | // We currently only support the default time source, wall clock time. |
| 946 | return; |
| 947 | } |
| 948 | |
| 949 | ProfilerEventProto* profile; |
| 950 | if (!uma_proto()->profiler_event_size()) { |
| 951 | // For the first process's data, add a new field to the protocol buffer. |
| 952 | profile = uma_proto()->add_profiler_event(); |
| 953 | profile->set_profile_type(ProfilerEventProto::STARTUP_PROFILE); |
| 954 | profile->set_time_source(ProfilerEventProto::WALL_CLOCK_TIME); |
| 955 | } else { |
| 956 | // For the remaining calls, re-use the existing field. |
| 957 | profile = uma_proto()->mutable_profiler_event(0); |
| 958 | } |
| 959 | |
| 960 | WriteProfilerData(process_data, process_type, profile); |
| 961 | } |
| 962 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 963 | void MetricsLog::WriteAllProfilesMetrics( |
| 964 | const DictionaryValue& all_profiles_metrics) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 965 | const std::string profile_prefix(prefs::kProfilePrefix); |
[email protected] | a703e71e | 2013-02-26 23:58:14 | [diff] [blame] | 966 | for (DictionaryValue::Iterator i(all_profiles_metrics); !i.IsAtEnd(); |
| 967 | i.Advance()) { |
| 968 | if (i.key().compare(0, profile_prefix.size(), profile_prefix) == 0) { |
[email protected] | a61890e | 2012-07-27 22:27:11 | [diff] [blame] | 969 | const DictionaryValue* profile; |
[email protected] | a703e71e | 2013-02-26 23:58:14 | [diff] [blame] | 970 | if (i.value().GetAsDictionary(&profile)) |
| 971 | WriteProfileMetrics(i.key().substr(profile_prefix.size()), *profile); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 972 | } |
| 973 | } |
| 974 | } |
| 975 | |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 976 | void MetricsLog::WriteProfileMetrics(const std::string& profileidhash, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 977 | const DictionaryValue& profile_metrics) { |
| 978 | OPEN_ELEMENT_FOR_SCOPE("userprofile"); |
[email protected] | e7b418b | 2010-07-30 19:47:47 | [diff] [blame] | 979 | WriteAttribute("profileidhash", profileidhash); |
[email protected] | a703e71e | 2013-02-26 23:58:14 | [diff] [blame] | 980 | for (DictionaryValue::Iterator i(profile_metrics); !i.IsAtEnd(); |
| 981 | i.Advance()) { |
| 982 | DCHECK_NE(i.key(), "id"); |
| 983 | switch (i.value().GetType()) { |
| 984 | case Value::TYPE_STRING: { |
| 985 | std::string string_value; |
| 986 | if (i.value().GetAsString(&string_value)) { |
| 987 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
| 988 | WriteAttribute("name", i.key()); |
| 989 | WriteAttribute("value", string_value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 990 | } |
[email protected] | a703e71e | 2013-02-26 23:58:14 | [diff] [blame] | 991 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 992 | } |
[email protected] | a703e71e | 2013-02-26 23:58:14 | [diff] [blame] | 993 | |
| 994 | case Value::TYPE_BOOLEAN: { |
| 995 | bool bool_value; |
| 996 | if (i.value().GetAsBoolean(&bool_value)) { |
| 997 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
| 998 | WriteAttribute("name", i.key()); |
| 999 | WriteIntAttribute("value", bool_value ? 1 : 0); |
| 1000 | } |
| 1001 | break; |
| 1002 | } |
| 1003 | |
| 1004 | case Value::TYPE_INTEGER: { |
| 1005 | int int_value; |
| 1006 | if (i.value().GetAsInteger(&int_value)) { |
| 1007 | OPEN_ELEMENT_FOR_SCOPE("profileparam"); |
| 1008 | WriteAttribute("name", i.key()); |
| 1009 | WriteIntAttribute("value", int_value); |
| 1010 | } |
| 1011 | break; |
| 1012 | } |
| 1013 | |
| 1014 | default: |
| 1015 | NOTREACHED(); |
| 1016 | break; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | void MetricsLog::RecordOmniboxOpenedURL(const AutocompleteLog& log) { |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 1022 | DCHECK(!locked()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1023 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1024 | // Write the XML version. |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 1025 | OPEN_ELEMENT_FOR_SCOPE("uielement"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1026 | WriteAttribute("action", "autocomplete"); |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 1027 | WriteAttribute("targetidhash", std::string()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1028 | // TODO(kochi): Properly track windows. |
| 1029 | WriteIntAttribute("window", 0); |
[email protected] | 6ebc316 | 2011-12-19 13:44:00 | [diff] [blame] | 1030 | if (log.tab_id != -1) { |
| 1031 | // If we know what tab the autocomplete URL was opened in, log it. |
| 1032 | WriteIntAttribute("tab", static_cast<int>(log.tab_id)); |
| 1033 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1034 | WriteCommonEventAttributes(); |
| 1035 | |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 1036 | std::vector<string16> terms; |
| 1037 | const int num_terms = |
| 1038 | static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms)); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 1039 | { |
| 1040 | OPEN_ELEMENT_FOR_SCOPE("autocomplete"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1041 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 1042 | WriteIntAttribute("typedlength", static_cast<int>(log.text.length())); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 1043 | WriteIntAttribute("numterms", num_terms); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 1044 | WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index)); |
| 1045 | WriteIntAttribute("completedlength", |
[email protected] | 62b3ef5 | 2013-01-18 00:13:02 | [diff] [blame] | 1046 | log.completed_length != string16::npos ? |
| 1047 | static_cast<int>(log.completed_length) : 0); |
[email protected] | 9e34976 | 2012-01-31 03:24:36 | [diff] [blame] | 1048 | if (log.elapsed_time_since_user_first_modified_omnibox != |
| 1049 | base::TimeDelta::FromMilliseconds(-1)) { |
| 1050 | // Only upload the typing duration if it is set/valid. |
| 1051 | WriteInt64Attribute("typingduration", |
| 1052 | log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); |
| 1053 | } |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 1054 | const std::string input_type( |
| 1055 | AutocompleteInput::TypeToString(log.input_type)); |
| 1056 | if (!input_type.empty()) |
| 1057 | WriteAttribute("inputtype", input_type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1058 | |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 1059 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 1060 | i != log.result.end(); ++i) { |
| 1061 | OPEN_ELEMENT_FOR_SCOPE("autocompleteitem"); |
| 1062 | if (i->provider) |
[email protected] | 35f1f4f0 | 2012-09-11 13:17:00 | [diff] [blame] | 1063 | WriteAttribute("provider", i->provider->GetName()); |
[email protected] | 381e299 | 2008-12-16 01:41:00 | [diff] [blame] | 1064 | const std::string result_type(AutocompleteMatch::TypeToString(i->type)); |
| 1065 | if (!result_type.empty()) |
| 1066 | WriteAttribute("resulttype", result_type); |
[email protected] | ffaf78a | 2008-11-12 17:38:33 | [diff] [blame] | 1067 | WriteIntAttribute("relevance", i->relevance); |
| 1068 | WriteIntAttribute("isstarred", i->starred ? 1 : 0); |
| 1069 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1070 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1071 | |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1072 | // Write the protobuf version. |
[email protected] | 767c9d9 | 2012-03-02 16:04:34 | [diff] [blame] | 1073 | OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event(); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1074 | omnibox_event->set_time(MetricsLogBase::GetCurrentTime()); |
| 1075 | if (log.tab_id != -1) { |
| 1076 | // If we know what tab the autocomplete URL was opened in, log it. |
| 1077 | omnibox_event->set_tab_id(log.tab_id); |
| 1078 | } |
| 1079 | omnibox_event->set_typed_length(log.text.length()); |
[email protected] | 660fe8f3 | 2012-05-03 20:01:08 | [diff] [blame] | 1080 | omnibox_event->set_just_deleted_text(log.just_deleted_text); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 1081 | omnibox_event->set_num_typed_terms(num_terms); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1082 | omnibox_event->set_selected_index(log.selected_index); |
[email protected] | 62b3ef5 | 2013-01-18 00:13:02 | [diff] [blame] | 1083 | if (log.completed_length != string16::npos) |
| 1084 | omnibox_event->set_completed_length(log.completed_length); |
[email protected] | 6595631 | 2012-04-19 21:28:12 | [diff] [blame] | 1085 | if (log.elapsed_time_since_user_first_modified_omnibox != |
| 1086 | base::TimeDelta::FromMilliseconds(-1)) { |
| 1087 | // Only upload the typing duration if it is set/valid. |
| 1088 | omnibox_event->set_typing_duration_ms( |
| 1089 | log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); |
| 1090 | } |
[email protected] | 35d5560 | 2012-11-20 23:49:03 | [diff] [blame] | 1091 | omnibox_event->set_duration_since_last_default_match_update_ms( |
| 1092 | log.elapsed_time_since_last_change_to_default_match.InMilliseconds()); |
[email protected] | ee90253 | 2012-05-01 23:54:49 | [diff] [blame] | 1093 | omnibox_event->set_current_page_classification( |
| 1094 | log.current_page_classification); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1095 | omnibox_event->set_input_type(AsOmniboxEventInputType(log.input_type)); |
| 1096 | for (AutocompleteResult::const_iterator i(log.result.begin()); |
| 1097 | i != log.result.end(); ++i) { |
| 1098 | OmniboxEventProto::Suggestion* suggestion = omnibox_event->add_suggestion(); |
[email protected] | 0e9e878 | 2012-05-15 23:01:51 | [diff] [blame] | 1099 | suggestion->set_provider(i->provider->AsOmniboxEventProviderType()); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1100 | suggestion->set_result_type(AsOmniboxEventResultType(i->type)); |
| 1101 | suggestion->set_relevance(i->relevance); |
[email protected] | cf6256f | 2012-06-12 23:36:01 | [diff] [blame] | 1102 | if (i->typed_count != -1) |
| 1103 | suggestion->set_typed_count(i->typed_count); |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1104 | suggestion->set_is_starred(i->starred); |
| 1105 | } |
[email protected] | 0e9e878 | 2012-05-15 23:01:51 | [diff] [blame] | 1106 | for (ProvidersInfo::const_iterator i(log.providers_info.begin()); |
| 1107 | i != log.providers_info.end(); ++i) { |
| 1108 | OmniboxEventProto::ProviderInfo* provider_info = |
| 1109 | omnibox_event->add_provider_info(); |
| 1110 | provider_info->CopyFrom(*i); |
| 1111 | } |
[email protected] | fe58acc2 | 2012-02-29 01:29:58 | [diff] [blame] | 1112 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1113 | ++num_events_; |
| 1114 | } |
[email protected] | 197c077 | 2012-05-14 23:50:51 | [diff] [blame] | 1115 | |
| 1116 | void MetricsLog::WriteGoogleUpdateProto( |
| 1117 | const GoogleUpdateMetrics& google_update_metrics) { |
| 1118 | #if defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| 1119 | SystemProfileProto::GoogleUpdate* google_update = |
| 1120 | uma_proto()->mutable_system_profile()->mutable_google_update(); |
| 1121 | |
| 1122 | google_update->set_is_system_install(google_update_metrics.is_system_install); |
| 1123 | |
| 1124 | if (!google_update_metrics.last_started_au.is_null()) { |
| 1125 | google_update->set_last_automatic_start_timestamp( |
| 1126 | google_update_metrics.last_started_au.ToTimeT()); |
| 1127 | } |
| 1128 | |
| 1129 | if (!google_update_metrics.last_checked.is_null()) { |
| 1130 | google_update->set_last_update_check_timestamp( |
| 1131 | google_update_metrics.last_checked.ToTimeT()); |
| 1132 | } |
| 1133 | |
| 1134 | if (!google_update_metrics.google_update_data.version.empty()) { |
| 1135 | ProductDataToProto(google_update_metrics.google_update_data, |
| 1136 | google_update->mutable_google_update_status()); |
| 1137 | } |
| 1138 | |
| 1139 | if (!google_update_metrics.product_data.version.empty()) { |
| 1140 | ProductDataToProto(google_update_metrics.product_data, |
| 1141 | google_update->mutable_client_status()); |
| 1142 | } |
| 1143 | #endif // defined(GOOGLE_CHROME_BUILD) && defined(OS_WIN) |
| 1144 | } |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 1145 | |
| 1146 | void MetricsLog::SetBluetoothAdapter( |
| 1147 | scoped_refptr<device::BluetoothAdapter> adapter) { |
| 1148 | adapter_ = adapter; |
| 1149 | } |
| 1150 | |
| 1151 | void MetricsLog::WriteBluetoothProto( |
| 1152 | SystemProfileProto::Hardware* hardware) { |
[email protected] | 728f9b2 | 2013-05-02 06:08:18 | [diff] [blame] | 1153 | #if defined(OS_CHROMEOS) |
[email protected] | 611ae29a | 2013-04-29 21:32:19 | [diff] [blame] | 1154 | SystemProfileProto::Hardware::Bluetooth* bluetooth = |
| 1155 | hardware->mutable_bluetooth(); |
| 1156 | |
| 1157 | bluetooth->set_is_present(adapter_->IsPresent()); |
| 1158 | bluetooth->set_is_enabled(adapter_->IsPowered()); |
| 1159 | |
| 1160 | device::BluetoothAdapter::DeviceList devices = adapter_->GetDevices(); |
| 1161 | for (device::BluetoothAdapter::DeviceList::iterator iter = |
| 1162 | devices.begin(); iter != devices.end(); ++iter) { |
| 1163 | PairedDevice* paired_device = bluetooth->add_paired_device(); |
| 1164 | |
| 1165 | device::BluetoothDevice* device = *iter; |
| 1166 | paired_device->set_bluetooth_class(device->GetBluetoothClass()); |
| 1167 | paired_device->set_type(AsBluetoothDeviceType(device->GetDeviceType())); |
| 1168 | |
| 1169 | // address is xx:xx:xx:xx:xx:xx, extract the first three components and |
| 1170 | // pack into a uint32 |
| 1171 | std::string address = device->GetAddress(); |
| 1172 | if (address.size() > 9 && |
| 1173 | address[2] == ':' && address[5] == ':' && address[8] == ':') { |
| 1174 | std::string vendor_prefix_str; |
| 1175 | uint64 vendor_prefix; |
| 1176 | |
| 1177 | RemoveChars(address.substr(0, 9), ":", &vendor_prefix_str); |
| 1178 | DCHECK_EQ(6U, vendor_prefix_str.size()); |
| 1179 | base::HexStringToUInt64(vendor_prefix_str, &vendor_prefix); |
| 1180 | |
| 1181 | paired_device->set_vendor_prefix(vendor_prefix); |
| 1182 | } |
| 1183 | |
| 1184 | paired_device->set_vendor_id(device->GetVendorID()); |
| 1185 | paired_device->set_product_id(device->GetProductID()); |
| 1186 | paired_device->set_device_id(device->GetDeviceID()); |
| 1187 | } |
| 1188 | #endif // defined(OS_CHROMEOS) |
| 1189 | } |