OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager .h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 CleanUpIpAddresses(); | 187 CleanUpIpAddresses(); |
188 ScheduleNextCleanUpAfterInterval( | 188 ScheduleNextCleanUpAfterInterval( |
189 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); | 189 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); |
190 } | 190 } |
191 | 191 |
192 SafeBrowsingNavigationObserverManager::AttributionResult | 192 SafeBrowsingNavigationObserverManager::AttributionResult |
193 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainForDownload( | 193 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainForDownload( |
194 const GURL& target_url, | 194 const GURL& target_url, |
195 int target_tab_id, | 195 int target_tab_id, |
196 int user_gesture_count_limit, | 196 int user_gesture_count_limit, |
197 std::vector<ReferrerChainEntry>* out_referrer_chain) { | 197 ReferrerChain* out_referrer_chain) { |
198 if (!target_url.is_valid()) | 198 if (!target_url.is_valid()) |
199 return INVALID_URL; | 199 return INVALID_URL; |
200 | 200 |
201 NavigationEvent* nav_event = FindNavigationEvent( | 201 NavigationEvent* nav_event = FindNavigationEvent( |
202 target_url, | 202 target_url, |
203 GURL(), | 203 GURL(), |
204 target_tab_id); | 204 target_tab_id); |
205 if (!nav_event) { | 205 if (!nav_event) { |
206 // We cannot find a single navigation event related to this download. | 206 // We cannot find a single navigation event related to this download. |
207 return NAVIGATION_EVENT_NOT_FOUND; | 207 return NAVIGATION_EVENT_NOT_FOUND; |
(...skipping 10 matching lines...) Expand all Loading... | |
218 &result); | 218 &result); |
219 return result; | 219 return result; |
220 } | 220 } |
221 | 221 |
222 SafeBrowsingNavigationObserverManager::AttributionResult | 222 SafeBrowsingNavigationObserverManager::AttributionResult |
223 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainForPPAPIDownload( | 223 SafeBrowsingNavigationObserverManager::IdentifyReferrerChainForPPAPIDownload( |
224 const GURL& initiating_frame_url, | 224 const GURL& initiating_frame_url, |
225 int tab_id, | 225 int tab_id, |
226 bool has_user_gesture, | 226 bool has_user_gesture, |
227 int user_gesture_count_limit, | 227 int user_gesture_count_limit, |
228 std::vector<ReferrerChainEntry>* out_referrer_chain) { | 228 ReferrerChain* out_referrer_chain) { |
229 if (!initiating_frame_url.is_valid()) | 229 if (!initiating_frame_url.is_valid()) |
230 return INVALID_URL; | 230 return INVALID_URL; |
231 | 231 |
232 NavigationEvent* nav_event = | 232 NavigationEvent* nav_event = |
233 FindNavigationEvent(initiating_frame_url, GURL(), tab_id); | 233 FindNavigationEvent(initiating_frame_url, GURL(), tab_id); |
234 if (!nav_event) { | 234 if (!nav_event) { |
235 // We cannot find a single navigation event related to this download. | 235 // We cannot find a single navigation event related to this download. |
236 return NAVIGATION_EVENT_NOT_FOUND; | 236 return NAVIGATION_EVENT_NOT_FOUND; |
237 } | 237 } |
238 | 238 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 GURL search_url = | 390 GURL search_url = |
391 target_url.is_empty() ? target_main_frame_url : target_url; | 391 target_url.is_empty() ? target_main_frame_url : target_url; |
392 auto it = navigation_map_.find(search_url); | 392 auto it = navigation_map_.find(search_url); |
393 if (it == navigation_map_.end()) | 393 if (it == navigation_map_.end()) |
394 return nullptr; | 394 return nullptr; |
395 | 395 |
396 // Since navigation events are recorded in chronological order, we traverse | 396 // Since navigation events are recorded in chronological order, we traverse |
397 // the vector in reverse order to get the latest match. | 397 // the vector in reverse order to get the latest match. |
398 for (auto rit = it->second.rbegin(); rit != it->second.rend(); ++rit) { | 398 for (auto rit = it->second.rbegin(); rit != it->second.rend(); ++rit) { |
399 // If tab id is not valid, we only compare url, otherwise we compare both. | 399 // If tab id is not valid, we only compare url, otherwise we compare both. |
400 if (rit->destination_url == search_url) | |
Jialiu Lin
2017/01/09 23:23:04
not sure why this line slipped through last CL...
Nathan Parker
2017/01/10 01:25:13
Weird! At least it's a NOOP. :-)
| |
401 if (rit->destination_url == search_url && | 400 if (rit->destination_url == search_url && |
402 (target_tab_id == -1 || rit->target_tab_id == target_tab_id)) { | 401 (target_tab_id == -1 || rit->target_tab_id == target_tab_id)) { |
403 // If both source_url and source_main_frame_url are empty, and this | 402 // If both source_url and source_main_frame_url are empty, and this |
404 // navigation is not triggered by user, a retargeting navigation probably | 403 // navigation is not triggered by user, a retargeting navigation probably |
405 // causes this navigation. In this case, we skip this navigation event and | 404 // causes this navigation. In this case, we skip this navigation event and |
406 // looks for the retargeting navigation event. | 405 // looks for the retargeting navigation event. |
407 if (rit->source_url.is_empty() && rit->source_main_frame_url.is_empty() && | 406 if (rit->source_url.is_empty() && rit->source_main_frame_url.is_empty() && |
408 !rit->is_user_initiated) { | 407 !rit->is_user_initiated) { |
409 // If there is a server redirection immediately after retargeting, we | 408 // If there is a server redirection immediately after retargeting, we |
410 // need to adjust our search url to the original request. | 409 // need to adjust our search url to the original request. |
411 if (rit->has_server_redirect){ | 410 if (rit->has_server_redirect){ |
412 NavigationEvent* retargeting_nav_event = | 411 NavigationEvent* retargeting_nav_event = |
413 FindNavigationEvent(rit->original_request_url, | 412 FindNavigationEvent(rit->original_request_url, |
414 GURL(), | 413 GURL(), |
415 rit->target_tab_id); | 414 rit->target_tab_id); |
415 if (!retargeting_nav_event) | |
Nathan Parker
2017/01/10 01:25:13
Does this imply has_server_redirect was wrong?
Jialiu Lin
2017/01/10 02:15:12
Not necessarily. For some cases, previous Navigati
| |
416 return nullptr; | |
416 // Adjust retargeting navigation event's attributes. | 417 // Adjust retargeting navigation event's attributes. |
417 retargeting_nav_event->has_server_redirect = true; | 418 retargeting_nav_event->has_server_redirect = true; |
418 retargeting_nav_event->destination_url = search_url; | 419 retargeting_nav_event->destination_url = search_url; |
419 return retargeting_nav_event; | 420 return retargeting_nav_event; |
420 } else { | 421 } else { |
421 continue; | 422 continue; |
422 } | 423 } |
423 } else { | 424 } else { |
424 return &*rit; | 425 return &*rit; |
425 } | 426 } |
426 } | 427 } |
427 } | 428 } |
428 return nullptr; | 429 return nullptr; |
429 } | 430 } |
430 | 431 |
431 void SafeBrowsingNavigationObserverManager::AddToReferrerChain( | 432 void SafeBrowsingNavigationObserverManager::AddToReferrerChain( |
432 std::vector<ReferrerChainEntry>* referrer_chain, | 433 ReferrerChain* referrer_chain, |
433 NavigationEvent* nav_event, | 434 NavigationEvent* nav_event, |
434 ReferrerChainEntry::URLType type) { | 435 ReferrerChainEntry::URLType type) { |
435 ReferrerChainEntry referrer_chain_entry; | 436 std::unique_ptr<ReferrerChainEntry> referrer_chain_entry = |
436 referrer_chain_entry.set_url(nav_event->destination_url.spec()); | 437 base::MakeUnique<ReferrerChainEntry>(); |
437 referrer_chain_entry.set_type(type); | 438 referrer_chain_entry->set_url(nav_event->destination_url.spec()); |
439 referrer_chain_entry->set_type(type); | |
438 auto ip_it = host_to_ip_map_.find(nav_event->destination_url.host()); | 440 auto ip_it = host_to_ip_map_.find(nav_event->destination_url.host()); |
439 if (ip_it != host_to_ip_map_.end()) { | 441 if (ip_it != host_to_ip_map_.end()) { |
440 for (ResolvedIPAddress entry : ip_it->second) { | 442 for (ResolvedIPAddress entry : ip_it->second) { |
441 referrer_chain_entry.add_ip_addresses(entry.ip); | 443 referrer_chain_entry->add_ip_addresses(entry.ip); |
442 } | 444 } |
443 } | 445 } |
444 // Since we only track navigation to landing referrer, we will not log the | 446 // Since we only track navigation to landing referrer, we will not log the |
445 // referrer of the landing referrer page. | 447 // referrer of the landing referrer page. |
446 if (type != ReferrerChainEntry::LANDING_REFERRER) { | 448 if (type != ReferrerChainEntry::LANDING_REFERRER) { |
447 referrer_chain_entry.set_referrer_url(nav_event->source_url.spec()); | 449 referrer_chain_entry->set_referrer_url(nav_event->source_url.spec()); |
448 referrer_chain_entry.set_referrer_main_frame_url( | 450 referrer_chain_entry->set_referrer_main_frame_url( |
449 nav_event->source_main_frame_url.spec()); | 451 nav_event->source_main_frame_url.spec()); |
450 } | 452 } |
451 referrer_chain_entry.set_is_retargeting(nav_event->source_tab_id != | 453 referrer_chain_entry->set_is_retargeting(nav_event->source_tab_id != |
452 nav_event->target_tab_id); | 454 nav_event->target_tab_id); |
453 referrer_chain_entry.set_navigation_time_msec( | 455 referrer_chain_entry->set_navigation_time_msec( |
454 nav_event->last_updated.ToJavaTime()); | 456 nav_event->last_updated.ToJavaTime()); |
455 referrer_chain->push_back(std::move(referrer_chain_entry)); | 457 referrer_chain->push_back(std::move(referrer_chain_entry)); |
456 } | 458 } |
457 | 459 |
458 void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain( | 460 void SafeBrowsingNavigationObserverManager::GetRemainingReferrerChain( |
459 NavigationEvent* last_nav_event_traced, | 461 NavigationEvent* last_nav_event_traced, |
460 int current_user_gesture_count, | 462 int current_user_gesture_count, |
461 int user_gesture_count_limit, | 463 int user_gesture_count_limit, |
462 std::vector<ReferrerChainEntry>* out_referrer_chain, | 464 ReferrerChain* out_referrer_chain, |
463 SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { | 465 SafeBrowsingNavigationObserverManager::AttributionResult* out_result) { |
464 | 466 |
465 while (current_user_gesture_count < user_gesture_count_limit) { | 467 while (current_user_gesture_count < user_gesture_count_limit) { |
466 // Back trace to the next nav_event that was initiated by the user. | 468 // Back trace to the next nav_event that was initiated by the user. |
467 while (!last_nav_event_traced->is_user_initiated) { | 469 while (!last_nav_event_traced->is_user_initiated) { |
468 last_nav_event_traced = | 470 last_nav_event_traced = |
469 FindNavigationEvent(last_nav_event_traced->source_url, | 471 FindNavigationEvent(last_nav_event_traced->source_url, |
470 last_nav_event_traced->source_main_frame_url, | 472 last_nav_event_traced->source_main_frame_url, |
471 last_nav_event_traced->source_tab_id); | 473 last_nav_event_traced->source_tab_id); |
472 if (!last_nav_event_traced) | 474 if (!last_nav_event_traced) |
(...skipping 26 matching lines...) Expand all Loading... | |
499 | 501 |
500 AddToReferrerChain(out_referrer_chain, last_nav_event_traced, | 502 AddToReferrerChain(out_referrer_chain, last_nav_event_traced, |
501 GetURLTypeAndAdjustAttributionResult( | 503 GetURLTypeAndAdjustAttributionResult( |
502 current_user_gesture_count == | 504 current_user_gesture_count == |
503 user_gesture_count_limit, | 505 user_gesture_count_limit, |
504 out_result)); | 506 out_result)); |
505 } | 507 } |
506 } | 508 } |
507 | 509 |
508 } // namespace safe_browsing | 510 } // namespace safe_browsing |
OLD | NEW |