Chromium Code Reviews| 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 content::WebContents* web_contents) { |
|
lpz
2017/04/20 14:37:02
Feels like it might be better to keep passing Prof
Jialiu Lin
2017/04/20 18:02:56
Acknowledged.
IsEnabledAndReady is only called ins
| |
| 219 return base::FeatureList::IsEnabled( | 216 Profile* profile = |
| 220 SafeBrowsingNavigationObserverManager::kDownloadAttribution) && | 217 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 221 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && | 218 return profile && |
| 222 g_browser_process->safe_browsing_service() && | 219 profile->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |
| 223 g_browser_process->safe_browsing_service()->navigation_observer_manager(); | 220 g_browser_process->safe_browsing_service() && |
| 221 g_browser_process->safe_browsing_service() | |
| 222 ->navigation_observer_manager(); | |
| 224 } | 223 } |
| 225 | 224 |
| 226 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() | 225 SafeBrowsingNavigationObserverManager::SafeBrowsingNavigationObserverManager() |
| 227 : navigation_event_list_(kNavigationRecordMaxSize) { | 226 : navigation_event_list_(kNavigationRecordMaxSize) { |
| 228 | 227 |
| 229 // Schedule clean up in 2 minutes. | 228 // Schedule clean up in 2 minutes. |
| 230 ScheduleNextCleanUpAfterInterval( | 229 ScheduleNextCleanUpAfterInterval( |
| 231 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); | 230 base::TimeDelta::FromSecondsD(kNavigationFootprintTTLInSecond)); |
| 232 } | 231 } |
| 233 | 232 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 out_result)); | 585 out_result)); |
| 587 // Stop searching if the size of out_referrer_chain already reached its | 586 // Stop searching if the size of out_referrer_chain already reached its |
| 588 // limit. | 587 // limit. |
| 589 if (out_referrer_chain->size() == kReferrerChainMaxLength) | 588 if (out_referrer_chain->size() == kReferrerChainMaxLength) |
| 590 return; | 589 return; |
| 591 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; | 590 last_main_frame_url_traced = last_nav_event_traced->source_main_frame_url; |
| 592 } | 591 } |
| 593 } | 592 } |
| 594 | 593 |
| 595 } // namespace safe_browsing | 594 } // namespace safe_browsing |
| OLD | NEW |