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

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

Issue 14619006: [Autofill] Add geolocation data to Risk fingerprint. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Don't use high accuracy for now Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "components/autofill/browser/risk/proto/fingerprint.pb.h" 16 #include "components/autofill/browser/risk/proto/fingerprint.pb.h"
17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/browser/font_list_async.h" 18 #include "content/public/browser/font_list_async.h"
19 #include "content/public/browser/geolocation_provider.h"
18 #include "content/public/browser/gpu_data_manager.h" 20 #include "content/public/browser/gpu_data_manager.h"
19 #include "content/public/browser/gpu_data_manager_observer.h" 21 #include "content/public/browser/gpu_data_manager_observer.h"
20 #include "content/public/browser/plugin_service.h" 22 #include "content/public/browser/plugin_service.h"
21 #include "content/public/browser/render_widget_host.h" 23 #include "content/public/browser/render_widget_host.h"
22 #include "content/public/browser/render_widget_host_view.h" 24 #include "content/public/browser/render_widget_host_view.h"
23 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
24 #include "content/public/browser/web_contents_view.h" 26 #include "content/public/browser/web_contents_view.h"
25 #include "content/public/common/content_client.h" 27 #include "content/public/common/content_client.h"
28 #include "content/public/common/geoposition.h"
26 #include "content/public/common/gpu_info.h" 29 #include "content/public/common/gpu_info.h"
27 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h" 30 #include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
28 #include "third_party/WebKit/Source/Platform/chromium/public/WebScreenInfo.h" 31 #include "third_party/WebKit/Source/Platform/chromium/public/WebScreenInfo.h"
29 #include "ui/gfx/rect.h" 32 #include "ui/gfx/rect.h"
30 #include "ui/gfx/screen.h" 33 #include "ui/gfx/screen.h"
31 #include "webkit/plugins/webplugininfo.h" 34 #include "webkit/plugins/webplugininfo.h"
32 35
33 using WebKit::WebScreenInfo; 36 using WebKit::WebScreenInfo;
34 37
35 namespace autofill { 38 namespace autofill {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 196
194 private: 197 private:
195 virtual ~FingerprintDataLoader(); 198 virtual ~FingerprintDataLoader();
196 199
197 // content::GpuDataManagerObserver: 200 // content::GpuDataManagerObserver:
198 virtual void OnGpuInfoUpdate() OVERRIDE; 201 virtual void OnGpuInfoUpdate() OVERRIDE;
199 202
200 // Callbacks for asynchronously loaded data. 203 // Callbacks for asynchronously loaded data.
201 void OnGotFonts(scoped_ptr<base::ListValue> fonts); 204 void OnGotFonts(scoped_ptr<base::ListValue> fonts);
202 void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins); 205 void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins);
206 void OnGotGeoposition(const content::Geoposition& geoposition);
207
208 // Methods that run on the IO thread to communicate with the
209 // GeolocationProvider.
210 void LoadGeoposition();
211 void OnGotGeopositionOnIOThread(const content::Geoposition& geoposition);
203 212
204 // If all of the asynchronous data has been loaded, calls |callback_| with 213 // If all of the asynchronous data has been loaded, calls |callback_| with
205 // the fingerprint data. 214 // the fingerprint data.
206 void MaybeFillFingerprint(); 215 void MaybeFillFingerprint();
207 216
208 // Calls |callback_| with the fingerprint data. 217 // Calls |callback_| with the fingerprint data.
209 void FillFingerprint(); 218 void FillFingerprint();
210 219
211 // The GPU data provider. 220 // The GPU data provider.
212 content::GpuDataManager* const gpu_data_manager_; 221 content::GpuDataManager* const gpu_data_manager_;
213 222
223 // The callback used as an "observer" of the GeolocationProvider. Accessed
224 // only on the IO thread.
225 content::GeolocationProvider::LocationUpdateCallback geolocation_callback_;
226
214 // Data that will be passed on to the next loading phase. 227 // Data that will be passed on to the next loading phase.
215 const int64 gaia_id_; 228 const int64 gaia_id_;
216 const gfx::Rect window_bounds_; 229 const gfx::Rect window_bounds_;
217 const gfx::Rect content_bounds_; 230 const gfx::Rect content_bounds_;
218 const WebScreenInfo screen_info_; 231 const WebScreenInfo screen_info_;
219 const std::string version_; 232 const std::string version_;
220 const std::string charset_; 233 const std::string charset_;
221 const std::string accept_languages_; 234 const std::string accept_languages_;
222 const base::Time install_time_; 235 const base::Time install_time_;
223 DialogType dialog_type_; 236 DialogType dialog_type_;
224 237
225 // Data that will be loaded asynchronously. 238 // Data that will be loaded asynchronously.
226 scoped_ptr<base::ListValue> fonts_; 239 scoped_ptr<base::ListValue> fonts_;
227 std::vector<webkit::WebPluginInfo> plugins_; 240 std::vector<webkit::WebPluginInfo> plugins_;
228 bool has_loaded_plugins_; 241 bool has_loaded_plugins_;
242 content::Geoposition geoposition_;
229 243
230 // The current application locale. 244 // The current application locale.
231 std::string app_locale_; 245 std::string app_locale_;
232 246
233 // 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.
234 base::Callback<void(scoped_ptr<Fingerprint>)> callback_; 248 base::Callback<void(scoped_ptr<Fingerprint>)> callback_;
235 249
236 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader); 250 DISALLOW_COPY_AND_ASSIGN(FingerprintDataLoader);
237 }; 251 };
238 252
(...skipping 29 matching lines...) Expand all
268 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded(); 282 gpu_data_manager_->RequestCompleteGpuInfoIfNeeded();
269 } 283 }
270 284
271 // Load plugin data. 285 // Load plugin data.
272 content::PluginService::GetInstance()->GetPlugins( 286 content::PluginService::GetInstance()->GetPlugins(
273 base::Bind(&FingerprintDataLoader::OnGotPlugins, base::Unretained(this))); 287 base::Bind(&FingerprintDataLoader::OnGotPlugins, base::Unretained(this)));
274 288
275 // Load font data. 289 // Load font data.
276 content::GetFontListAsync( 290 content::GetFontListAsync(
277 base::Bind(&FingerprintDataLoader::OnGotFonts, base::Unretained(this))); 291 base::Bind(&FingerprintDataLoader::OnGotFonts, base::Unretained(this)));
292
293 // Load geolocation data.
294 content::BrowserThread::PostTask(
295 content::BrowserThread::IO, FROM_HERE,
296 base::Bind(&FingerprintDataLoader::LoadGeoposition,
297 base::Unretained(this)));
278 } 298 }
279 299
280 FingerprintDataLoader::~FingerprintDataLoader() { 300 FingerprintDataLoader::~FingerprintDataLoader() {
281 } 301 }
282 302
283 void FingerprintDataLoader::OnGpuInfoUpdate() { 303 void FingerprintDataLoader::OnGpuInfoUpdate() {
284 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable()) 304 if (!gpu_data_manager_->IsCompleteGpuInfoAvailable())
285 return; 305 return;
286 306
287 gpu_data_manager_->RemoveObserver(this); 307 gpu_data_manager_->RemoveObserver(this);
288 MaybeFillFingerprint(); 308 MaybeFillFingerprint();
289 } 309 }
290 310
291 void FingerprintDataLoader::OnGotFonts(scoped_ptr<base::ListValue> fonts) { 311 void FingerprintDataLoader::OnGotFonts(scoped_ptr<base::ListValue> fonts) {
292 DCHECK(!fonts_); 312 DCHECK(!fonts_);
293 fonts_.reset(fonts.release()); 313 fonts_.reset(fonts.release());
294 MaybeFillFingerprint(); 314 MaybeFillFingerprint();
295 } 315 }
296 316
297 void FingerprintDataLoader::OnGotPlugins( 317 void FingerprintDataLoader::OnGotPlugins(
298 const std::vector<webkit::WebPluginInfo>& plugins) { 318 const std::vector<webkit::WebPluginInfo>& plugins) {
299 DCHECK(!has_loaded_plugins_); 319 DCHECK(!has_loaded_plugins_);
300 has_loaded_plugins_ = true; 320 has_loaded_plugins_ = true;
301 plugins_ = plugins; 321 plugins_ = plugins;
302 MaybeFillFingerprint(); 322 MaybeFillFingerprint();
303 } 323 }
304 324
325 void FingerprintDataLoader::OnGotGeoposition(
326 const content::Geoposition& geoposition) {
327 DCHECK(!geoposition_.Validate());
328
329 geoposition_ = geoposition;
330 DCHECK(geoposition_.Validate() ||
331 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE);
332
333 MaybeFillFingerprint();
334 }
335
336 void FingerprintDataLoader::LoadGeoposition() {
337 geolocation_callback_ =
338 base::Bind(&FingerprintDataLoader::OnGotGeopositionOnIOThread,
339 base::Unretained(this));
340 content::GeolocationProvider::GetInstance()->AddLocationUpdateCallback(
341 geolocation_callback_, false);
342 }
343
344 void FingerprintDataLoader::OnGotGeopositionOnIOThread(
345 const content::Geoposition& geoposition) {
346 content::BrowserThread::PostTask(
347 content::BrowserThread::UI, FROM_HERE,
348 base::Bind(&FingerprintDataLoader::OnGotGeoposition,
349 base::Unretained(this), geoposition));
350
351 // Unregister as an observer, since this class instance might be destroyed
352 // after this callback. Note: It's important to unregister *after* posting
353 // the task above. Unregistering as an observer can have the side-effect of
354 // modifying the value of |geoposition|.
355 bool removed =
356 content::GeolocationProvider::GetInstance()->RemoveLocationUpdateCallback(
357 geolocation_callback_);
358 DCHECK(removed);
359 }
360
305 void FingerprintDataLoader::MaybeFillFingerprint() { 361 void FingerprintDataLoader::MaybeFillFingerprint() {
306 // If all of the data has been loaded, fill the fingerprint and clean up. 362 // If all of the data has been loaded, fill the fingerprint and clean up.
307 if (gpu_data_manager_->IsCompleteGpuInfoAvailable() && 363 if (gpu_data_manager_->IsCompleteGpuInfoAvailable() &&
308 fonts_ && 364 fonts_ &&
309 has_loaded_plugins_) { 365 has_loaded_plugins_ &&
366 (geoposition_.Validate() ||
367 geoposition_.error_code != content::Geoposition::ERROR_CODE_NONE)) {
310 FillFingerprint(); 368 FillFingerprint();
311 delete this; 369 delete this;
312 } 370 }
313 } 371 }
314 372
315 void FingerprintDataLoader::FillFingerprint() { 373 void FingerprintDataLoader::FillFingerprint() {
316 scoped_ptr<Fingerprint> fingerprint(new Fingerprint); 374 scoped_ptr<Fingerprint> fingerprint(new Fingerprint);
317 Fingerprint_MachineCharacteristics* machine = 375 Fingerprint_MachineCharacteristics* machine =
318 fingerprint->mutable_machine_characteristics(); 376 fingerprint->mutable_machine_characteristics();
319 377
(...skipping 25 matching lines...) Expand all
345 inner_window_size->set_width(content_bounds_.width()); 403 inner_window_size->set_width(content_bounds_.width());
346 inner_window_size->set_height(content_bounds_.height()); 404 inner_window_size->set_height(content_bounds_.height());
347 Fingerprint_Dimension* outer_window_size = 405 Fingerprint_Dimension* outer_window_size =
348 transient_state->mutable_outer_window_size(); 406 transient_state->mutable_outer_window_size();
349 outer_window_size->set_width(window_bounds_.width()); 407 outer_window_size->set_width(window_bounds_.width());
350 outer_window_size->set_height(window_bounds_.height()); 408 outer_window_size->set_height(window_bounds_.height());
351 409
352 // TODO(isherman): Record network performance data, which is theoretically 410 // TODO(isherman): Record network performance data, which is theoretically
353 // available to JS. 411 // available to JS.
354 412
355 // TODO(isherman): Record user behavior data. 413 // TODO(isherman): Record more user behavior data.
414 if (geoposition_.error_code == content::Geoposition::ERROR_CODE_NONE) {
415 Fingerprint_UserCharacteristics_Location* location =
416 fingerprint->mutable_user_characteristics()->mutable_location();
417 location->set_altitude(geoposition_.altitude);
418 location->set_latitude(geoposition_.latitude);
419 location->set_longitude(geoposition_.longitude);
420 location->set_accuracy(geoposition_.accuracy);
421 location->set_time_in_ms(
422 (geoposition_.timestamp - base::Time::UnixEpoch()).InMilliseconds());
423 }
356 424
357 Fingerprint_Metadata* metadata = fingerprint->mutable_metadata(); 425 Fingerprint_Metadata* metadata = fingerprint->mutable_metadata();
358 metadata->set_timestamp_ms( 426 metadata->set_timestamp_ms(
359 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); 427 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds());
360 metadata->set_gaia_id(gaia_id_); 428 metadata->set_gaia_id(gaia_id_);
361 metadata->set_fingerprinter_version(kFingerprinterVersion); 429 metadata->set_fingerprinter_version(kFingerprinterVersion);
362 430
363 callback_.Run(fingerprint.Pass()); 431 callback_.Run(fingerprint.Pass());
364 } 432 }
365 433
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 // This class is responsible for freeing its own memory. 476 // This class is responsible for freeing its own memory.
409 new FingerprintDataLoader(gaia_id, window_bounds, content_bounds, screen_info, 477 new FingerprintDataLoader(gaia_id, window_bounds, content_bounds, screen_info,
410 version, charset, accept_languages, install_time, 478 version, charset, accept_languages, install_time,
411 dialog_type, app_locale, callback); 479 dialog_type, app_locale, callback);
412 } 480 }
413 481
414 } // namespace internal 482 } // namespace internal
415 483
416 } // namespace risk 484 } // namespace risk
417 } // namespace autofill 485 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/risk/fingerprint_browsertest.cc ('k') | components/autofill/browser/risk/proto/fingerprint.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698