| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // Generating a fingerprint consists of two major steps: | 5 // Generating a fingerprint consists of two major steps: |
| 6 // (1) Gather all the necessary data. | 6 // (1) Gather all the necessary data. |
| 7 // (2) Write it into a protocol buffer. | 7 // (2) Write it into a protocol buffer. |
| 8 // | 8 // |
| 9 // Step (2) is as simple as it sounds -- it's really just a matter of copying | 9 // Step (2) is as simple as it sounds -- it's really just a matter of copying |
| 10 // data. Step (1) requires waiting on several asynchronous callbacks, which are | 10 // data. Step (1) requires waiting on several asynchronous callbacks, which are |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 graphics->set_driver_version(gpu_info.driver_version); | 172 graphics->set_driver_version(gpu_info.driver_version); |
| 173 graphics->set_driver_date(gpu_info.driver_date); | 173 graphics->set_driver_date(gpu_info.driver_date); |
| 174 | 174 |
| 175 Fingerprint::MachineCharacteristics::Graphics::PerformanceStatistics* | 175 Fingerprint::MachineCharacteristics::Graphics::PerformanceStatistics* |
| 176 gpu_performance = graphics->mutable_performance_statistics(); | 176 gpu_performance = graphics->mutable_performance_statistics(); |
| 177 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); | 177 gpu_performance->set_graphics_score(gpu_info.performance_stats.graphics); |
| 178 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); | 178 gpu_performance->set_gaming_score(gpu_info.performance_stats.gaming); |
| 179 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); | 179 gpu_performance->set_overall_score(gpu_info.performance_stats.overall); |
| 180 } | 180 } |
| 181 | 181 |
| 182 // Waits for geoposition data to be loaded. Lives on the IO thread. | |
| 183 class GeopositionLoader { | |
| 184 public: | |
| 185 // |callback_| will be called on the UI thread with the loaded geoposition, | |
| 186 // once it is available. | |
| 187 GeopositionLoader( | |
| 188 const base::TimeDelta& timeout, | |
| 189 const base::Callback<void(const content::Geoposition&)>& callback); | |
| 190 ~GeopositionLoader() {} | |
| 191 | |
| 192 private: | |
| 193 // Methods to communicate with the GeolocationProvider. | |
| 194 void OnGotGeoposition(const content::Geoposition& geoposition); | |
| 195 | |
| 196 // The callback that will be called once the geoposition is available. | |
| 197 // Will be called on the UI thread. | |
| 198 const base::Callback<void(const content::Geoposition&)> callback_; | |
| 199 | |
| 200 // The callback used as an "observer" of the GeolocationProvider. | |
| 201 content::GeolocationProvider::LocationUpdateCallback geolocation_callback_; | |
| 202 | |
| 203 // Timer to enforce a maximum timeout before the |callback_| is called, even | |
| 204 // if the geoposition has not been loaded. | |
| 205 base::OneShotTimer<GeopositionLoader> timeout_timer_; | |
| 206 }; | |
| 207 | |
| 208 GeopositionLoader::GeopositionLoader( | |
| 209 const base::TimeDelta& timeout, | |
| 210 const base::Callback<void(const content::Geoposition&)>& callback) | |
| 211 : callback_(callback) { | |
| 212 timeout_timer_.Start(FROM_HERE, timeout, | |
| 213 base::Bind(&GeopositionLoader::OnGotGeoposition, | |
| 214 base::Unretained(this), | |
| 215 content::Geoposition())); | |
| 216 | |
| 217 geolocation_callback_ = | |
| 218 base::Bind(&GeopositionLoader::OnGotGeoposition, base::Unretained(this)); | |
| 219 content::GeolocationProvider::GetInstance()->AddLocationUpdateCallback( | |
| 220 geolocation_callback_, false); | |
| 221 } | |
| 222 | |
| 223 void GeopositionLoader::OnGotGeoposition( | |
| 224 const content::Geoposition& geoposition) { | |
| 225 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, | |
| 226 base::Bind(callback_, geoposition)); | |
| 227 | |
| 228 // Unregister as an observer, since this class instance might be destroyed | |
| 229 // after this callback. Note: It's important to unregister *after* posting | |
| 230 // the task above. Unregistering as an observer can have the side-effect of | |
| 231 // modifying the value of |geoposition|. | |
| 232 bool removed = | |
| 233 content::GeolocationProvider::GetInstance()->RemoveLocationUpdateCallback( | |
| 234 geolocation_callback_); | |
| 235 DCHECK(removed); | |
| 236 | |
| 237 delete this; | |
| 238 } | |
| 239 | |
| 240 // Asynchronously loads the user's current geoposition and calls |callback_| on | |
| 241 // the UI thread with the loaded geoposition, once it is available. Expected to | |
| 242 // be called on the IO thread. | |
| 243 void LoadGeoposition( | |
| 244 const base::TimeDelta& timeout, | |
| 245 const base::Callback<void(const content::Geoposition&)>& callback) { | |
| 246 // The loader is responsible for freeing its own memory. | |
| 247 new GeopositionLoader(timeout, callback); | |
| 248 } | |
| 249 | |
| 250 // Waits for all asynchronous data required for the fingerprint to be loaded, | 182 // Waits for all asynchronous data required for the fingerprint to be loaded, |
| 251 // then fills out the fingerprint. | 183 // then fills out the fingerprint. |
| 252 class FingerprintDataLoader : public content::GpuDataManagerObserver { | 184 class FingerprintDataLoader : public content::GpuDataManagerObserver { |
| 253 public: | 185 public: |
| 254 FingerprintDataLoader( | 186 FingerprintDataLoader( |
| 255 uint64 obfuscated_gaia_id, | 187 uint64 obfuscated_gaia_id, |
| 256 const gfx::Rect& window_bounds, | 188 const gfx::Rect& window_bounds, |
| 257 const gfx::Rect& content_bounds, | 189 const gfx::Rect& content_bounds, |
| 258 const WebScreenInfo& screen_info, | 190 const WebScreenInfo& screen_info, |
| 259 const std::string& version, | 191 const std::string& version, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // if not all asynchronous data has been loaded. | 246 // if not all asynchronous data has been loaded. |
| 315 base::OneShotTimer<FingerprintDataLoader> timeout_timer_; | 247 base::OneShotTimer<FingerprintDataLoader> timeout_timer_; |
| 316 | 248 |
| 317 // For invalidating asynchronous callbacks that might arrive after |this| | 249 // For invalidating asynchronous callbacks that might arrive after |this| |
| 318 // instance is destroyed. | 250 // instance is destroyed. |
| 319 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; | 251 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; |
| 320 | 252 |
| 321 // The callback that will be called once all the data is available. | 253 // The callback that will be called once all the data is available. |
| 322 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; | 254 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; |
| 323 | 255 |
| 256 // The callback used as an "observer" of the GeolocationProvider. |
| 257 scoped_ptr<content::GeolocationProvider::Subscription> |
| 258 geolocation_subscription_; |
| 259 |
| 324 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); | 260 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); |
| 325 }; | 261 }; |
| 326 | 262 |
| 327 FingerprintDataLoader::FingerprintDataLoader( | 263 FingerprintDataLoader::FingerprintDataLoader( |
| 328 uint64 obfuscated_gaia_id, | 264 uint64 obfuscated_gaia_id, |
| 329 const gfx::Rect& window_bounds, | 265 const gfx::Rect& window_bounds, |
| 330 const gfx::Rect& content_bounds, | 266 const gfx::Rect& content_bounds, |
| 331 const WebScreenInfo& screen_info, | 267 const WebScreenInfo& screen_info, |
| 332 const std::string& version, | 268 const std::string& version, |
| 333 const std::string& charset, | 269 const std::string& charset, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 #else | 309 #else |
| 374 waiting_on_plugins_ = false; | 310 waiting_on_plugins_ = false; |
| 375 #endif | 311 #endif |
| 376 | 312 |
| 377 // Load font data. | 313 // Load font data. |
| 378 content::GetFontListAsync( | 314 content::GetFontListAsync( |
| 379 base::Bind(&FingerprintDataLoader::OnGotFonts, | 315 base::Bind(&FingerprintDataLoader::OnGotFonts, |
| 380 weak_ptr_factory_.GetWeakPtr())); | 316 weak_ptr_factory_.GetWeakPtr())); |
| 381 | 317 |
| 382 // Load geolocation data. | 318 // Load geolocation data. |
| 383 content::BrowserThread::PostTask( | 319 geolocation_subscription_ = content::GeolocationProvider::GetInstance()-> |
| 384 content::BrowserThread::IO, FROM_HERE, | 320 AddLocationUpdateCallback( |
| 385 base::Bind(&LoadGeoposition, | 321 base::Bind(&FingerprintDataLoader::OnGotGeoposition, |
| 386 timeout, | 322 weak_ptr_factory_.GetWeakPtr()), |
| 387 base::Bind(&FingerprintDataLoader::OnGotGeoposition, | 323 false); |
| 388 weak_ptr_factory_.GetWeakPtr()))); | |
| 389 } | 324 } |
| 390 | 325 |
| 391 void FingerprintDataLoader::OnGpuInfoUpdate() { | 326 void FingerprintDataLoader::OnGpuInfoUpdate() { |
| 392 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable()) | 327 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable()) |
| 393 return; | 328 return; |
| 394 | 329 |
| 395 gpu_observer_.Remove(gpu_data_manager_); | 330 gpu_observer_.Remove(gpu_data_manager_); |
| 396 MaybeFillFingerprint(); | 331 MaybeFillFingerprint(); |
| 397 } | 332 } |
| 398 | 333 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 410 MaybeFillFingerprint(); | 345 MaybeFillFingerprint(); |
| 411 } | 346 } |
| 412 | 347 |
| 413 void FingerprintDataLoader::OnGotGeoposition( | 348 void FingerprintDataLoader::OnGotGeoposition( |
| 414 const content::Geoposition& geoposition) { | 349 const content::Geoposition& geoposition) { |
| 415 DCHECK(!geoposition_.Validate()); | 350 DCHECK(!geoposition_.Validate()); |
| 416 | 351 |
| 417 geoposition_ = geoposition; | 352 geoposition_ = geoposition; |
| 418 DCHECK(geoposition_.Validate() || | 353 DCHECK(geoposition_.Validate() || |
| 419 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE); | 354 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE); |
| 355 geolocation_subscription_.reset(); |
| 420 | 356 |
| 421 MaybeFillFingerprint(); | 357 MaybeFillFingerprint(); |
| 422 } | 358 } |
| 423 | 359 |
| 424 void FingerprintDataLoader::MaybeFillFingerprint() { | 360 void FingerprintDataLoader::MaybeFillFingerprint() { |
| 425 // If all of the data has been loaded, or if the |timeout_timer_| has expired, | 361 // If all of the data has been loaded, or if the |timeout_timer_| has expired, |
| 426 // fill the fingerprint and clean up. | 362 // fill the fingerprint and clean up. |
| 427 if (!timeout_timer_.IsRunning() || | 363 if (!timeout_timer_.IsRunning() || |
| 428 ((!gpu_data_manager_->GpuAccessAllowed(NULL) || | 364 ((!gpu_data_manager_->GpuAccessAllowed(NULL) || |
| 429 gpu_data_manager_->IsCompleteGpuInfoAvailable()) && | 365 gpu_data_manager_->IsCompleteGpuInfoAvailable()) && |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); | 483 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); |
| 548 | 484 |
| 549 internal::GetFingerprintInternal( | 485 internal::GetFingerprintInternal( |
| 550 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, | 486 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, |
| 551 charset, accept_languages, install_time, app_locale, user_agent, | 487 charset, accept_languages, install_time, app_locale, user_agent, |
| 552 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); | 488 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); |
| 553 } | 489 } |
| 554 | 490 |
| 555 } // namespace risk | 491 } // namespace risk |
| 556 } // namespace autofill | 492 } // namespace autofill |
| OLD | NEW |