| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 const gfx::Rect& window_bounds, | 177 const gfx::Rect& window_bounds, |
| 178 const gfx::Rect& content_bounds, | 178 const gfx::Rect& content_bounds, |
| 179 const WebScreenInfo& screen_info, | 179 const WebScreenInfo& screen_info, |
| 180 const std::string& version, | 180 const std::string& version, |
| 181 const std::string& charset, | 181 const std::string& charset, |
| 182 const std::string& accept_languages, | 182 const std::string& accept_languages, |
| 183 const base::Time& install_time, | 183 const base::Time& install_time, |
| 184 const std::string& app_locale, | 184 const std::string& app_locale, |
| 185 const std::string& user_agent, | 185 const std::string& user_agent, |
| 186 const base::TimeDelta& timeout, | 186 const base::TimeDelta& timeout, |
| 187 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback); | 187 const base::Callback<void(std::unique_ptr<Fingerprint>)>& callback); |
| 188 | 188 |
| 189 private: | 189 private: |
| 190 ~FingerprintDataLoader() override {} | 190 ~FingerprintDataLoader() override {} |
| 191 | 191 |
| 192 // content::GpuDataManagerObserver: | 192 // content::GpuDataManagerObserver: |
| 193 void OnGpuInfoUpdate() override; | 193 void OnGpuInfoUpdate() override; |
| 194 | 194 |
| 195 // Callbacks for asynchronously loaded data. | 195 // Callbacks for asynchronously loaded data. |
| 196 void OnGotFonts(scoped_ptr<base::ListValue> fonts); | 196 void OnGotFonts(std::unique_ptr<base::ListValue> fonts); |
| 197 void OnGotPlugins(const std::vector<content::WebPluginInfo>& plugins); | 197 void OnGotPlugins(const std::vector<content::WebPluginInfo>& plugins); |
| 198 void OnGotGeoposition(const content::Geoposition& geoposition); | 198 void OnGotGeoposition(const content::Geoposition& geoposition); |
| 199 | 199 |
| 200 // If all of the asynchronous data has been loaded, calls |callback_| with | 200 // If all of the asynchronous data has been loaded, calls |callback_| with |
| 201 // the fingerprint data. | 201 // the fingerprint data. |
| 202 void MaybeFillFingerprint(); | 202 void MaybeFillFingerprint(); |
| 203 | 203 |
| 204 // Calls |callback_| with the fingerprint data. | 204 // Calls |callback_| with the fingerprint data. |
| 205 void FillFingerprint(); | 205 void FillFingerprint(); |
| 206 | 206 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 219 const gfx::Rect content_bounds_; | 219 const gfx::Rect content_bounds_; |
| 220 const WebScreenInfo screen_info_; | 220 const WebScreenInfo screen_info_; |
| 221 const std::string version_; | 221 const std::string version_; |
| 222 const std::string charset_; | 222 const std::string charset_; |
| 223 const std::string accept_languages_; | 223 const std::string accept_languages_; |
| 224 const std::string app_locale_; | 224 const std::string app_locale_; |
| 225 const std::string user_agent_; | 225 const std::string user_agent_; |
| 226 const base::Time install_time_; | 226 const base::Time install_time_; |
| 227 | 227 |
| 228 // Data that will be loaded asynchronously. | 228 // Data that will be loaded asynchronously. |
| 229 scoped_ptr<base::ListValue> fonts_; | 229 std::unique_ptr<base::ListValue> fonts_; |
| 230 std::vector<content::WebPluginInfo> plugins_; | 230 std::vector<content::WebPluginInfo> plugins_; |
| 231 bool waiting_on_plugins_; | 231 bool waiting_on_plugins_; |
| 232 content::Geoposition geoposition_; | 232 content::Geoposition geoposition_; |
| 233 | 233 |
| 234 // Timer to enforce a maximum timeout before the |callback_| is called, even | 234 // Timer to enforce a maximum timeout before the |callback_| is called, even |
| 235 // if not all asynchronous data has been loaded. | 235 // if not all asynchronous data has been loaded. |
| 236 base::OneShotTimer timeout_timer_; | 236 base::OneShotTimer timeout_timer_; |
| 237 | 237 |
| 238 // The callback that will be called once all the data is available. | 238 // The callback that will be called once all the data is available. |
| 239 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; | 239 base::Callback<void(std::unique_ptr<Fingerprint>)> callback_; |
| 240 | 240 |
| 241 // The callback used as an "observer" of the GeolocationProvider. | 241 // The callback used as an "observer" of the GeolocationProvider. |
| 242 scoped_ptr<content::GeolocationProvider::Subscription> | 242 std::unique_ptr<content::GeolocationProvider::Subscription> |
| 243 geolocation_subscription_; | 243 geolocation_subscription_; |
| 244 | 244 |
| 245 // For invalidating asynchronous callbacks that might arrive after |this| | 245 // For invalidating asynchronous callbacks that might arrive after |this| |
| 246 // instance is destroyed. | 246 // instance is destroyed. |
| 247 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; | 247 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; |
| 248 | 248 |
| 249 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); | 249 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); |
| 250 }; | 250 }; |
| 251 | 251 |
| 252 FingerprintDataLoader::FingerprintDataLoader( | 252 FingerprintDataLoader::FingerprintDataLoader( |
| 253 uint64_t obfuscated_gaia_id, | 253 uint64_t obfuscated_gaia_id, |
| 254 const gfx::Rect& window_bounds, | 254 const gfx::Rect& window_bounds, |
| 255 const gfx::Rect& content_bounds, | 255 const gfx::Rect& content_bounds, |
| 256 const WebScreenInfo& screen_info, | 256 const WebScreenInfo& screen_info, |
| 257 const std::string& version, | 257 const std::string& version, |
| 258 const std::string& charset, | 258 const std::string& charset, |
| 259 const std::string& accept_languages, | 259 const std::string& accept_languages, |
| 260 const base::Time& install_time, | 260 const base::Time& install_time, |
| 261 const std::string& app_locale, | 261 const std::string& app_locale, |
| 262 const std::string& user_agent, | 262 const std::string& user_agent, |
| 263 const base::TimeDelta& timeout, | 263 const base::TimeDelta& timeout, |
| 264 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) | 264 const base::Callback<void(std::unique_ptr<Fingerprint>)>& callback) |
| 265 : gpu_data_manager_(content::GpuDataManager::GetInstance()), | 265 : gpu_data_manager_(content::GpuDataManager::GetInstance()), |
| 266 gpu_observer_(this), | 266 gpu_observer_(this), |
| 267 obfuscated_gaia_id_(obfuscated_gaia_id), | 267 obfuscated_gaia_id_(obfuscated_gaia_id), |
| 268 window_bounds_(window_bounds), | 268 window_bounds_(window_bounds), |
| 269 content_bounds_(content_bounds), | 269 content_bounds_(content_bounds), |
| 270 screen_info_(screen_info), | 270 screen_info_(screen_info), |
| 271 version_(version), | 271 version_(version), |
| 272 charset_(charset), | 272 charset_(charset), |
| 273 accept_languages_(accept_languages), | 273 accept_languages_(accept_languages), |
| 274 app_locale_(app_locale), | 274 app_locale_(app_locale), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 | 314 |
| 315 void FingerprintDataLoader::OnGpuInfoUpdate() { | 315 void FingerprintDataLoader::OnGpuInfoUpdate() { |
| 316 if (!gpu_data_manager_->IsEssentialGpuInfoAvailable()) | 316 if (!gpu_data_manager_->IsEssentialGpuInfoAvailable()) |
| 317 return; | 317 return; |
| 318 | 318 |
| 319 gpu_observer_.Remove(gpu_data_manager_); | 319 gpu_observer_.Remove(gpu_data_manager_); |
| 320 MaybeFillFingerprint(); | 320 MaybeFillFingerprint(); |
| 321 } | 321 } |
| 322 | 322 |
| 323 void FingerprintDataLoader::OnGotFonts(scoped_ptr<base::ListValue> fonts) { | 323 void FingerprintDataLoader::OnGotFonts(std::unique_ptr<base::ListValue> fonts) { |
| 324 DCHECK(!fonts_); | 324 DCHECK(!fonts_); |
| 325 fonts_.reset(fonts.release()); | 325 fonts_.reset(fonts.release()); |
| 326 MaybeFillFingerprint(); | 326 MaybeFillFingerprint(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 void FingerprintDataLoader::OnGotPlugins( | 329 void FingerprintDataLoader::OnGotPlugins( |
| 330 const std::vector<content::WebPluginInfo>& plugins) { | 330 const std::vector<content::WebPluginInfo>& plugins) { |
| 331 DCHECK(waiting_on_plugins_); | 331 DCHECK(waiting_on_plugins_); |
| 332 waiting_on_plugins_ = false; | 332 waiting_on_plugins_ = false; |
| 333 plugins_ = plugins; | 333 plugins_ = plugins; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 355 fonts_ && | 355 fonts_ && |
| 356 !waiting_on_plugins_ && | 356 !waiting_on_plugins_ && |
| 357 (geoposition_.Validate() || | 357 (geoposition_.Validate() || |
| 358 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE))) { | 358 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE))) { |
| 359 FillFingerprint(); | 359 FillFingerprint(); |
| 360 delete this; | 360 delete this; |
| 361 } | 361 } |
| 362 } | 362 } |
| 363 | 363 |
| 364 void FingerprintDataLoader::FillFingerprint() { | 364 void FingerprintDataLoader::FillFingerprint() { |
| 365 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); | 365 std::unique_ptr<Fingerprint> fingerprint(new Fingerprint); |
| 366 Fingerprint::MachineCharacteristics* machine = | 366 Fingerprint::MachineCharacteristics* machine = |
| 367 fingerprint->mutable_machine_characteristics(); | 367 fingerprint->mutable_machine_characteristics(); |
| 368 | 368 |
| 369 machine->set_operating_system_build(GetOperatingSystemVersion()); | 369 machine->set_operating_system_build(GetOperatingSystemVersion()); |
| 370 // We use the delta between the install time and the Unix epoch, in hours. | 370 // We use the delta between the install time and the Unix epoch, in hours. |
| 371 machine->set_browser_install_time_hours( | 371 machine->set_browser_install_time_hours( |
| 372 (install_time_ - base::Time::UnixEpoch()).InHours()); | 372 (install_time_ - base::Time::UnixEpoch()).InHours()); |
| 373 machine->set_utc_offset_ms(GetTimezoneOffset().InMilliseconds()); | 373 machine->set_utc_offset_ms(GetTimezoneOffset().InMilliseconds()); |
| 374 machine->set_browser_language(app_locale_); | 374 machine->set_browser_language(app_locale_); |
| 375 machine->set_charset(charset_); | 375 machine->set_charset(charset_); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 const gfx::Rect& window_bounds, | 434 const gfx::Rect& window_bounds, |
| 435 const gfx::Rect& content_bounds, | 435 const gfx::Rect& content_bounds, |
| 436 const blink::WebScreenInfo& screen_info, | 436 const blink::WebScreenInfo& screen_info, |
| 437 const std::string& version, | 437 const std::string& version, |
| 438 const std::string& charset, | 438 const std::string& charset, |
| 439 const std::string& accept_languages, | 439 const std::string& accept_languages, |
| 440 const base::Time& install_time, | 440 const base::Time& install_time, |
| 441 const std::string& app_locale, | 441 const std::string& app_locale, |
| 442 const std::string& user_agent, | 442 const std::string& user_agent, |
| 443 const base::TimeDelta& timeout, | 443 const base::TimeDelta& timeout, |
| 444 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 444 const base::Callback<void(std::unique_ptr<Fingerprint>)>& callback) { |
| 445 // Begin loading all of the data that we need to load asynchronously. | 445 // Begin loading all of the data that we need to load asynchronously. |
| 446 // This class is responsible for freeing its own memory. | 446 // This class is responsible for freeing its own memory. |
| 447 new FingerprintDataLoader(obfuscated_gaia_id, window_bounds, content_bounds, | 447 new FingerprintDataLoader(obfuscated_gaia_id, window_bounds, content_bounds, |
| 448 screen_info, version, charset, accept_languages, | 448 screen_info, version, charset, accept_languages, |
| 449 install_time, app_locale, user_agent, timeout, | 449 install_time, app_locale, user_agent, timeout, |
| 450 callback); | 450 callback); |
| 451 } | 451 } |
| 452 | 452 |
| 453 } // namespace internal | 453 } // namespace internal |
| 454 | 454 |
| 455 void GetFingerprint( | 455 void GetFingerprint( |
| 456 uint64_t obfuscated_gaia_id, | 456 uint64_t obfuscated_gaia_id, |
| 457 const gfx::Rect& window_bounds, | 457 const gfx::Rect& window_bounds, |
| 458 content::WebContents* web_contents, | 458 content::WebContents* web_contents, |
| 459 const std::string& version, | 459 const std::string& version, |
| 460 const std::string& charset, | 460 const std::string& charset, |
| 461 const std::string& accept_languages, | 461 const std::string& accept_languages, |
| 462 const base::Time& install_time, | 462 const base::Time& install_time, |
| 463 const std::string& app_locale, | 463 const std::string& app_locale, |
| 464 const std::string& user_agent, | 464 const std::string& user_agent, |
| 465 const base::Callback<void(scoped_ptr<Fingerprint>)>& callback) { | 465 const base::Callback<void(std::unique_ptr<Fingerprint>)>& callback) { |
| 466 gfx::Rect content_bounds = web_contents->GetContainerBounds(); | 466 gfx::Rect content_bounds = web_contents->GetContainerBounds(); |
| 467 | 467 |
| 468 blink::WebScreenInfo screen_info; | 468 blink::WebScreenInfo screen_info; |
| 469 const content::RenderWidgetHostView* host_view = | 469 const content::RenderWidgetHostView* host_view = |
| 470 web_contents->GetRenderWidgetHostView(); | 470 web_contents->GetRenderWidgetHostView(); |
| 471 if (host_view) | 471 if (host_view) |
| 472 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); | 472 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); |
| 473 | 473 |
| 474 internal::GetFingerprintInternal( | 474 internal::GetFingerprintInternal( |
| 475 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, | 475 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, |
| 476 charset, accept_languages, install_time, app_locale, user_agent, | 476 charset, accept_languages, install_time, app_locale, user_agent, |
| 477 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); | 477 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); |
| 478 } | 478 } |
| 479 | 479 |
| 480 } // namespace risk | 480 } // namespace risk |
| 481 } // namespace autofill | 481 } // namespace autofill |
| OLD | NEW |