Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: components/autofill/content/browser/risk/fingerprint.cc

Issue 2192683003: Revert of Reland: Geolocation: move from content/browser to device/ (patchset #2 id:20001 of https:… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2810
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 #include "base/scoped_observer.h" 23 #include "base/scoped_observer.h"
24 #include "base/strings/string_split.h" 24 #include "base/strings/string_split.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/sys_info.h" 26 #include "base/sys_info.h"
27 #include "base/time/time.h" 27 #include "base/time/time.h"
28 #include "base/timer/timer.h" 28 #include "base/timer/timer.h"
29 #include "base/values.h" 29 #include "base/values.h"
30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h" 30 #include "components/autofill/content/browser/risk/proto/fingerprint.pb.h"
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/browser/font_list_async.h" 32 #include "content/public/browser/font_list_async.h"
33 #include "content/public/browser/geolocation_provider.h"
33 #include "content/public/browser/gpu_data_manager.h" 34 #include "content/public/browser/gpu_data_manager.h"
34 #include "content/public/browser/gpu_data_manager_observer.h" 35 #include "content/public/browser/gpu_data_manager_observer.h"
35 #include "content/public/browser/plugin_service.h" 36 #include "content/public/browser/plugin_service.h"
36 #include "content/public/browser/render_widget_host.h" 37 #include "content/public/browser/render_widget_host.h"
37 #include "content/public/browser/render_widget_host_view.h" 38 #include "content/public/browser/render_widget_host_view.h"
38 #include "content/public/browser/web_contents.h" 39 #include "content/public/browser/web_contents.h"
40 #include "content/public/common/geoposition.h"
39 #include "content/public/common/webplugininfo.h" 41 #include "content/public/common/webplugininfo.h"
40 #include "device/geolocation/geolocation_provider.h"
41 #include "device/geolocation/geoposition.h"
42 #include "gpu/config/gpu_info.h" 42 #include "gpu/config/gpu_info.h"
43 #include "third_party/WebKit/public/platform/WebRect.h" 43 #include "third_party/WebKit/public/platform/WebRect.h"
44 #include "third_party/WebKit/public/platform/WebScreenInfo.h" 44 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
45 #include "ui/display/display.h" 45 #include "ui/display/display.h"
46 #include "ui/display/screen.h" 46 #include "ui/display/screen.h"
47 #include "ui/gfx/geometry/rect.h" 47 #include "ui/gfx/geometry/rect.h"
48 48
49 using blink::WebScreenInfo; 49 using blink::WebScreenInfo;
50 50
51 namespace autofill { 51 namespace autofill {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 193
194 private: 194 private:
195 ~FingerprintDataLoader() override {} 195 ~FingerprintDataLoader() override {}
196 196
197 // content::GpuDataManagerObserver: 197 // content::GpuDataManagerObserver:
198 void OnGpuInfoUpdate() override; 198 void OnGpuInfoUpdate() override;
199 199
200 // Callbacks for asynchronously loaded data. 200 // Callbacks for asynchronously loaded data.
201 void OnGotFonts(std::unique_ptr<base::ListValue> fonts); 201 void OnGotFonts(std::unique_ptr<base::ListValue> fonts);
202 void OnGotPlugins(const std::vector<content::WebPluginInfo>& plugins); 202 void OnGotPlugins(const std::vector<content::WebPluginInfo>& plugins);
203 void OnGotGeoposition(const device::Geoposition& geoposition); 203 void OnGotGeoposition(const content::Geoposition& geoposition);
204 204
205 // If all of the asynchronous data has been loaded, calls |callback_| with 205 // If all of the asynchronous data has been loaded, calls |callback_| with
206 // the fingerprint data. 206 // the fingerprint data.
207 void MaybeFillFingerprint(); 207 void MaybeFillFingerprint();
208 208
209 // Calls |callback_| with the fingerprint data. 209 // Calls |callback_| with the fingerprint data.
210 void FillFingerprint(); 210 void FillFingerprint();
211 211
212 // The GPU data provider. 212 // The GPU data provider.
213 // Weak reference because the GpuDataManager class is a singleton. 213 // Weak reference because the GpuDataManager class is a singleton.
(...skipping 13 matching lines...) Expand all
227 const std::string charset_; 227 const std::string charset_;
228 const std::string accept_languages_; 228 const std::string accept_languages_;
229 const std::string app_locale_; 229 const std::string app_locale_;
230 const std::string user_agent_; 230 const std::string user_agent_;
231 const base::Time install_time_; 231 const base::Time install_time_;
232 232
233 // Data that will be loaded asynchronously. 233 // Data that will be loaded asynchronously.
234 std::unique_ptr<base::ListValue> fonts_; 234 std::unique_ptr<base::ListValue> fonts_;
235 std::vector<content::WebPluginInfo> plugins_; 235 std::vector<content::WebPluginInfo> plugins_;
236 bool waiting_on_plugins_; 236 bool waiting_on_plugins_;
237 device::Geoposition geoposition_; 237 content::Geoposition geoposition_;
238 238
239 // Timer to enforce a maximum timeout before the |callback_| is called, even 239 // Timer to enforce a maximum timeout before the |callback_| is called, even
240 // if not all asynchronous data has been loaded. 240 // if not all asynchronous data has been loaded.
241 base::OneShotTimer timeout_timer_; 241 base::OneShotTimer timeout_timer_;
242 242
243 // The callback that will be called once all the data is available. 243 // The callback that will be called once all the data is available.
244 base::Callback<void(std::unique_ptr<Fingerprint>)> callback_; 244 base::Callback<void(std::unique_ptr<Fingerprint>)> callback_;
245 245
246 // The callback used as an "observer" of the GeolocationProvider. 246 // The callback used as an "observer" of the GeolocationProvider.
247 std::unique_ptr<device::GeolocationProvider::Subscription> 247 std::unique_ptr<content::GeolocationProvider::Subscription>
248 geolocation_subscription_; 248 geolocation_subscription_;
249 249
250 // For invalidating asynchronous callbacks that might arrive after |this| 250 // For invalidating asynchronous callbacks that might arrive after |this|
251 // instance is destroyed. 251 // instance is destroyed.
252 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_; 252 base::WeakPtrFactory<FingerprintDataLoader> weak_ptr_factory_;
253 253
254 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); 254 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader);
255 }; 255 };
256 256
257 FingerprintDataLoader::FingerprintDataLoader( 257 FingerprintDataLoader::FingerprintDataLoader(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 #else 303 #else
304 waiting_on_plugins_ = false; 304 waiting_on_plugins_ = false;
305 #endif 305 #endif
306 306
307 // Load font data. 307 // Load font data.
308 content::GetFontListAsync( 308 content::GetFontListAsync(
309 base::Bind(&FingerprintDataLoader::OnGotFonts, 309 base::Bind(&FingerprintDataLoader::OnGotFonts,
310 weak_ptr_factory_.GetWeakPtr())); 310 weak_ptr_factory_.GetWeakPtr()));
311 311
312 // Load geolocation data. 312 // Load geolocation data.
313 geolocation_subscription_ = device::GeolocationProvider::GetInstance()-> 313 geolocation_subscription_ = content::GeolocationProvider::GetInstance()->
314 AddLocationUpdateCallback( 314 AddLocationUpdateCallback(
315 base::Bind(&FingerprintDataLoader::OnGotGeoposition, 315 base::Bind(&FingerprintDataLoader::OnGotGeoposition,
316 weak_ptr_factory_.GetWeakPtr()), 316 weak_ptr_factory_.GetWeakPtr()),
317 false); 317 false);
318 } 318 }
319 319
320 void FingerprintDataLoader::OnGpuInfoUpdate() { 320 void FingerprintDataLoader::OnGpuInfoUpdate() {
321 if (!gpu_data_manager_->IsEssentialGpuInfoAvailable()) 321 if (!gpu_data_manager_->IsEssentialGpuInfoAvailable())
322 return; 322 return;
323 323
324 gpu_observer_.Remove(gpu_data_manager_); 324 gpu_observer_.Remove(gpu_data_manager_);
325 MaybeFillFingerprint(); 325 MaybeFillFingerprint();
326 } 326 }
327 327
328 void FingerprintDataLoader::OnGotFonts(std::unique_ptr<base::ListValue> fonts) { 328 void FingerprintDataLoader::OnGotFonts(std::unique_ptr<base::ListValue> fonts) {
329 DCHECK(!fonts_); 329 DCHECK(!fonts_);
330 fonts_.reset(fonts.release()); 330 fonts_.reset(fonts.release());
331 MaybeFillFingerprint(); 331 MaybeFillFingerprint();
332 } 332 }
333 333
334 void FingerprintDataLoader::OnGotPlugins( 334 void FingerprintDataLoader::OnGotPlugins(
335 const std::vector<content::WebPluginInfo>& plugins) { 335 const std::vector<content::WebPluginInfo>& plugins) {
336 DCHECK(waiting_on_plugins_); 336 DCHECK(waiting_on_plugins_);
337 waiting_on_plugins_ = false; 337 waiting_on_plugins_ = false;
338 plugins_ = plugins; 338 plugins_ = plugins;
339 MaybeFillFingerprint(); 339 MaybeFillFingerprint();
340 } 340 }
341 341
342 void FingerprintDataLoader::OnGotGeoposition( 342 void FingerprintDataLoader::OnGotGeoposition(
343 const device::Geoposition& geoposition) { 343 const content::Geoposition& geoposition) {
344 DCHECK(!geoposition_.Validate()); 344 DCHECK(!geoposition_.Validate());
345 345
346 geoposition_ = geoposition; 346 geoposition_ = geoposition;
347 DCHECK(geoposition_.Validate() || 347 DCHECK(geoposition_.Validate() ||
348 geoposition_.error_code != device::Geoposition::ERROR_CODE_NONE); 348 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE);
349 geolocation_subscription_.reset(); 349 geolocation_subscription_.reset();
350 350
351 MaybeFillFingerprint(); 351 MaybeFillFingerprint();
352 } 352 }
353 353
354 void FingerprintDataLoader::MaybeFillFingerprint() { 354 void FingerprintDataLoader::MaybeFillFingerprint() {
355 // If all of the data has been loaded, or if the |timeout_timer_| has expired, 355 // If all of the data has been loaded, or if the |timeout_timer_| has expired,
356 // fill the fingerprint and clean up. 356 // fill the fingerprint and clean up.
357 if (!timeout_timer_.IsRunning() || 357 if (!timeout_timer_.IsRunning() ||
358 ((!gpu_data_manager_->GpuAccessAllowed(NULL) || 358 ((!gpu_data_manager_->GpuAccessAllowed(NULL) ||
359 gpu_data_manager_->IsEssentialGpuInfoAvailable()) && 359 gpu_data_manager_->IsEssentialGpuInfoAvailable()) &&
360 fonts_ && 360 fonts_ &&
361 !waiting_on_plugins_ && 361 !waiting_on_plugins_ &&
362 (geoposition_.Validate() || 362 (geoposition_.Validate() ||
363 geoposition_.error_code != device::Geoposition::ERROR_CODE_NONE))) { 363 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE))) {
364 FillFingerprint(); 364 FillFingerprint();
365 delete this; 365 delete this;
366 } 366 }
367 } 367 }
368 368
369 void FingerprintDataLoader::FillFingerprint() { 369 void FingerprintDataLoader::FillFingerprint() {
370 std::unique_ptr<Fingerprint> fingerprint(new Fingerprint); 370 std::unique_ptr<Fingerprint> fingerprint(new Fingerprint);
371 Fingerprint::MachineCharacteristics* machine = 371 Fingerprint::MachineCharacteristics* machine =
372 fingerprint->mutable_machine_characteristics(); 372 fingerprint->mutable_machine_characteristics();
373 373
(...skipping 29 matching lines...) Expand all
403 Fingerprint::Dimension* outer_window_size = 403 Fingerprint::Dimension* outer_window_size =
404 transient_state->mutable_outer_window_size(); 404 transient_state->mutable_outer_window_size();
405 outer_window_size->set_width(window_bounds_.width()); 405 outer_window_size->set_width(window_bounds_.width());
406 outer_window_size->set_height(window_bounds_.height()); 406 outer_window_size->set_height(window_bounds_.height());
407 407
408 // TODO(isherman): Record network performance data, which is theoretically 408 // TODO(isherman): Record network performance data, which is theoretically
409 // available to JS. 409 // available to JS.
410 410
411 // TODO(isherman): Record more user behavior data. 411 // TODO(isherman): Record more user behavior data.
412 if (geoposition_.Validate() && 412 if (geoposition_.Validate() &&
413 geoposition_.error_code == device::Geoposition::ERROR_CODE_NONE) { 413 geoposition_.error_code == content::Geoposition::ERROR_CODE_NONE) {
414 Fingerprint::UserCharacteristics::Location* location = 414 Fingerprint::UserCharacteristics::Location* location =
415 fingerprint->mutable_user_characteristics()->mutable_location(); 415 fingerprint->mutable_user_characteristics()->mutable_location();
416 location->set_altitude(geoposition_.altitude); 416 location->set_altitude(geoposition_.altitude);
417 location->set_latitude(geoposition_.latitude); 417 location->set_latitude(geoposition_.latitude);
418 location->set_longitude(geoposition_.longitude); 418 location->set_longitude(geoposition_.longitude);
419 location->set_accuracy(geoposition_.accuracy); 419 location->set_accuracy(geoposition_.accuracy);
420 location->set_time_in_ms( 420 location->set_time_in_ms(
421 (geoposition_.timestamp - base::Time::UnixEpoch()).InMilliseconds()); 421 (geoposition_.timestamp - base::Time::UnixEpoch()).InMilliseconds());
422 } 422 }
423 423
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info); 477 host_view->GetRenderWidgetHost()->GetWebScreenInfo(&screen_info);
478 478
479 internal::GetFingerprintInternal( 479 internal::GetFingerprintInternal(
480 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version, 480 obfuscated_gaia_id, window_bounds, content_bounds, screen_info, version,
481 charset, accept_languages, install_time, app_locale, user_agent, 481 charset, accept_languages, install_time, app_locale, user_agent,
482 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback); 482 base::TimeDelta::FromSeconds(kTimeoutSeconds), callback);
483 } 483 }
484 484
485 } // namespace risk 485 } // namespace risk
486 } // namespace autofill 486 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/browser/DEPS ('k') | components/autofill/content/browser/risk/fingerprint_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698