Chromium Code Reviews| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); | 175 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); |
| 176 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); | 176 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); |
| 177 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); | 177 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Waits for all asynchronous data required for the fingerprint to be loaded; | 180 // Waits for all asynchronous data required for the fingerprint to be loaded; |
| 181 // then fills out the fingerprint. | 181 // then fills out the fingerprint. |
| 182 class FingerprintDataLoader : public content::GpuDataManagerObserver { | 182 class FingerprintDataLoader : public content::GpuDataManagerObserver { |
| 183 public: | 183 public: |
| 184 FingerprintDataLoader( | 184 FingerprintDataLoader( |
| 185 int64 gaia_id, | 185 uint64 obfuscated_gaia_id, |
| 186 const gfx::Rect& window_bounds, | 186 const gfx::Rect& window_bounds, |
| 187 const gfx::Rect& content_bounds, | 187 const gfx::Rect& content_bounds, |
| 188 const WebScreenInfo& screen_info, | 188 const WebScreenInfo& screen_info, |
| 189 const std::string& version, | 189 const std::string& version, |
| 190 const std::string& charset, | 190 const std::string& charset, |
| 191 const std::string& accept_languages, | 191 const std::string& accept_languages, |
| 192 const base::Time& install_time, | 192 const base::Time& install_time, |
| 193 DialogType dialog_type, | 193 DialogType dialog_type, |
| 194 const std::string& app_locale, | 194 const std::string& app_locale, |
| 195 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); | 195 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 218 void FillFingerprint(); | 218 void FillFingerprint(); |
| 219 | 219 |
| 220 // The GPU data provider. | 220 // The GPU data provider. |
| 221 content::GpuDataManager* const gpu_data_manager_; | 221 content::GpuDataManager* const gpu_data_manager_; |
| 222 | 222 |
| 223 // The callback used as an "observer" of the GeolocationProvider. Accessed | 223 // The callback used as an "observer" of the GeolocationProvider. Accessed |
| 224 // only on the IO thread. | 224 // only on the IO thread. |
| 225 content::GeolocationProvider::LocationUpdateCallback geolocation_callback_; | 225 content::GeolocationProvider::LocationUpdateCallback geolocation_callback_; |
| 226 | 226 |
| 227 // Data that will be passed on to the next loading phase. | 227 // Data that will be passed on to the next loading phase. |
| 228 const int64 gaia_id_; | 228 const uint64 obfuscated_gaia_id_; |
| 229 const gfx::Rect window_bounds_; | 229 const gfx::Rect window_bounds_; |
| 230 const gfx::Rect content_bounds_; | 230 const gfx::Rect content_bounds_; |
| 231 const WebScreenInfo screen_info_; | 231 const WebScreenInfo screen_info_; |
| 232 const std::string version_; | 232 const std::string version_; |
| 233 const std::string charset_; | 233 const std::string charset_; |
| 234 const std::string accept_languages_; | 234 const std::string accept_languages_; |
| 235 const base::Time install_time_; | 235 const base::Time install_time_; |
| 236 DialogType dialog_type_; | 236 DialogType dialog_type_; |
| 237 | 237 |
| 238 // Data that will be loaded asynchronously. | 238 // Data that will be loaded asynchronously. |
| 239 scoped_ptr<base::ListValue> fonts_; | 239 scoped_ptr<base::ListValue> fonts_; |
| 240 std::vector<webkit::WebPluginInfo> plugins_; | 240 std::vector<webkit::WebPluginInfo> plugins_; |
| 241 bool has_loaded_plugins_; | 241 bool has_loaded_plugins_; |
| 242 content::Geoposition geoposition_; | 242 content::Geoposition geoposition_; |
| 243 | 243 |
| 244 // The current application locale. | 244 // The current application locale. |
| 245 std::string app_locale_; | 245 std::string app_locale_; |
| 246 | 246 |
| 247 // The callback that will be called once all the data is available. | 247 // The callback that will be called once all the data is available. |
| 248 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; | 248 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; |
| 249 | 249 |
| 250 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); | 250 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); |
| 251 }; | 251 }; |
| 252 | 252 |
| 253 FingerprintDataLoader::FingerprintDataLoader( | 253 FingerprintDataLoader::FingerprintDataLoader( |
| 254 int64 gaia_id, | 254 uint64 obfuscated_gaia_id, |
| 255 const gfx::Rect& window_bounds, | 255 const gfx::Rect& window_bounds, |
| 256 const gfx::Rect& content_bounds, | 256 const gfx::Rect& content_bounds, |
| 257 const WebScreenInfo& screen_info, | 257 const WebScreenInfo& screen_info, |
| 258 const std::string& version, | 258 const std::string& version, |
| 259 const std::string& charset, | 259 const std::string& charset, |
| 260 const std::string& accept_languages, | 260 const std::string& accept_languages, |
| 261 const base::Time& install_time, | 261 const base::Time& install_time, |
| 262 DialogType dialog_type, | 262 DialogType dialog_type, |
| 263 const std::string& app_locale, | 263 const std::string& app_locale, |
| 264 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) | 264 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) |
| 265 : gpu_data_manager_(content::GpuDataManager::GetInstance()), | 265 : gpu_data_manager_(content::GpuDataManager::GetInstance()), |
| 266 gaia_id_(gaia_id), | 266 obfuscated_gaia_id_(obfuscated_gaia_id), |
| 267 window_bounds_(window_bounds), | 267 window_bounds_(window_bounds), |
| 268 content_bounds_(content_bounds), | 268 content_bounds_(content_bounds), |
| 269 screen_info_(screen_info), | 269 screen_info_(screen_info), |
| 270 version_(version), | 270 version_(version), |
| 271 charset_(charset), | 271 charset_(charset), |
| 272 accept_languages_(accept_languages), | 272 accept_languages_(accept_languages), |
| 273 install_time_(install_time), | 273 install_time_(install_time), |
| 274 dialog_type_(dialog_type), | 274 dialog_type_(dialog_type), |
| 275 has_loaded_plugins_(false), | 275 has_loaded_plugins_(false), |
| 276 callback_(callback) { | 276 callback_(callback) { |
| 277 DCHECK(!install_time_.is_null()); | 277 DCHECK(!install_time_.is_null()); |
| 278 | 278 |
| 279 // Load GPU data if needed. | 279 // Load GPU data if needed. |
| 280 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable()) { | 280 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable()) { |
| 281 gpu_data_manager_->AddObserver(this); | 281 gpu_data_manager_->AddObserver(this); |
| 282 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); | 282 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 #if defined(ENABLE_PLUGINS) | |
| 285 // Load plugin data. | 286 // Load plugin data. |
| 286 content::PluginService::GetInstance()->GetPlugins( | 287 content::PluginService::GetInstance()->GetPlugins( |
| 287 base::Bind(&FingerprintDataLoader::OnGotPlugins, base::Unretained(this))); | 288 base::Bind(&FingerprintDataLoader::OnGotPlugins, base::Unretained(this))); |
| 289 #endif | |
| 288 | 290 |
| 289 // Load font data. | 291 // Load font data. |
| 290 content::GetFontListAsync( | 292 content::GetFontListAsync( |
| 291 base::Bind(&FingerprintDataLoader::OnGotFonts, base::Unretained(this))); | 293 base::Bind(&FingerprintDataLoader::OnGotFonts, base::Unretained(this))); |
| 292 | 294 |
| 293 // Load geolocation data. | 295 // Load geolocation data. |
| 294 content::BrowserThread::PostTask( | 296 content::BrowserThread::PostTask( |
| 295 content::BrowserThread::IO, FROM_HERE, | 297 content::BrowserThread::IO, FROM_HERE, |
| 296 base::Bind(&FingerprintDataLoader::LoadGeoposition, | 298 base::Bind(&FingerprintDataLoader::LoadGeoposition, |
| 297 base::Unretained(this))); | 299 base::Unretained(this))); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 // the task above. Unregistering as an observer can have the side-effect of | 355 // the task above. Unregistering as an observer can have the side-effect of |
| 354 // modifying the value of |geoposition|. | 356 // modifying the value of |geoposition|. |
| 355 bool removed = | 357 bool removed = |
| 356 content::GeolocationProvider::GetInstance()->RemoveLocationUpdateCallback( | 358 content::GeolocationProvider::GetInstance()->RemoveLocationUpdateCallback( |
| 357 geolocation_callback_); | 359 geolocation_callback_); |
| 358 DCHECK(removed); | 360 DCHECK(removed); |
| 359 } | 361 } |
| 360 | 362 |
| 361 void FingerprintDataLoader::MaybeFillFingerprint() { | 363 void FingerprintDataLoader::MaybeFillFingerprint() { |
| 362 // If all of the data has been loaded, fill the fingerprint and clean up. | 364 // If all of the data has been loaded, fill the fingerprint and clean up. |
| 363 if (gpu_data_manager_->IsCompleteGpuInfoAvailable() && | 365 bool finished = gpu_data_manager_->IsCompleteGpuInfoAvailable() && |
| 364 fonts_ && | 366 fonts_ && |
| 365 has_loaded_plugins_ && | 367 has_loaded_plugins_ && |
|
Ilya Sherman
2013/05/22 22:34:24
Did you mean to remove this line? It seems like i
Dan Beam
2013/05/22 23:25:20
this was messed up in a merge conflict, they haven
| |
| 366 (geoposition_.Validate() || | 368 (geoposition_.Validate() || |
| 367 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE)) { | 369 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE); |
| 370 #if defined(ENABLE_PLUGINS) | |
| 371 finished = finished && has_loaded_plugins_; | |
| 372 #endif | |
| 373 if (finished) { | |
| 368 FillFingerprint(); | 374 FillFingerprint(); |
| 369 delete this; | 375 delete this; |
| 370 } | 376 } |
| 371 } | 377 } |
| 372 | 378 |
| 373 void FingerprintDataLoader::FillFingerprint() { | 379 void FingerprintDataLoader::FillFingerprint() { |
| 374 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); | 380 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); |
| 375 Fingerprint_MachineCharacteristics* machine = | 381 Fingerprint_MachineCharacteristics* machine = |
| 376 fingerprint->mutable_machine_characteristics(); | 382 fingerprint->mutable_machine_characteristics(); |
| 377 | 383 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 location->set_latitude(geoposition_.latitude); | 424 location->set_latitude(geoposition_.latitude); |
| 419 location->set_longitude(geoposition_.longitude); | 425 location->set_longitude(geoposition_.longitude); |
| 420 location->set_accuracy(geoposition_.accuracy); | 426 location->set_accuracy(geoposition_.accuracy); |
| 421 location->set_time_in_ms( | 427 location->set_time_in_ms( |
| 422 (geoposition_.timestamp - base::Time::UnixEpoch()).InMilliseconds()); | 428 (geoposition_.timestamp - base::Time::UnixEpoch()).InMilliseconds()); |
| 423 } | 429 } |
| 424 | 430 |
| 425 Fingerprint_Metadata* metadata = fingerprint->mutable_metadata(); | 431 Fingerprint_Metadata* metadata = fingerprint->mutable_metadata(); |
| 426 metadata->set_timestamp_ms( | 432 metadata->set_timestamp_ms( |
| 427 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); | 433 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); |
| 428 metadata->set_gaia_id(gaia_id_); | 434 metadata->set_obfuscated_gaia_id(obfuscated_gaia_id_); |
| 429 metadata->set_fingerprinter_version(kFingerprinterVersion); | 435 metadata->set_fingerprinter_version(kFingerprinterVersion); |
| 430 | 436 |
| 431 callback_.Run(fingerprint.Pass()); | 437 callback_.Run(fingerprint.Pass()); |
| 432 } | 438 } |
| 433 | 439 |
| 434 } // namespace | 440 } // namespace |
| 435 | 441 |
| 436 void GetFingerprint( | 442 void GetFingerprint( |
| 437 int64 gaia_id, | 443 uint64 obfuscated_gaia_id, |
| 438 const gfx::Rect& window_bounds, | 444 const gfx::Rect& window_bounds, |
| 439 const content::WebContents& web_contents, | 445 const content::WebContents& web_contents, |
| 440 const std::string& version, | 446 const std::string& version, |
| 441 const std::string& charset, | 447 const std::string& charset, |
| 442 const std::string& accept_languages, | 448 const std::string& accept_languages, |
| 443 const base::Time& install_time, | 449 const base::Time& install_time, |
| 444 DialogType dialog_type, | 450 DialogType dialog_type, |
| 445 const std::string& app_locale, | 451 const std::string& app_locale, |
| 446 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 452 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
| 447 gfx::Rect content_bounds; | 453 gfx::Rect content_bounds; |
| 448 web_contents.GetView()->GetContainerBounds(&content_bounds); | 454 web_contents.GetView()->GetContainerBounds(&content_bounds); |
| 449 | 455 |
| 450 WebKit::WebScreenInfo screen_info; | 456 WebKit::WebScreenInfo screen_info; |
| 451 content::RenderWidgetHostView* host_view = | 457 content::RenderWidgetHostView* host_view = |
| 452 web_contents.GetRenderWidgetHostView(); | 458 web_contents.GetRenderWidgetHostView(); |
| 453 if (host_view) | 459 if (host_view) |
| 454 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); | 460 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); |
| 455 | 461 |
| 456 internal::GetFingerprintInternal( | 462 internal::GetFingerprintInternal( |
| 457 gaia_id, window_bounds, content_bounds, screen_info, version, charset, | 463 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, |
| 458 accept_languages, install_time, dialog_type, app_locale, callback); | 464 charset, accept_languages, install_time, dialog_type, app_locale, |
| 465 callback); | |
| 459 } | 466 } |
| 460 | 467 |
| 461 namespace internal { | 468 namespace internal { |
| 462 | 469 |
| 463 void GetFingerprintInternal( | 470 void GetFingerprintInternal( |
| 464 int64 gaia_id, | 471 uint64 obfuscated_gaia_id, |
| 465 const gfx::Rect& window_bounds, | 472 const gfx::Rect& window_bounds, |
| 466 const gfx::Rect& content_bounds, | 473 const gfx::Rect& content_bounds, |
| 467 const WebKit::WebScreenInfo& screen_info, | 474 const WebKit::WebScreenInfo& screen_info, |
| 468 const std::string& version, | 475 const std::string& version, |
| 469 const std::string& charset, | 476 const std::string& charset, |
| 470 const std::string& accept_languages, | 477 const std::string& accept_languages, |
| 471 const base::Time& install_time, | 478 const base::Time& install_time, |
| 472 DialogType dialog_type, | 479 DialogType dialog_type, |
| 473 const std::string& app_locale, | 480 const std::string& app_locale, |
| 474 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 481 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
| 475 // Begin loading all of the data that we need to load asynchronously. | 482 // Begin loading all of the data that we need to load asynchronously. |
| 476 // This class is responsible for freeing its own memory. | 483 // This class is responsible for freeing its own memory. |
| 477 new FingerprintDataLoader(gaia_id, window_bounds, content_bounds, screen_info, | 484 new FingerprintDataLoader(obfuscated_gaia_id, window_bounds, content_bounds, |
| 478 version, charset, accept_languages, install_time, | 485 screen_info, version, charset, accept_languages, |
| 479 dialog_type, app_locale, callback); | 486 install_time, dialog_type, app_locale, callback); |
| 480 } | 487 } |
| 481 | 488 |
| 482 } // namespace internal | 489 } // namespace internal |
| 483 | 490 |
| 484 } // namespace risk | 491 } // namespace risk |
| 485 } // namespace autofill | 492 } // namespace autofill |
| OLD | NEW |