| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 //------------------------------------------------------------------------------ | 7 //------------------------------------------------------------------------------ |
| 8 // Description of the life cycle of a instance of MetricsService. | 8 // Description of the life cycle of a instance of MetricsService. |
| 9 // | 9 // |
| 10 // OVERVIEW | 10 // OVERVIEW |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // twice. For example, if a log file is sent, but not yet acknowledged by | 151 // twice. For example, if a log file is sent, but not yet acknowledged by |
| 152 // the external server, and the user shuts down, then a copy of the log may be | 152 // the external server, and the user shuts down, then a copy of the log may be |
| 153 // saved for re-transmission. These duplicates could be filtered out server | 153 // saved for re-transmission. These duplicates could be filtered out server |
| 154 // side, but are not expected to be a significant problem. | 154 // side, but are not expected to be a significant problem. |
| 155 // | 155 // |
| 156 // | 156 // |
| 157 //------------------------------------------------------------------------------ | 157 //------------------------------------------------------------------------------ |
| 158 | 158 |
| 159 #include "chrome/browser/metrics/metrics_service.h" | 159 #include "chrome/browser/metrics/metrics_service.h" |
| 160 | 160 |
| 161 #if defined(OS_WIN) | |
| 162 #include <windows.h> | |
| 163 #include <objbase.h> | |
| 164 #endif | |
| 165 | |
| 166 #include "base/base64.h" | 161 #include "base/base64.h" |
| 167 #include "base/command_line.h" | 162 #include "base/command_line.h" |
| 168 #include "base/histogram.h" | 163 #include "base/histogram.h" |
| 169 #include "base/md5.h" | 164 #include "base/md5.h" |
| 165 #include "base/rand_util.h" |
| 170 #include "base/string_number_conversions.h" | 166 #include "base/string_number_conversions.h" |
| 171 #include "base/thread.h" | 167 #include "base/thread.h" |
| 172 #include "base/utf_string_conversions.h" | 168 #include "base/utf_string_conversions.h" |
| 173 #include "base/values.h" | 169 #include "base/values.h" |
| 174 #include "chrome/browser/bookmarks/bookmark_model.h" | 170 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 175 #include "chrome/browser/browser_list.h" | 171 #include "chrome/browser/browser_list.h" |
| 176 #include "chrome/browser/browser_process.h" | 172 #include "chrome/browser/browser_process.h" |
| 177 #include "chrome/browser/load_notification_details.h" | 173 #include "chrome/browser/load_notification_details.h" |
| 178 #include "chrome/browser/memory_details.h" | 174 #include "chrome/browser/memory_details.h" |
| 179 #include "chrome/browser/metrics/histogram_synchronizer.h" | 175 #include "chrome/browser/metrics/histogram_synchronizer.h" |
| 180 #include "chrome/browser/metrics/metrics_log.h" | 176 #include "chrome/browser/metrics/metrics_log.h" |
| 181 #include "chrome/browser/prefs/pref_service.h" | 177 #include "chrome/browser/prefs/pref_service.h" |
| 182 #include "chrome/browser/profile.h" | 178 #include "chrome/browser/profile.h" |
| 183 #include "chrome/browser/renderer_host/render_process_host.h" | 179 #include "chrome/browser/renderer_host/render_process_host.h" |
| 184 #include "chrome/browser/search_engines/template_url_model.h" | 180 #include "chrome/browser/search_engines/template_url_model.h" |
| 185 #include "chrome/common/child_process_info.h" | 181 #include "chrome/common/child_process_info.h" |
| 186 #include "chrome/common/child_process_logging.h" | 182 #include "chrome/common/child_process_logging.h" |
| 187 #include "chrome/common/chrome_switches.h" | 183 #include "chrome/common/chrome_switches.h" |
| 188 #include "chrome/common/notification_service.h" | 184 #include "chrome/common/notification_service.h" |
| 189 #include "chrome/common/pref_names.h" | 185 #include "chrome/common/pref_names.h" |
| 190 #include "chrome/common/render_messages.h" | 186 #include "chrome/common/render_messages.h" |
| 191 #include "webkit/glue/plugins/plugin_list.h" | 187 #include "webkit/glue/plugins/plugin_list.h" |
| 192 #include "webkit/glue/plugins/webplugininfo.h" | 188 #include "webkit/glue/plugins/webplugininfo.h" |
| 193 #include "libxml/xmlwriter.h" | 189 #include "libxml/xmlwriter.h" |
| 194 | 190 |
| 195 #if !defined(OS_WIN) | |
| 196 #include "base/rand_util.h" | |
| 197 #endif | |
| 198 | |
| 199 // TODO(port): port browser_distribution.h. | 191 // TODO(port): port browser_distribution.h. |
| 200 #if !defined(OS_POSIX) | 192 #if !defined(OS_POSIX) |
| 201 #include "chrome/installer/util/browser_distribution.h" | 193 #include "chrome/installer/util/browser_distribution.h" |
| 202 #endif | 194 #endif |
| 203 | 195 |
| 204 #if defined(OS_CHROMEOS) | 196 #if defined(OS_CHROMEOS) |
| 205 #include "chrome/browser/chromeos/cros/cros_library.h" | 197 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 206 #include "chrome/browser/chromeos/cros/system_library.h" | 198 #include "chrome/browser/chromeos/cros/system_library.h" |
| 207 #include "chrome/browser/chromeos/external_metrics.h" | 199 #include "chrome/browser/chromeos/external_metrics.h" |
| 208 #endif | 200 #endif |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 const std::string& hardware_class, | 801 const std::string& hardware_class, |
| 810 const std::vector<WebPluginInfo>& plugins) { | 802 const std::vector<WebPluginInfo>& plugins) { |
| 811 DCHECK(state_ == INIT_TASK_SCHEDULED); | 803 DCHECK(state_ == INIT_TASK_SCHEDULED); |
| 812 hardware_class_ = hardware_class; | 804 hardware_class_ = hardware_class; |
| 813 plugins_ = plugins; | 805 plugins_ = plugins; |
| 814 if (state_ == INIT_TASK_SCHEDULED) | 806 if (state_ == INIT_TASK_SCHEDULED) |
| 815 state_ = INIT_TASK_DONE; | 807 state_ = INIT_TASK_DONE; |
| 816 } | 808 } |
| 817 | 809 |
| 818 std::string MetricsService::GenerateClientID() { | 810 std::string MetricsService::GenerateClientID() { |
| 819 #if defined(OS_WIN) | 811 return base::GenerateGUID(); |
| 820 const int kGUIDSize = 39; | |
| 821 | |
| 822 GUID guid; | |
| 823 HRESULT guid_result = CoCreateGuid(&guid); | |
| 824 DCHECK(SUCCEEDED(guid_result)); | |
| 825 | |
| 826 std::wstring guid_string; | |
| 827 int result = StringFromGUID2(guid, | |
| 828 WriteInto(&guid_string, kGUIDSize), kGUIDSize); | |
| 829 DCHECK(result == kGUIDSize); | |
| 830 | |
| 831 return WideToUTF8(guid_string.substr(1, guid_string.length() - 2)); | |
| 832 #else | |
| 833 uint64 sixteen_bytes[2] = { base::RandUint64(), base::RandUint64() }; | |
| 834 return RandomBytesToGUIDString(sixteen_bytes); | |
| 835 #endif | |
| 836 } | 812 } |
| 837 | 813 |
| 838 #if defined(OS_POSIX) | |
| 839 // TODO(cmasone): Once we're comfortable this works, migrate Windows code to | |
| 840 // use this as well. | |
| 841 std::string MetricsService::RandomBytesToGUIDString(const uint64 bytes[2]) { | |
| 842 return StringPrintf("%08X-%04X-%04X-%04X-%012llX", | |
| 843 static_cast<unsigned int>(bytes[0] >> 32), | |
| 844 static_cast<unsigned int>((bytes[0] >> 16) & 0x0000ffff), | |
| 845 static_cast<unsigned int>(bytes[0] & 0x0000ffff), | |
| 846 static_cast<unsigned int>(bytes[1] >> 48), | |
| 847 bytes[1] & 0x0000ffffffffffffULL); | |
| 848 } | |
| 849 #endif | |
| 850 | |
| 851 //------------------------------------------------------------------------------ | 814 //------------------------------------------------------------------------------ |
| 852 // State save methods | 815 // State save methods |
| 853 | 816 |
| 854 void MetricsService::ScheduleNextStateSave() { | 817 void MetricsService::ScheduleNextStateSave() { |
| 855 state_saver_factory_.RevokeAll(); | 818 state_saver_factory_.RevokeAll(); |
| 856 | 819 |
| 857 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 820 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 858 state_saver_factory_.NewRunnableMethod(&MetricsService::SaveLocalState), | 821 state_saver_factory_.NewRunnableMethod(&MetricsService::SaveLocalState), |
| 859 kSaveStateInterval * 1000); | 822 kSaveStateInterval * 1000); |
| 860 } | 823 } |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1943 thread_id = PlatformThread::CurrentId(); | 1906 thread_id = PlatformThread::CurrentId(); |
| 1944 return PlatformThread::CurrentId() == thread_id; | 1907 return PlatformThread::CurrentId() == thread_id; |
| 1945 } | 1908 } |
| 1946 | 1909 |
| 1947 #if defined(OS_CHROMEOS) | 1910 #if defined(OS_CHROMEOS) |
| 1948 void MetricsService::StartExternalMetrics() { | 1911 void MetricsService::StartExternalMetrics() { |
| 1949 external_metrics_ = new chromeos::ExternalMetrics; | 1912 external_metrics_ = new chromeos::ExternalMetrics; |
| 1950 external_metrics_->Start(); | 1913 external_metrics_->Start(); |
| 1951 } | 1914 } |
| 1952 #endif | 1915 #endif |
| OLD | NEW |