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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_navigation_observer_manager.h

Issue 2601303002: Wireup SafeBrowsingNavigationObserverManager to help PPAPI download attribution (Closed)
Patch Set: add check for rfh Created 3 years, 11 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 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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H _ 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H _
6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H _ 6 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGER_H _
7 7
8 #include "base/feature_list.h" 8 #include "base/feature_list.h"
9 #include "chrome/common/safe_browsing/csd.pb.h" 9 #include "chrome/common/safe_browsing/csd.pb.h"
10 #include "content/public/browser/notification_observer.h" 10 #include "content/public/browser/notification_observer.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 SafeBrowsingNavigationObserverManager(); 63 SafeBrowsingNavigationObserverManager();
64 64
65 // Add |nav_event| to |navigation_map_| based on |nav_event_key|. Object 65 // Add |nav_event| to |navigation_map_| based on |nav_event_key|. Object
66 // pointed to by |nav_event| will be no longer accessible after this function. 66 // pointed to by |nav_event| will be no longer accessible after this function.
67 void RecordNavigationEvent(const GURL& nav_event_key, 67 void RecordNavigationEvent(const GURL& nav_event_key,
68 NavigationEvent* nav_event); 68 NavigationEvent* nav_event);
69 void RecordUserGestureForWebContents(content::WebContents* web_contents, 69 void RecordUserGestureForWebContents(content::WebContents* web_contents,
70 const base::Time& timestamp); 70 const base::Time& timestamp);
71 void OnUserGestureConsumed(content::WebContents* web_contents, 71 void OnUserGestureConsumed(content::WebContents* web_contents,
72 const base::Time& timestamp); 72 const base::Time& timestamp);
73 bool HasUserGesture(content::WebContents* web_contents);
73 void RecordHostToIpMapping(const std::string& host, const std::string& ip); 74 void RecordHostToIpMapping(const std::string& host, const std::string& ip);
74 75
75 // Clean-ups need to be done when a WebContents gets destroyed. 76 // Clean-ups need to be done when a WebContents gets destroyed.
76 void OnWebContentDestroyed(content::WebContents* web_contents); 77 void OnWebContentDestroyed(content::WebContents* web_contents);
77 78
78 // Remove all the observed NavigationEvents, user gestures, and resolved IP 79 // Remove all the observed NavigationEvents, user gestures, and resolved IP
79 // addresses that are older than kNavigationFootprintTTLInSecond. 80 // addresses that are older than kNavigationFootprintTTLInSecond.
80 void CleanUpStaleNavigationFootprints(); 81 void CleanUpStaleNavigationFootprints();
81 82
82 // Based on the |target_url| and |target_tab_id|, trace back the observed 83 // Based on the |target_url| and |target_tab_id|, trace back the observed
83 // NavigationEvents in navigation_map_ to identify the sequence of navigations 84 // NavigationEvents in navigation_map_ to identify the sequence of navigations
84 // leading to the target, with the coverage limited to 85 // leading to the target, with the coverage limited to
85 // |user_gesture_count_limit| number of user gestures. Then convert these 86 // |user_gesture_count_limit| number of user gestures. Then convert these
86 // identified NavigationEvents into ReferrerChainEntrys and append them to 87 // identified NavigationEvents into ReferrerChainEntrys and append them to
87 // |out_referrer_chain|. 88 // |out_referrer_chain|.
88 AttributionResult IdentifyReferrerChain( 89 AttributionResult IdentifyReferrerChainForDownload(
89 const GURL& target_url, 90 const GURL& target_url,
90 int target_tab_id, // -1 if tab id is not valid 91 int target_tab_id, // -1 if tab id is not valid
91 int user_gesture_count_limit, 92 int user_gesture_count_limit,
92 std::vector<ReferrerChainEntry>* out_referrer_chain); 93 std::vector<ReferrerChainEntry>* out_referrer_chain);
93 94
95 // Based on the |initiating_frame_url| and its associated |tab_id|, trace back
96 // the observed NavigationEvents in navigation_map_ to identify the sequence
97 // of navigations leading to this |initiating_frame_url|. If this initiating
98 // frame has a user gesture, we trace back with the coverage limited to
99 // |user_gesture_count_limit|-1 number of user gestures, otherwise we trace
100 // back |user_gesture_count_limit| number of user gestures. We then convert
101 // these identified NavigationEvents into ReferrerChainEntrys and append them
102 // to |out_referrer_chain|.
103 AttributionResult IdentifyReferrerChainForPPAPIDownload(
104 const GURL& initiating_frame_url,
105 int tab_id,
106 bool has_user_gesture,
107 int user_gesture_count_limit,
108 std::vector<ReferrerChainEntry>* out_referrer_chain);
109
94 private: 110 private:
95 friend class base::RefCountedThreadSafe< 111 friend class base::RefCountedThreadSafe<
96 SafeBrowsingNavigationObserverManager>; 112 SafeBrowsingNavigationObserverManager>;
97 friend class TestNavigationObserverManager; 113 friend class TestNavigationObserverManager;
98 friend class SBNavigationObserverBrowserTest; 114 friend class SBNavigationObserverBrowserTest;
99 friend class SBNavigationObserverTest; 115 friend class SBNavigationObserverTest;
100 116
101 struct GurlHash { 117 struct GurlHash {
102 std::size_t operator()(const GURL& url) const { 118 std::size_t operator()(const GURL& url) const {
103 return std::hash<std::string>()(url.spec()); 119 return std::hash<std::string>()(url.spec());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 // However, it does not prevent us to attribute url1 in Window A as the cause 177 // However, it does not prevent us to attribute url1 in Window A as the cause
162 // of all these navigations. 178 // of all these navigations.
163 NavigationEvent* FindNavigationEvent(const GURL& target_url, 179 NavigationEvent* FindNavigationEvent(const GURL& target_url,
164 const GURL& target_main_frame_url, 180 const GURL& target_main_frame_url,
165 int target_tab_id); 181 int target_tab_id);
166 182
167 void AddToReferrerChain(std::vector<ReferrerChainEntry>* referrer_chain, 183 void AddToReferrerChain(std::vector<ReferrerChainEntry>* referrer_chain,
168 NavigationEvent* nav_event, 184 NavigationEvent* nav_event,
169 ReferrerChainEntry::URLType type); 185 ReferrerChainEntry::URLType type);
170 186
187 // Helper function to get the remaining referrer chain when we've already
188 // traced back |current_user_gesture_count| number of user gestures.
189 // This function modifies the |out_referrer_chain| and |out_result|.
190 void GetRemainingReferrerChain(
191 NavigationEvent* last_nav_event_traced,
192 int current_user_gesture_count,
193 int user_gesture_count_limit,
194 std::vector<ReferrerChainEntry>* out_referrer_chain,
195 AttributionResult* out_result);
196
171 // navigation_map_ keeps track of all the observed navigations. This map is 197 // navigation_map_ keeps track of all the observed navigations. This map is
172 // keyed on the resolved request url. In other words, in case of server 198 // keyed on the resolved request url. In other words, in case of server
173 // redirects, its key is the last server redirect url, otherwise, it is the 199 // redirects, its key is the last server redirect url, otherwise, it is the
174 // original target url. Since the same url can be requested multiple times 200 // original target url. Since the same url can be requested multiple times
175 // across different tabs and frames, the value of this map is a vector of 201 // across different tabs and frames, the value of this map is a vector of
176 // NavigationEvent ordered by navigation finish time. 202 // NavigationEvent ordered by navigation finish time.
177 // Entries in navigation_map_ will be removed if they are older than 2 minutes 203 // Entries in navigation_map_ will be removed if they are older than 2 minutes
178 // since their corresponding navigations finish. 204 // since their corresponding navigations finish.
179 NavigationMap navigation_map_; 205 NavigationMap navigation_map_;
180 206
(...skipping 11 matching lines...) Expand all
192 218
193 content::NotificationRegistrar registrar_; 219 content::NotificationRegistrar registrar_;
194 220
195 base::OneShotTimer cleanup_timer_; 221 base::OneShotTimer cleanup_timer_;
196 222
197 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserverManager); 223 DISALLOW_COPY_AND_ASSIGN(SafeBrowsingNavigationObserverManager);
198 }; 224 };
199 } // namespace safe_browsing 225 } // namespace safe_browsing
200 226
201 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGE R_H_ 227 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_NAVIGATION_OBSERVER_MANAGE R_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698