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

Unified Diff: chrome/browser/autofill/risk/machine_fingerprint.cc

Issue 11612017: [Autofill] Add protobuf for Google Wallet risk parameters and a utility function for filling it out. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean it up! Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/risk/machine_fingerprint.cc
diff --git a/chrome/browser/autofill/risk/machine_fingerprint.cc b/chrome/browser/autofill/risk/machine_fingerprint.cc
new file mode 100644
index 0000000000000000000000000000000000000000..31e81609029c2f7fcf83ad5a3bc43ef98a181f89
--- /dev/null
+++ b/chrome/browser/autofill/risk/machine_fingerprint.cc
@@ -0,0 +1,333 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/autofill/risk/machine_fingerprint.h"
+
+#include "base/bind.h"
+#include "base/cpu.h"
+#include "base/logging.h"
+#include "base/string_split.h"
+#include "base/sys_info.h"
+#include "base/time.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/browser/autofill/risk/proto/machine_fingerprint.pb.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/chrome_version_info.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/browser/font_list_async.h"
+#include "content/public/browser/gpu_data_manager.h"
+#include "content/public/browser/gpu_data_manager_observer.h"
+#include "content/public/browser/plugin_service.h"
+#include "content/public/common/content_client.h"
+#include "content/public/common/gpu_info.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/screen.h"
+#include "webkit/plugins/webplugininfo.h"
+
+namespace autofill {
+namespace risk {
+
+namespace {
+
+const int32 kFingerprinterVersion = 1;
+
+// Returns the delta between |timestamp| and the Unix epoch, in milliseconds.
+int64 GetMillisecondsSinceEpoch(const base::Time& timestamp) {
+ return (timestamp - base::Time::UnixEpoch()).InMilliseconds();
+}
+
+// Returns the time at which Chrome was installed, in milliseconds since the
+// epoch.
+int64 GetInstallTimeMs() {
+ // TODO(isherman): If we keep this implementation, the metric should probably
+ // be renamed; or at least the comments for it should be updated.
+ PrefService* prefs = g_browser_process->local_state();
+ base::Time install_time = base::Time::FromTimeT(
+ prefs->GetInt64(prefs::kUninstallMetricsInstallDate));
+ // The install date should always be available and initialized.
+ DCHECK(!install_time.is_null());
+ return GetMillisecondsSinceEpoch(install_time);
+}
+
+// Returns the delta between the local timezone and UTC, in milliseconds.
+int64 GetTimezoneOffsetMs() {
+ base::Time now = base::Time::Now();
+
+ base::Time::Exploded utc;
+ now.UTCExplode(&utc);
+
+ base::Time::Exploded local;
+ now.LocalExplode(&local);
+
+ base::TimeDelta delta =
+ base::Time::FromUTCExploded(local) - base::Time::FromUTCExploded(utc);
+ return delta.InMilliseconds();
+}
+
+// Returns the concatenation of the operating system name and version, e.g.
+// "Mac OS X 10.6.8".
+std::string GetOperatingSystemVersion() {
+ return
+ base::SysInfo::OperatingSystemName() + " " +
+ base::SysInfo::OperatingSystemVersion();
+}
+
+// Adds the list of |fonts| to the |fingerprint|.
+void AddFontsToFingerprint(
+ const base::ListValue& fonts,
+ BrowserNativeFingerprinting_Fingerprint* fingerprint) {
+ for (base::ListValue::const_iterator it = fonts.begin();
+ it != fonts.end(); ++it) {
+ // Each item in the list is a two-element list such that the first element
+ // is the font family and the second is the font name.
+ const base::ListValue* font_description;
+ bool success = (*it)->GetAsList(&font_description);
+ DCHECK(success);
+
+ std::string font_name;
+ success = font_description->GetString(1, &font_name);
+ DCHECK(success);
+
+ fingerprint->add_font(font_name);
+ }
+}
+
+// Adds the list of |plugins| to the |fingerprint|.
+void AddPluginsToFingerprint(
+ const std::vector<webkit::WebPluginInfo>& plugins,
+ BrowserNativeFingerprinting_Fingerprint* fingerprint) {
+ for (std::vector<webkit::WebPluginInfo>::const_iterator it = plugins.begin();
+ it != plugins.end(); ++it) {
+ BrowserNativeFingerprinting_Fingerprint_Plugin* plugin =
+ fingerprint->add_plugin();
+ plugin->set_name(UTF16ToUTF8(it->name));
+ plugin->set_description(UTF16ToUTF8(it->desc));
+ for (std::vector<webkit::WebPluginMimeType>::const_iterator mime_type =
+ it->mime_types.begin();
+ mime_type != it->mime_types.end(); ++mime_type) {
+ plugin->add_mime_type(mime_type->mime_type);
+ }
+ plugin->set_version(UTF16ToUTF8(it->version));
+ }
+}
+
+// Adds the list of HTTP accept languages in |prefs| to the |fingerprint|.
+void AddAcceptLanguagesToFingerprint(
+ const PrefService& prefs,
+ BrowserNativeFingerprinting_Fingerprint* fingerprint) {
+ std::vector<std::string> accept_languages;
+ base::SplitString(prefs.GetString(prefs::kAcceptLanguages), ',',
+ &accept_languages);
+ for (std::vector<std::string>::const_iterator it = accept_languages.begin();
+ it != accept_languages.end(); ++it) {
+ fingerprint->add_requested_language(*it);
+ }
+}
+
+// Writes the number of screens and the primary display's screen size into the
+// |fingerprint|.
+void AddScreenInfoToFingerprint(
+ BrowserNativeFingerprinting_Fingerprint* fingerprint) {
+ // TODO(scottmg): NativeScreen maybe wrong. http://crbug.com/133312
+ fingerprint->set_screen_count(
+ gfx::Screen::GetNativeScreen()->GetNumDisplays());
+
+ gfx::Size screen_size =
+ gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().GetSizeInPixel();
+ fingerprint->mutable_screen_size()->set_width(screen_size.width());
+ fingerprint->mutable_screen_size()->set_height(screen_size.height());
+}
+
+// Writes info about the machine's CPU into the |fingerprint|.
+void AddCpuInfoToFingerprint(
+ BrowserNativeFingerprinting_Fingerprint* fingerprint) {
+ base::CPU cpu;
+ fingerprint->mutable_cpu()->set_vendor_name(cpu.vendor_name());
+ fingerprint->mutable_cpu()->set_vendor_name(cpu.cpu_brand());
+}
+
+// Writes info about the machine's GPU into the |fingerprint|.
+void AddGpuInfoToFingerprint(
+ BrowserNativeFingerprinting_Fingerprint* fingerprint) {
+ const content::GPUInfo& gpu_info =
+ content::GpuDataManager::GetInstance()->GetGPUInfo();
+ DCHECK(gpu_info.finalized);
+
+ BrowserNativeFingerprinting_Fingerprint_Graphics* graphics =
+ fingerprint->mutable_graphics_card();
+ graphics->set_vendor_id(gpu_info.gpu.vendor_id);
+ graphics->set_device_id(gpu_info.gpu.device_id);
+ graphics->set_driver_version(gpu_info.driver_version);
+ graphics->set_driver_date(gpu_info.driver_date);
+
+ BrowserNativeFingerprinting_Fingerprint_Graphics_PerformanceStatistics*
+ gpu_performance = graphics->mutable_performance_statistics();
+ gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics);
+ gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming);
+ gpu_performance->set_overall_score(gpu_info.performance_stats.overall);
+}
+
+void GetMachineFingerprintImpl(
+ int64 gaia_id,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& content_rect,
+ scoped_ptr<BrowserNativeFingerprinting> data,
+ scoped_ptr<base::ListValue> fonts,
+ const std::vector<webkit::WebPluginInfo>& plugins) {
+ // TODO(isherman): We should not rely on the assumption that the last used
+ // profile is the correct profile. I need to figure out how to pass in a
+ // pointer to the correct profile such that the pointer is guaranteed not to
+ // be dead by the time I look at it.
Evan Stade 2012/12/19 03:13:27 I think you'd need to listen for PROFILE_DESTROYED
Ilya Sherman 2012/12/20 04:06:49 Done.
+ const PrefService* prefs = ProfileManager::GetLastUsedProfile()->GetPrefs();
+
+ BrowserNativeFingerprinting_Fingerprint* fingerprint =
+ data->mutable_fingerprint();
+
+ fingerprint->set_operating_system_build(GetOperatingSystemVersion());
+ fingerprint->set_browser_install_time_ms(GetInstallTimeMs());
+ fingerprint->set_utc_offset_ms(GetTimezoneOffsetMs());
+ fingerprint->set_browser_language(
+ content::GetContentClient()->browser()->GetApplicationLocale());
+ fingerprint->set_charset(prefs->GetString(prefs::kDefaultCharset));
+ fingerprint->set_user_agent(content::GetContentClient()->GetUserAgent());
+ fingerprint->set_ram(base::SysInfo::AmountOfPhysicalMemory());
+ fingerprint->set_browser_build(chrome::VersionInfo().Version());
+ AddFontsToFingerprint(*fonts.get(), fingerprint);
+ AddPluginsToFingerprint(plugins, fingerprint);
+ AddAcceptLanguagesToFingerprint(*prefs, fingerprint);
+ AddScreenInfoToFingerprint(fingerprint);
+ AddCpuInfoToFingerprint(fingerprint);
+ AddGpuInfoToFingerprint(fingerprint);
+
+ // TODO(isherman): Store the user's screen color depth by refactoring the code
+ // for RenderWidgetHostImpl::GetWebScreenInfo().
+ // TODO(isherman): Store the user's unavailable screen size, likewise by
+ // fetching the WebScreenInfo that RenderWidgetHostImpl::GetWebScreenInfo()
+ // provides.
+ // TODO(isherman): Store the partition size of the hard drives?
+
+ BrowserNativeFingerprinting_State* transient_state = data->mutable_state();
+ BrowserNativeFingerprinting_Dimension* inner_window_size =
+ transient_state->mutable_inner_window_size();
+ inner_window_size->set_width(window_rect.width());
+ inner_window_size->set_height(window_rect.height());
+ BrowserNativeFingerprinting_Dimension* outer_window_size =
+ transient_state->mutable_outer_window_size();
+ outer_window_size->set_width(content_rect.width());
+ outer_window_size->set_height(content_rect.height());
+
+ // TODO(isherman): Record network performance data, which is theoretically
+ // available to JS.
+
+ // TODO(isherman): Record user behavior data.
+
+ BrowserNativeFingerprinting_Metadata* metadata = data->mutable_metadata();
+ metadata->set_timestamp_ms(GetMillisecondsSinceEpoch(base::Time::Now()));
+ metadata->set_gaia_id(gaia_id);
+ metadata->set_fingerprinter_version(kFingerprinterVersion);
+
+ // TODO(isherman): REMOVEME
+ DLOG(WARNING) << "\n" << data->DebugString();
+}
+
+void OnGotFonts(int64 gaia_id,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& content_rect,
+ scoped_ptr<BrowserNativeFingerprinting> data,
+ scoped_ptr<base::ListValue> fonts) {
+ content::PluginService::GetInstance()->GetPlugins(
Evan Stade 2012/12/19 03:13:27 it seems like you could create one class that does
Ilya Sherman 2012/12/20 04:06:49 Done.
+ base::Bind(&GetMachineFingerprintImpl, gaia_id, window_rect, content_rect,
+ base::Passed(&data), base::Passed(&fonts)));
+}
+
+// Waits for GPU data to be loaded; then fires off a task to continue loading
+// other data needed for fingerprinting.
+class GpuDataLoader : public content::GpuDataManagerObserver {
+ public:
+ GpuDataLoader(int64 gaia_id,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& content_rect,
+ scoped_ptr<BrowserNativeFingerprinting> data);
+
+ private:
+ virtual ~GpuDataLoader();
+
+ // content::GpuDataManagerObserver:
+ virtual void OnGpuInfoUpdate() OVERRIDE;
+ virtual void OnVideoMemoryUsageStatsUpdate(
+ const content::GPUVideoMemoryUsageStats& video_memory_usage_stats)
+ OVERRIDE;
+
+ // Continues on to the next loading phase for fingerprinting: loading fonts.
+ void LoadFonts();
+
+ // The GPU data provider.
+ content::GpuDataManager* const gpu_data_manager_;
+
+ // Data that will be passed on to the next loading phase.
Evan Stade 2012/12/19 03:13:27 it would make more sense to me if you passed this
Ilya Sherman 2012/12/20 04:06:49 moot.
+ const int64 gaia_id_;
+ const gfx::Rect window_rect_;
+ const gfx::Rect content_rect_;
+ scoped_ptr<BrowserNativeFingerprinting> data_;
+
+ DISALLOW_COPY_AND_ASSIGN(GpuDataLoader);
+};
+
+GpuDataLoader::GpuDataLoader(int64 gaia_id,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& content_rect,
+ scoped_ptr<BrowserNativeFingerprinting> data)
+ : gpu_data_manager_(content::GpuDataManager::GetInstance()),
+ gaia_id_(gaia_id),
+ window_rect_(window_rect),
+ content_rect_(content_rect),
+ data_(data.Pass()) {
+ if (gpu_data_manager_->IsCompleteGpuInfoAvailable()) {
+ LoadFonts();
+ } else {
+ gpu_data_manager_->RequestCompleteGpuInfoIfNeeded();
+ gpu_data_manager_->AddObserver(this);
+ }
+}
+
+GpuDataLoader::~GpuDataLoader() {
+ gpu_data_manager_->RemoveObserver(this);
+}
+
+void GpuDataLoader::OnGpuInfoUpdate() {
+ if (gpu_data_manager_->IsCompleteGpuInfoAvailable())
+ LoadFonts();
+}
+
+void GpuDataLoader::OnVideoMemoryUsageStatsUpdate(
+ const content::GPUVideoMemoryUsageStats& video_memory_usage_stats) {
+}
+
+void GpuDataLoader::LoadFonts() {
+ content::GetFontListAsync(
+ base::Bind(&OnGotFonts, gaia_id_, window_rect_, content_rect_,
+ base::Passed(&data_)));
+
+ delete this;
+}
+
+
+} // namespace
+
+// TODO(isherman): The variable |data| could use a more descriptive name. Any
+// suggestions?
+void GetMachineFingerprint(int64 gaia_id,
+ const gfx::Rect& window_rect,
+ const gfx::Rect& content_rect,
+ scoped_ptr<BrowserNativeFingerprinting> data) {
+ // Begin loading all of the data that we need to load asynchronously.
+ // This class is responsible for freeing its own memory.
+ new GpuDataLoader(gaia_id, window_rect, content_rect, data.Pass());
+}
+
+} // namespace risk
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698