| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/browser/risk/fingerprint.h" | 5 #include "components/autofill/browser/risk/fingerprint.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); | 172 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); |
| 173 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); | 173 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); |
| 174 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); | 174 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Waits for all asynchronous data required for the fingerprint to be loaded; | 177 // Waits for all asynchronous data required for the fingerprint to be loaded; |
| 178 // then fills out the fingerprint. | 178 // then fills out the fingerprint. |
| 179 class FingerprintDataLoader : public content::GpuDataManagerObserver { | 179 class FingerprintDataLoader : public content::GpuDataManagerObserver { |
| 180 public: | 180 public: |
| 181 FingerprintDataLoader( | 181 FingerprintDataLoader( |
| 182 int64 gaia_id, | 182 uint64 obfuscated_gaia_id, |
| 183 const gfx::Rect& window_bounds, | 183 const gfx::Rect& window_bounds, |
| 184 const gfx::Rect& content_bounds, | 184 const gfx::Rect& content_bounds, |
| 185 const WebScreenInfo& screen_info, | 185 const WebScreenInfo& screen_info, |
| 186 const std::string& version, | 186 const std::string& version, |
| 187 const std::string& charset, | 187 const std::string& charset, |
| 188 const std::string& accept_languages, | 188 const std::string& accept_languages, |
| 189 const base::Time& install_time, | 189 const base::Time& install_time, |
| 190 DialogType dialog_type, | 190 DialogType dialog_type, |
| 191 const std::string& app_locale, | 191 const std::string& app_locale, |
| 192 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); | 192 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 205 // the fingerprint data. | 205 // the fingerprint data. |
| 206 void MaybeFillFingerprint(); | 206 void MaybeFillFingerprint(); |
| 207 | 207 |
| 208 // Calls |callback_| with the fingerprint data. | 208 // Calls |callback_| with the fingerprint data. |
| 209 void FillFingerprint(); | 209 void FillFingerprint(); |
| 210 | 210 |
| 211 // The GPU data provider. | 211 // The GPU data provider. |
| 212 content::GpuDataManager* const gpu_data_manager_; | 212 content::GpuDataManager* const gpu_data_manager_; |
| 213 | 213 |
| 214 // Data that will be passed on to the next loading phase. | 214 // Data that will be passed on to the next loading phase. |
| 215 const int64 gaia_id_; | 215 const uint64 obfuscated_gaia_id_; |
| 216 const gfx::Rect window_bounds_; | 216 const gfx::Rect window_bounds_; |
| 217 const gfx::Rect content_bounds_; | 217 const gfx::Rect content_bounds_; |
| 218 const WebScreenInfo screen_info_; | 218 const WebScreenInfo screen_info_; |
| 219 const std::string version_; | 219 const std::string version_; |
| 220 const std::string charset_; | 220 const std::string charset_; |
| 221 const std::string accept_languages_; | 221 const std::string accept_languages_; |
| 222 const base::Time install_time_; | 222 const base::Time install_time_; |
| 223 DialogType dialog_type_; | 223 DialogType dialog_type_; |
| 224 | 224 |
| 225 // Data that will be loaded asynchronously. | 225 // Data that will be loaded asynchronously. |
| 226 scoped_ptr<base::ListValue> fonts_; | 226 scoped_ptr<base::ListValue> fonts_; |
| 227 std::vector<webkit::WebPluginInfo> plugins_; | 227 std::vector<webkit::WebPluginInfo> plugins_; |
| 228 bool has_loaded_plugins_; | 228 bool has_loaded_plugins_; |
| 229 | 229 |
| 230 // The current application locale. | 230 // The current application locale. |
| 231 std::string app_locale_; | 231 std::string app_locale_; |
| 232 | 232 |
| 233 // The callback that will be called once all the data is available. | 233 // The callback that will be called once all the data is available. |
| 234 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; | 234 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; |
| 235 | 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); | 236 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 FingerprintDataLoader::FingerprintDataLoader( | 239 FingerprintDataLoader::FingerprintDataLoader( |
| 240 int64 gaia_id, | 240 uint64 obfuscated_gaia_id, |
| 241 const gfx::Rect& window_bounds, | 241 const gfx::Rect& window_bounds, |
| 242 const gfx::Rect& content_bounds, | 242 const gfx::Rect& content_bounds, |
| 243 const WebScreenInfo& screen_info, | 243 const WebScreenInfo& screen_info, |
| 244 const std::string& version, | 244 const std::string& version, |
| 245 const std::string& charset, | 245 const std::string& charset, |
| 246 const std::string& accept_languages, | 246 const std::string& accept_languages, |
| 247 const base::Time& install_time, | 247 const base::Time& install_time, |
| 248 DialogType dialog_type, | 248 DialogType dialog_type, |
| 249 const std::string& app_locale, | 249 const std::string& app_locale, |
| 250 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) | 250 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) |
| 251 : gpu_data_manager_(content::GpuDataManager::GetInstance()), | 251 : gpu_data_manager_(content::GpuDataManager::GetInstance()), |
| 252 gaia_id_(gaia_id), | 252 obfuscated_gaia_id_(obfuscated_gaia_id), |
| 253 window_bounds_(window_bounds), | 253 window_bounds_(window_bounds), |
| 254 content_bounds_(content_bounds), | 254 content_bounds_(content_bounds), |
| 255 screen_info_(screen_info), | 255 screen_info_(screen_info), |
| 256 version_(version), | 256 version_(version), |
| 257 charset_(charset), | 257 charset_(charset), |
| 258 accept_languages_(accept_languages), | 258 accept_languages_(accept_languages), |
| 259 install_time_(install_time), | 259 install_time_(install_time), |
| 260 dialog_type_(dialog_type), | 260 dialog_type_(dialog_type), |
| 261 has_loaded_plugins_(false), | 261 has_loaded_plugins_(false), |
| 262 callback_(callback) { | 262 callback_(callback) { |
| 263 DCHECK(!install_time_.is_null()); | 263 DCHECK(!install_time_.is_null()); |
| 264 | 264 |
| 265 // Load GPU data if needed. | 265 // Load GPU data if needed. |
| 266 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable()) { | 266 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable()) { |
| 267 gpu_data_manager_->AddObserver(this); | 267 gpu_data_manager_->AddObserver(this); |
| 268 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); | 268 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 #if defined(USE_PLUGINS) |
| 271 // Load plugin data. | 272 // Load plugin data. |
| 272 content::PluginService::GetInstance()->GetPlugins( | 273 content::PluginService::GetInstance()->GetPlugins( |
| 273 base::Bind(&FingerprintDataLoader::OnGotPlugins, base::Unretained(this))); | 274 base::Bind(&FingerprintDataLoader::OnGotPlugins, base::Unretained(this))); |
| 275 #endif |
| 274 | 276 |
| 275 // Load font data. | 277 // Load font data. |
| 276 content::GetFontListAsync( | 278 content::GetFontListAsync( |
| 277 base::Bind(&FingerprintDataLoader::OnGotFonts, base::Unretained(this))); | 279 base::Bind(&FingerprintDataLoader::OnGotFonts, base::Unretained(this))); |
| 278 } | 280 } |
| 279 | 281 |
| 280 FingerprintDataLoader::~FingerprintDataLoader() { | 282 FingerprintDataLoader::~FingerprintDataLoader() { |
| 281 } | 283 } |
| 282 | 284 |
| 283 void FingerprintDataLoader::OnGpuInfoUpdate() { | 285 void FingerprintDataLoader::OnGpuInfoUpdate() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 297 void FingerprintDataLoader::OnGotPlugins( | 299 void FingerprintDataLoader::OnGotPlugins( |
| 298 const std::vector<webkit::WebPluginInfo>& plugins) { | 300 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 299 DCHECK(!has_loaded_plugins_); | 301 DCHECK(!has_loaded_plugins_); |
| 300 has_loaded_plugins_ = true; | 302 has_loaded_plugins_ = true; |
| 301 plugins_ = plugins; | 303 plugins_ = plugins; |
| 302 MaybeFillFingerprint(); | 304 MaybeFillFingerprint(); |
| 303 } | 305 } |
| 304 | 306 |
| 305 void FingerprintDataLoader::MaybeFillFingerprint() { | 307 void FingerprintDataLoader::MaybeFillFingerprint() { |
| 306 // If all of the data has been loaded, fill the fingerprint and clean up. | 308 // If all of the data has been loaded, fill the fingerprint and clean up. |
| 307 if (gpu_data_manager_->IsCompleteGpuInfoAvailable() && | 309 bool finished = gpu_data_manager_->IsCompleteGpuInfoAvailable() && fonts_; |
| 308 fonts_ && | 310 #if defined(USE_PLUGINS) |
| 309 has_loaded_plugins_) { | 311 finished = finished && has_loaded_plugins_; |
| 312 #endif |
| 313 if (finished) { |
| 310 FillFingerprint(); | 314 FillFingerprint(); |
| 311 delete this; | 315 delete this; |
| 312 } | 316 } |
| 313 } | 317 } |
| 314 | 318 |
| 315 void FingerprintDataLoader::FillFingerprint() { | 319 void FingerprintDataLoader::FillFingerprint() { |
| 316 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); | 320 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); |
| 317 Fingerprint_MachineCharacteristics* machine = | 321 Fingerprint_MachineCharacteristics* machine = |
| 318 fingerprint->mutable_machine_characteristics(); | 322 fingerprint->mutable_machine_characteristics(); |
| 319 | 323 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 350 outer_window_size->set_height(window_bounds_.height()); | 354 outer_window_size->set_height(window_bounds_.height()); |
| 351 | 355 |
| 352 // TODO(isherman): Record network performance data, which is theoretically | 356 // TODO(isherman): Record network performance data, which is theoretically |
| 353 // available to JS. | 357 // available to JS. |
| 354 | 358 |
| 355 // TODO(isherman): Record user behavior data. | 359 // TODO(isherman): Record user behavior data. |
| 356 | 360 |
| 357 Fingerprint_Metadata* metadata = fingerprint->mutable_metadata(); | 361 Fingerprint_Metadata* metadata = fingerprint->mutable_metadata(); |
| 358 metadata->set_timestamp_ms( | 362 metadata->set_timestamp_ms( |
| 359 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); | 363 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); |
| 360 metadata->set_gaia_id(gaia_id_); | 364 metadata->set_obfuscated_gaia_id(obfuscated_gaia_id_); |
| 361 metadata->set_fingerprinter_version(kFingerprinterVersion); | 365 metadata->set_fingerprinter_version(kFingerprinterVersion); |
| 362 | 366 |
| 363 callback_.Run(fingerprint.Pass()); | 367 callback_.Run(fingerprint.Pass()); |
| 364 } | 368 } |
| 365 | 369 |
| 366 } // namespace | 370 } // namespace |
| 367 | 371 |
| 368 void GetFingerprint( | 372 void GetFingerprint( |
| 369 int64 gaia_id, | 373 uint64 obfuscated_gaia_id, |
| 370 const gfx::Rect& window_bounds, | 374 const gfx::Rect& window_bounds, |
| 371 const content::WebContents& web_contents, | 375 const content::WebContents& web_contents, |
| 372 const std::string& version, | 376 const std::string& version, |
| 373 const std::string& charset, | 377 const std::string& charset, |
| 374 const std::string& accept_languages, | 378 const std::string& accept_languages, |
| 375 const base::Time& install_time, | 379 const base::Time& install_time, |
| 376 DialogType dialog_type, | 380 DialogType dialog_type, |
| 377 const std::string& app_locale, | 381 const std::string& app_locale, |
| 378 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 382 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
| 379 gfx::Rect content_bounds; | 383 gfx::Rect content_bounds; |
| 380 web_contents.GetView()->GetContainerBounds(&content_bounds); | 384 web_contents.GetView()->GetContainerBounds(&content_bounds); |
| 381 | 385 |
| 382 WebKit::WebScreenInfo screen_info; | 386 WebKit::WebScreenInfo screen_info; |
| 383 content::RenderWidgetHostView* host_view = | 387 content::RenderWidgetHostView* host_view = |
| 384 web_contents.GetRenderWidgetHostView(); | 388 web_contents.GetRenderWidgetHostView(); |
| 385 if (host_view) | 389 if (host_view) |
| 386 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); | 390 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); |
| 387 | 391 |
| 388 internal::GetFingerprintInternal( | 392 internal::GetFingerprintInternal( |
| 389 gaia_id, window_bounds, content_bounds, screen_info, version, charset, | 393 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, |
| 390 accept_languages, install_time, dialog_type, app_locale, callback); | 394 charset, accept_languages, install_time, dialog_type, app_locale, |
| 395 callback); |
| 391 } | 396 } |
| 392 | 397 |
| 393 namespace internal { | 398 namespace internal { |
| 394 | 399 |
| 395 void GetFingerprintInternal( | 400 void GetFingerprintInternal( |
| 396 int64 gaia_id, | 401 uint64 obfuscated_gaia_id, |
| 397 const gfx::Rect& window_bounds, | 402 const gfx::Rect& window_bounds, |
| 398 const gfx::Rect& content_bounds, | 403 const gfx::Rect& content_bounds, |
| 399 const WebKit::WebScreenInfo& screen_info, | 404 const WebKit::WebScreenInfo& screen_info, |
| 400 const std::string& version, | 405 const std::string& version, |
| 401 const std::string& charset, | 406 const std::string& charset, |
| 402 const std::string& accept_languages, | 407 const std::string& accept_languages, |
| 403 const base::Time& install_time, | 408 const base::Time& install_time, |
| 404 DialogType dialog_type, | 409 DialogType dialog_type, |
| 405 const std::string& app_locale, | 410 const std::string& app_locale, |
| 406 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 411 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
| 407 // Begin loading all of the data that we need to load asynchronously. | 412 // Begin loading all of the data that we need to load asynchronously. |
| 408 // This class is responsible for freeing its own memory. | 413 // This class is responsible for freeing its own memory. |
| 409 new FingerprintDataLoader(gaia_id, window_bounds, content_bounds, screen_info, | 414 new FingerprintDataLoader(obfuscated_gaia_id, window_bounds, content_bounds, |
| 410 version, charset, accept_languages, install_time, | 415 screen_info, version, charset, accept_languages, |
| 411 dialog_type, app_locale, callback); | 416 install_time, dialog_type, app_locale, callback); |
| 412 } | 417 } |
| 413 | 418 |
| 414 } // namespace internal | 419 } // namespace internal |
| 415 | 420 |
| 416 } // namespace risk | 421 } // namespace risk |
| 417 } // namespace autofill | 422 } // namespace autofill |
| OLD | NEW |