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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 FingerprintDataLoader( | 256 FingerprintDataLoader( |
257 uint64 obfuscated_gaia_id, | 257 uint64 obfuscated_gaia_id, |
258 const gfx::Rect& window_bounds, | 258 const gfx::Rect& window_bounds, |
259 const gfx::Rect& content_bounds, | 259 const gfx::Rect& content_bounds, |
260 const WebScreenInfo& screen_info, | 260 const WebScreenInfo& screen_info, |
261 const std::string& version, | 261 const std::string& version, |
262 const std::string& charset, | 262 const std::string& charset, |
263 const std::string& accept_languages, | 263 const std::string& accept_languages, |
264 const base::Time& install_time, | 264 const base::Time& install_time, |
265 const std::string& app_locale, | 265 const std::string& app_locale, |
266 const std::string& user_agent, | |
267 const base::TimeDelta& timeout, | 266 const base::TimeDelta& timeout, |
268 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); | 267 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); |
269 | 268 |
270 private: | 269 private: |
271 virtual ~FingerprintDataLoader() {} | 270 virtual ~FingerprintDataLoader() {} |
272 | 271 |
273 // content::GpuDataManagerObserver: | 272 // content::GpuDataManagerObserver: |
274 virtual void OnGpuInfoUpdate() OVERRIDE; | 273 virtual void OnGpuInfoUpdate() OVERRIDE; |
275 | 274 |
276 // Callbacks for asynchronously loaded data. | 275 // Callbacks for asynchronously loaded data. |
(...skipping 18 matching lines...) Expand all Loading... |
295 | 294 |
296 // Data that will be passed on to the next loading phase. See the comment for | 295 // Data that will be passed on to the next loading phase. See the comment for |
297 // GetFingerprint() for a description of these variables. | 296 // GetFingerprint() for a description of these variables. |
298 const uint64 obfuscated_gaia_id_; | 297 const uint64 obfuscated_gaia_id_; |
299 const gfx::Rect window_bounds_; | 298 const gfx::Rect window_bounds_; |
300 const gfx::Rect content_bounds_; | 299 const gfx::Rect content_bounds_; |
301 const WebScreenInfo screen_info_; | 300 const WebScreenInfo screen_info_; |
302 const std::string version_; | 301 const std::string version_; |
303 const std::string charset_; | 302 const std::string charset_; |
304 const std::string accept_languages_; | 303 const std::string accept_languages_; |
305 const std::string app_locale_; | |
306 const std::string user_agent_; | |
307 const base::Time install_time_; | 304 const base::Time install_time_; |
308 | 305 |
309 // Data that will be loaded asynchronously. | 306 // Data that will be loaded asynchronously. |
310 scoped_ptr<base::ListValue> fonts_; | 307 scoped_ptr<base::ListValue> fonts_; |
311 std::vector<content::WebPluginInfo> plugins_; | 308 std::vector<content::WebPluginInfo> plugins_; |
312 bool waiting_on_plugins_; | 309 bool waiting_on_plugins_; |
313 content::Geoposition geoposition_; | 310 content::Geoposition geoposition_; |
314 | 311 |
315 // Timer to enforce a maximum timeout before the |callback_| is called, even | 312 // Timer to enforce a maximum timeout before the |callback_| is called, even |
316 // if not all asynchronous data has been loaded. | 313 // if not all asynchronous data has been loaded. |
317 base::OneShotTimer<FingerprintDataLoader> timeout_timer_; | 314 base::OneShotTimer<FingerprintDataLoader> timeout_timer_; |
318 | 315 |
319 // For invalidating asynchronous callbacks that might arrive after |this| | 316 // For invalidating asynchronous callbacks that might arrive after |this| |
320 // instance is destroyed. | 317 // instance is destroyed. |
321 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; | 318 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; |
322 | 319 |
| 320 // The current application locale. |
| 321 std::string app_locale_; |
| 322 |
323 // The callback that will be called once all the data is available. | 323 // The callback that will be called once all the data is available. |
324 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; | 324 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; |
325 | 325 |
326 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); | 326 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); |
327 }; | 327 }; |
328 | 328 |
329 FingerprintDataLoader::FingerprintDataLoader( | 329 FingerprintDataLoader::FingerprintDataLoader( |
330 uint64 obfuscated_gaia_id, | 330 uint64 obfuscated_gaia_id, |
331 const gfx::Rect& window_bounds, | 331 const gfx::Rect& window_bounds, |
332 const gfx::Rect& content_bounds, | 332 const gfx::Rect& content_bounds, |
333 const WebScreenInfo& screen_info, | 333 const WebScreenInfo& screen_info, |
334 const std::string& version, | 334 const std::string& version, |
335 const std::string& charset, | 335 const std::string& charset, |
336 const std::string& accept_languages, | 336 const std::string& accept_languages, |
337 const base::Time& install_time, | 337 const base::Time& install_time, |
338 const std::string& app_locale, | 338 const std::string& app_locale, |
339 const std::string& user_agent, | |
340 const base::TimeDelta& timeout, | 339 const base::TimeDelta& timeout, |
341 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) | 340 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) |
342 : gpu_data_manager_(content::GpuDataManager::GetInstance()), | 341 : gpu_data_manager_(content::GpuDataManager::GetInstance()), |
343 gpu_observer_(this), | 342 gpu_observer_(this), |
344 obfuscated_gaia_id_(obfuscated_gaia_id), | 343 obfuscated_gaia_id_(obfuscated_gaia_id), |
345 window_bounds_(window_bounds), | 344 window_bounds_(window_bounds), |
346 content_bounds_(content_bounds), | 345 content_bounds_(content_bounds), |
347 screen_info_(screen_info), | 346 screen_info_(screen_info), |
348 version_(version), | 347 version_(version), |
349 charset_(charset), | 348 charset_(charset), |
350 accept_languages_(accept_languages), | 349 accept_languages_(accept_languages), |
351 app_locale_(app_locale), | |
352 user_agent_(user_agent), | |
353 install_time_(install_time), | 350 install_time_(install_time), |
354 waiting_on_plugins_(true), | 351 waiting_on_plugins_(true), |
355 weak_ptr_factory_(this), | 352 weak_ptr_factory_(this), |
356 callback_(callback) { | 353 callback_(callback) { |
357 DCHECK(!install_time_.is_null()); | 354 DCHECK(!install_time_.is_null()); |
358 | 355 |
359 timeout_timer_.Start(FROM_HERE, timeout, | 356 timeout_timer_.Start(FROM_HERE, timeout, |
360 base::Bind(&FingerprintDataLoader::MaybeFillFingerprint, | 357 base::Bind(&FingerprintDataLoader::MaybeFillFingerprint, |
361 weak_ptr_factory_.GetWeakPtr())); | 358 weak_ptr_factory_.GetWeakPtr())); |
362 | 359 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 Fingerprint::MachineCharacteristics* machine = | 438 Fingerprint::MachineCharacteristics* machine = |
442 fingerprint->mutable_machine_characteristics(); | 439 fingerprint->mutable_machine_characteristics(); |
443 | 440 |
444 machine->set_operating_system_build(GetOperatingSystemVersion()); | 441 machine->set_operating_system_build(GetOperatingSystemVersion()); |
445 // We use the delta between the install time and the Unix epoch, in hours. | 442 // We use the delta between the install time and the Unix epoch, in hours. |
446 machine->set_browser_install_time_hours( | 443 machine->set_browser_install_time_hours( |
447 (install_time_ - base::Time::UnixEpoch()).InHours()); | 444 (install_time_ - base::Time::UnixEpoch()).InHours()); |
448 machine->set_utc_offset_ms(GetTimezoneOffset().InMilliseconds()); | 445 machine->set_utc_offset_ms(GetTimezoneOffset().InMilliseconds()); |
449 machine->set_browser_language(app_locale_); | 446 machine->set_browser_language(app_locale_); |
450 machine->set_charset(charset_); | 447 machine->set_charset(charset_); |
451 machine->set_user_agent(user_agent_); | 448 machine->set_user_agent(content::GetUserAgent(GURL())); |
452 machine->set_ram(base::SysInfo::AmountOfPhysicalMemory()); | 449 machine->set_ram(base::SysInfo::AmountOfPhysicalMemory()); |
453 machine->set_browser_build(version_); | 450 machine->set_browser_build(version_); |
454 machine->set_browser_feature( | 451 machine->set_browser_feature( |
455 Fingerprint::MachineCharacteristics::FEATURE_REQUEST_AUTOCOMPLETE); | 452 Fingerprint::MachineCharacteristics::FEATURE_REQUEST_AUTOCOMPLETE); |
456 if (fonts_) | 453 if (fonts_) |
457 AddFontsToFingerprint(*fonts_, machine); | 454 AddFontsToFingerprint(*fonts_, machine); |
458 AddPluginsToFingerprint(plugins_, machine); | 455 AddPluginsToFingerprint(plugins_, machine); |
459 AddAcceptLanguagesToFingerprint(accept_languages_, machine); | 456 AddAcceptLanguagesToFingerprint(accept_languages_, machine); |
460 AddScreenInfoToFingerprint(screen_info_, machine); | 457 AddScreenInfoToFingerprint(screen_info_, machine); |
461 AddCpuInfoToFingerprint(machine); | 458 AddCpuInfoToFingerprint(machine); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 void GetFingerprintInternal( | 504 void GetFingerprintInternal( |
508 uint64 obfuscated_gaia_id, | 505 uint64 obfuscated_gaia_id, |
509 const gfx::Rect& window_bounds, | 506 const gfx::Rect& window_bounds, |
510 const gfx::Rect& content_bounds, | 507 const gfx::Rect& content_bounds, |
511 const blink::WebScreenInfo& screen_info, | 508 const blink::WebScreenInfo& screen_info, |
512 const std::string& version, | 509 const std::string& version, |
513 const std::string& charset, | 510 const std::string& charset, |
514 const std::string& accept_languages, | 511 const std::string& accept_languages, |
515 const base::Time& install_time, | 512 const base::Time& install_time, |
516 const std::string& app_locale, | 513 const std::string& app_locale, |
517 const std::string& user_agent, | |
518 const base::TimeDelta& timeout, | 514 const base::TimeDelta& timeout, |
519 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 515 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
520 // Begin loading all of the data that we need to load asynchronously. | 516 // Begin loading all of the data that we need to load asynchronously. |
521 // This class is responsible for freeing its own memory. | 517 // This class is responsible for freeing its own memory. |
522 new FingerprintDataLoader(obfuscated_gaia_id, window_bounds, content_bounds, | 518 new FingerprintDataLoader(obfuscated_gaia_id, window_bounds, content_bounds, |
523 screen_info, version, charset, accept_languages, | 519 screen_info, version, charset, accept_languages, |
524 install_time, app_locale, user_agent, timeout, | 520 install_time, app_locale, timeout, callback); |
525 callback); | |
526 } | 521 } |
527 | 522 |
528 } // namespace internal | 523 } // namespace internal |
529 | 524 |
530 void GetFingerprint( | 525 void GetFingerprint( |
531 uint64 obfuscated_gaia_id, | 526 uint64 obfuscated_gaia_id, |
532 const gfx::Rect& window_bounds, | 527 const gfx::Rect& window_bounds, |
533 const content::WebContents& web_contents, | 528 const content::WebContents& web_contents, |
534 const std::string& version, | 529 const std::string& version, |
535 const std::string& charset, | 530 const std::string& charset, |
536 const std::string& accept_languages, | 531 const std::string& accept_languages, |
537 const base::Time& install_time, | 532 const base::Time& install_time, |
538 const std::string& app_locale, | 533 const std::string& app_locale, |
539 const std::string& user_agent, | |
540 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 534 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { |
541 gfx::Rect content_bounds; | 535 gfx::Rect content_bounds; |
542 web_contents.GetView()->GetContainerBounds(&content_bounds); | 536 web_contents.GetView()->GetContainerBounds(&content_bounds); |
543 | 537 |
544 blink::WebScreenInfo screen_info; | 538 blink::WebScreenInfo screen_info; |
545 content::RenderWidgetHostView* host_view = | 539 content::RenderWidgetHostView* host_view = |
546 web_contents.GetRenderWidgetHostView(); | 540 web_contents.GetRenderWidgetHostView(); |
547 if (host_view) | 541 if (host_view) |
548 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); | 542 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); |
549 | 543 |
550 internal::GetFingerprintInternal( | 544 internal::GetFingerprintInternal( |
551 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, | 545 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, |
552 charset, accept_languages, install_time, app_locale, user_agent, | 546 charset, accept_languages, install_time, app_locale, |
553 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); | 547 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); |
554 } | 548 } |
555 | 549 |
556 } // namespace risk | 550 } // namespace risk |
557 } // namespace autofill | 551 } // namespace autofill |
OLD | NEW |