Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/autofill/risk/machine_fingerprint.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/cpu.h" | |
| 9 #include "base/logging.h" | |
| 10 #include "base/string_split.h" | |
| 11 #include "base/sys_info.h" | |
| 12 #include "base/time.h" | |
| 13 #include "base/utf_string_conversions.h" | |
| 14 #include "chrome/browser/autofill/risk/proto/machine_fingerprint.pb.h" | |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/prefs/pref_service.h" | |
| 17 #include "chrome/browser/profiles/profile_manager.h" | |
| 18 #include "chrome/common/chrome_version_info.h" | |
| 19 #include "chrome/common/pref_names.h" | |
| 20 #include "content/public/browser/content_browser_client.h" | |
| 21 #include "content/public/browser/font_list_async.h" | |
| 22 #include "content/public/browser/gpu_data_manager.h" | |
| 23 #include "content/public/browser/plugin_service.h" | |
| 24 #include "content/public/common/content_client.h" | |
| 25 #include "content/public/common/gpu_info.h" | |
| 26 #include "ui/gfx/rect.h" | |
| 27 #include "ui/gfx/screen.h" | |
| 28 #include "webkit/plugins/webplugininfo.h" | |
| 29 | |
| 30 namespace autofill { | |
| 31 namespace risk { | |
| 32 | |
| 33 namespace { | |
| 34 | |
| 35 const int32 kFingerprinterVersion = 1; | |
| 36 | |
| 37 // Returns the delta between |timestamp| and the Unix epoch, in milliseconds. | |
| 38 int64 GetMillisecondsSinceEpoch(const base::Time& timestamp) { | |
|
Albert Bodenhamer
2012/12/18 17:42:22
Should this live in a util module somewhere?
Evan Stade
2012/12/18 22:14:34
yea, this seems similar to ToJsTime
Ilya Sherman
2012/12/19 01:50:08
I'll check with Brett whether he's ok with moving
brettw
2012/12/19 06:18:13
I think the code you have here is short and quite
| |
| 39 return (timestamp - base::Time::UnixEpoch()).InMilliseconds(); | |
| 40 } | |
| 41 | |
| 42 // Returns the time at which Chrome was installed, in milliseconds since the | |
| 43 // epoch. | |
| 44 int64 GetInstallTimeMs() { | |
| 45 // TODO(isherman): If we keep this implementation, the metric should probably | |
| 46 // be renamed; or at least the comments for it should be updated. | |
| 47 PrefService* prefs = g_browser_process->local_state(); | |
| 48 base::Time install_time = base::Time::FromTimeT( | |
| 49 prefs->GetInt64(prefs::kUninstallMetricsInstallDate)); | |
| 50 // The install date should always be available and initialized. | |
| 51 DCHECK(!install_time.is_null()); | |
| 52 return GetMillisecondsSinceEpoch(install_time); | |
| 53 } | |
| 54 | |
| 55 // Returns the delta between the local timezone and UTC, in milliseconds. | |
| 56 int64 GetTimezoneOffsetMs() { | |
| 57 base::Time now = base::Time::Now(); | |
| 58 | |
| 59 base::Time::Exploded utc; | |
| 60 now.UTCExplode(&utc); | |
| 61 | |
| 62 base::Time::Exploded local; | |
| 63 now.LocalExplode(&local); | |
| 64 | |
| 65 base::TimeDelta delta = | |
| 66 base::Time::FromUTCExploded(local) - base::Time::FromUTCExploded(utc); | |
| 67 return delta.InMilliseconds(); | |
| 68 } | |
| 69 | |
| 70 void GetMachineFingerprintImpl( | |
| 71 int64 gaia_id, | |
| 72 const gfx::Rect& window_rect, | |
| 73 const gfx::Rect& content_rect, | |
| 74 scoped_ptr<BrowserNativeFingerprinting> data, | |
| 75 const std::vector<webkit::WebPluginInfo>& plugins, | |
| 76 scoped_ptr<base::ListValue> fonts) { | |
| 77 const PrefService* prefs = ProfileManager::GetLastUsedProfile()->GetPrefs(); | |
| 78 | |
| 79 BrowserNativeFingerprinting_Fingerprint* fingerprint = | |
| 80 data->mutable_fingerprint(); | |
| 81 | |
| 82 // TODO(isherman): Confirm the format for this and other strings in the | |
| 83 // fingerprint. | |
| 84 fingerprint->set_operating_system_build( | |
| 85 base::SysInfo::OperatingSystemVersion()); | |
| 86 | |
| 87 fingerprint->set_browser_install_time_ms(GetInstallTimeMs()); | |
| 88 | |
| 89 for (base::ListValue::const_iterator it = fonts->begin(); | |
|
Evan Stade
2012/12/18 22:14:34
dunno if you're looking for this level of review y
Ilya Sherman
2012/12/19 01:50:08
Done.
| |
| 90 it != fonts->end(); ++it) { | |
| 91 // Each item in the list is a two-element list such that the first element | |
| 92 // is the font family and the second is the font name. | |
| 93 const base::ListValue* font_description; | |
| 94 bool success = (*it)->GetAsList(&font_description); | |
| 95 DCHECK(success); | |
| 96 | |
| 97 std::string font_name; | |
| 98 success = font_description->GetString(1, &font_name); | |
| 99 DCHECK(success); | |
| 100 | |
| 101 fingerprint->add_font(font_name); | |
| 102 } | |
| 103 | |
| 104 for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin(); | |
| 105 it != plugins.end(); ++it) { | |
| 106 BrowserNativeFingerprinting_Fingerprint_Plugin* plugin = | |
| 107 fingerprint->add_plugin(); | |
| 108 plugin->set_name(UTF16ToUTF8(it->name)); | |
| 109 plugin->set_description(UTF16ToUTF8(it->desc)); | |
| 110 for (std::vector<webkit::WebPluginMimeType>::const_iterator mime_type = | |
| 111 it->mime_types.begin(); | |
| 112 mime_type != it->mime_types.end(); ++mime_type) { | |
| 113 plugin->add_mime_type(mime_type->mime_type); | |
| 114 } | |
| 115 plugin->set_version(UTF16ToUTF8(it->version)); | |
| 116 } | |
| 117 | |
| 118 fingerprint->set_utc_offset_ms(GetTimezoneOffsetMs()); | |
| 119 | |
| 120 fingerprint->set_browser_language( | |
| 121 content::GetContentClient()->browser()->GetApplicationLocale()); | |
| 122 | |
| 123 std::vector<std::string> accept_languages; | |
| 124 base::SplitString(prefs->GetString(prefs::kAcceptLanguages), ',', | |
| 125 &accept_languages); | |
| 126 for (std::vector<std::string>::const_iterator it = accept_languages.begin(); | |
| 127 it != accept_languages.end(); ++it) { | |
| 128 fingerprint->add_requested_language(*it); | |
| 129 } | |
| 130 | |
| 131 fingerprint->set_charset(prefs->GetString(prefs::kDefaultCharset)); | |
| 132 | |
| 133 // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312 | |
| 134 fingerprint->set_screen_count( | |
| 135 gfx::Screen::GetNativeScreen()->GetNumDisplays()); | |
| 136 | |
| 137 gfx::Size screen_size = | |
| 138 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel(); | |
| 139 fingerprint->mutable_screen_size()->set_width(screen_size.width()); | |
| 140 fingerprint->mutable_screen_size()->set_height(screen_size.height()); | |
| 141 | |
| 142 // TODO(isherman): Store the user's screen color depth by refactoring the code | |
| 143 // for RenderWidgetHostImpl::GetWebScreenInfo(). | |
| 144 // TODO(isherman): Store the user's unavailable screen size, likewise by | |
| 145 // fetching the WebScreenInfo that RenderWidgetHostImpl::GetWebScreenInfo() | |
| 146 // provides. | |
| 147 | |
| 148 fingerprint->set_user_agent(content::GetContentClient()->GetUserAgent()); | |
| 149 | |
| 150 // TODO(isherman): Store the partition size of the hard drives? | |
| 151 | |
| 152 base::CPU cpu; | |
| 153 fingerprint->set_cpu(cpu.vendor_name() + "; " + cpu.cpu_brand()); | |
| 154 | |
| 155 fingerprint->set_ram(base::SysInfo::AmountOfPhysicalMemory()); | |
| 156 | |
| 157 const content::GPUInfo& gpu_info = | |
| 158 content::GpuDataManager::GetInstance()->GetGPUInfo(); | |
| 159 BrowserNativeFingerprinting_Fingerprint_Graphics* graphics = | |
| 160 fingerprint->mutable_graphics_card(); | |
| 161 graphics->set_vendor_id(gpu_info.gpu.vendor_id); | |
| 162 graphics->set_device_id(gpu_info.gpu.device_id); | |
| 163 // TODO(isherman): The driver version might not be available yet. We need to | |
| 164 // register ourselves as an observer, and wait for the info to come back to | |
| 165 // us... | |
| 166 graphics->set_driver_version(gpu_info.driver_version); | |
| 167 graphics->set_driver_date(gpu_info.driver_date); | |
| 168 BrowserNativeFingerprinting_Fingerprint_Graphics_PerformanceStatistics* | |
| 169 gpu_performance = graphics->mutable_performance_statistics(); | |
| 170 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); | |
| 171 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); | |
| 172 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); | |
| 173 | |
| 174 fingerprint->set_browser_build(chrome::VersionInfo().Version()); | |
| 175 | |
| 176 BrowserNativeFingerprinting_State* transient_state = data->mutable_state(); | |
| 177 BrowserNativeFingerprinting_Dimension* inner_window_size = | |
| 178 transient_state->mutable_inner_window_size(); | |
| 179 inner_window_size->set_width(window_rect.width()); | |
| 180 inner_window_size->set_height(window_rect.height()); | |
| 181 BrowserNativeFingerprinting_Dimension* outer_window_size = | |
| 182 transient_state->mutable_outer_window_size(); | |
| 183 outer_window_size->set_width(content_rect.width()); | |
| 184 outer_window_size->set_height(content_rect.height()); | |
| 185 | |
| 186 // TODO(isherman): Record network performance data, which is theoretically | |
| 187 // available to JS. | |
| 188 | |
| 189 // TODO(isherman): Record user behavior data. | |
| 190 | |
| 191 BrowserNativeFingerprinting_Metadata* metadata = data->mutable_metadata(); | |
| 192 metadata->set_timestamp_ms(GetMillisecondsSinceEpoch(base::Time::Now())); | |
| 193 metadata->set_gaia_id(gaia_id); | |
| 194 metadata->set_fingerprinter_version(kFingerprinterVersion); | |
| 195 | |
| 196 // TODO(isherman): REMOVEME | |
|
Albert Bodenhamer
2012/12/18 17:42:22
Remove
Ilya Sherman
2012/12/19 01:50:08
This is useful for debugging; I'll remove once the
| |
| 197 DLOG(WARNING) << "\n" << data->DebugString(); | |
| 198 } | |
| 199 | |
| 200 void OnGotPlugins(int64 gaia_id, | |
| 201 const gfx::Rect& window_rect, | |
| 202 const gfx::Rect& content_rect, | |
| 203 scoped_ptr<BrowserNativeFingerprinting> data, | |
| 204 const std::vector<webkit::WebPluginInfo>& plugins) { | |
| 205 content::GetFontListAsync( | |
| 206 base::Bind(&GetMachineFingerprintImpl, gaia_id, window_rect, content_rect, | |
| 207 base::Passed(&data), plugins)); | |
| 208 } | |
| 209 | |
| 210 | |
| 211 } // namespace | |
| 212 | |
| 213 // TODO(isherman): The variable |data| could use a more descriptive name. Any | |
| 214 // suggestions? | |
| 215 void GetMachineFingerprint(int64 gaia_id, | |
| 216 const gfx::Rect& window_rect, | |
| 217 const gfx::Rect& content_rect, | |
| 218 scoped_ptr<BrowserNativeFingerprinting> data) { | |
|
Albert Bodenhamer
2012/12/18 17:42:22
|fingerprint| ?
Ilya Sherman
2012/12/19 01:50:08
Unfortunately, fingerprint is one of the fields wi
Evan Stade
2012/12/19 03:13:27
imo give the field within the data structure a bet
Ilya Sherman
2012/12/20 04:06:49
Done.
| |
| 219 content::PluginService::GetInstance()->GetPlugins( | |
| 220 base::Bind(&OnGotPlugins, gaia_id, window_rect, content_rect, | |
| 221 base::Passed(&data))); | |
| 222 } | |
| 223 | |
| 224 } // namespace risk | |
| 225 } // namespace autofill | |
| OLD | NEW |