| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 IsEventExpired(navigation_events_[0]->last_updated, | 188 IsEventExpired(navigation_events_[0]->last_updated, |
| 189 kNavigationFootprintTTLInSecond)) { | 189 kNavigationFootprintTTLInSecond)) { |
| 190 navigation_events_.pop_front(); | 190 navigation_events_.pop_front(); |
| 191 removal_count++; | 191 removal_count++; |
| 192 } | 192 } |
| 193 return removal_count; | 193 return removal_count; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // -----------------SafeBrowsingNavigationObserverManager----------- | 196 // -----------------SafeBrowsingNavigationObserverManager----------- |
| 197 // static | 197 // static |
| 198 const base::Feature SafeBrowsingNavigationObserverManager::kDownloadAttribution{ | |
| 199 "DownloadAttribution", base::FEATURE_ENABLED_BY_DEFAULT}; | |
| 200 // static | |
| 201 bool SafeBrowsingNavigationObserverManager::IsUserGestureExpired( | 198 bool SafeBrowsingNavigationObserverManager::IsUserGestureExpired( |
| 202 const base::Time& timestamp) { | 199 const base::Time& timestamp) { |
| 203 return IsEventExpired(timestamp, kUserGestureTTLInSecond); | 200 return IsEventExpired(timestamp, kUserGestureTTLInSecond); |
| 204 } | 201 } |
| 205 | 202 |
| 206 // static | 203 // static |
| 207 GURL SafeBrowsingNavigationObserverManager::ClearEmptyRef(const GURL& url) { | 204 GURL SafeBrowsingNavigationObserverManager::ClearEmptyRef(const GURL& url) { |
| 208 if (url.has_ref() && url.ref().empty()) { | 205 if (url.has_ref() && url.ref().empty()) { |
| 209 url::Replacements<char> replacements; | 206 url::Replacements<char> replacements; |
| 210 replacements.ClearRef(); | 207 replacements.ClearRef(); |
| 211 return url.ReplaceComponents(replacements); | 208 return url.ReplaceComponents(replacements); |
| 212 } | 209 } |
| 213 return url; | 210 return url; |
| 214 } | 211 } |
| 215 | 212 |
| 216 // static | 213 // static |
| 217 bool SafeBrowsingNavigationObserverManager::IsEnabledAndReady( | 214 bool SafeBrowsingNavigationObserverManager::IsEnabledAndReady( |
| 218 Profile* profile) { | 215 Profile* profile) { |
| 219 return base::FeatureList::IsEnabled( | 216 return profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 220 SafeBrowsingNavigationObserverManager::kDownloadAttribution) && | 217 g_browser_process->safe_browsing_service() && |
| 221 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 218 g_browser_process->safe_browsing_service() |
| 222 g_browser_process->safe_browsing_service() && | 219 ->navigation_observer_manager(); |
| 223 g_browser_process->safe_browsing_service()->navigation_observer_manager(); | |
| 224 } | 220 } |
| 225 | 221 |
| 226 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() | 222 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() |
| 227 : navigation_event_list_(kNavigationRecordMaxSize) { | 223 : navigation_event_list_(kNavigationRecordMaxSize) { |
| 228 | 224 |
| 229 // Schedule clean up in 2 minutes. | 225 // Schedule clean up in 2 minutes. |
| 230 ScheduleNextCleanUpAfterInterval( | 226 ScheduleNextCleanUpAfterInterval( |
| 231 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); | 227 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); |
| 232 } | 228 } |
| 233 | 229 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 out_result)); | 582 out_result)); |
| 587 // Stop searching if the size of out_referrer_chain already reached its | 583 // Stop searching if the size of out_referrer_chain already reached its |
| 588 // limit. | 584 // limit. |
| 589 if (out_referrer_chain->size() == kReferrerChainMaxLength) | 585 if (out_referrer_chain->size() == kReferrerChainMaxLength) |
| 590 return; | 586 return; |
| 591 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; | 587 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; |
| 592 } | 588 } |
| 593 } | 589 } |
| 594 | 590 |
| 595 } // namespace safe_browsing | 591 } // namespace safe_browsing |
| OLD | NEW |