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

Side by Side Diff: extensions/browser/extension_api_frame_id_map.h

Issue 2002763003: webRequest: reliably determine tabId (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webRequest-testing-unload
Patch Set: Last nits Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ 6 #define EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // Get the extension API frame ID for the parent of |navigation_handle|. 97 // Get the extension API frame ID for the parent of |navigation_handle|.
98 static int GetParentFrameId(content::NavigationHandle* navigation_handle); 98 static int GetParentFrameId(content::NavigationHandle* navigation_handle);
99 99
100 // Find the current RenderFrameHost for a given WebContents and extension 100 // Find the current RenderFrameHost for a given WebContents and extension
101 // frame ID. 101 // frame ID.
102 // Returns nullptr if not found. 102 // Returns nullptr if not found.
103 static content::RenderFrameHost* GetRenderFrameHostById( 103 static content::RenderFrameHost* GetRenderFrameHostById(
104 content::WebContents* web_contents, 104 content::WebContents* web_contents,
105 int frame_id); 105 int frame_id);
106 106
107 // Runs |callback| with the result that is equivalent to calling GetFrameId() 107 // Runs |callback| with a result that is equivalent to calling GetFrameData()
108 // on the UI thread. Thread hopping is minimized if possible. Callbacks for 108 // on the UI thread. Thread hopping is minimized if possible. Callbacks for
109 // the same |render_process_id| and |frame_routing_id| are guaranteed to be 109 // the same |render_process_id| and |frame_routing_id| are guaranteed to be
110 // run in order. The order of other callbacks is undefined. 110 // run in order. The order of other callbacks is undefined.
111 void GetFrameDataOnIO(int render_process_id, 111 void GetFrameDataOnIO(int render_process_id,
112 int frame_routing_id, 112 int frame_routing_id,
113 const FrameDataCallback& callback); 113 const FrameDataCallback& callback);
114 114
115 // Attempts to populate |frame_data_out| with the FrameData for the specified 115 // Attempts to populate |frame_data_out| with the FrameData for the specified
116 // frame, but only does so if the data is already cached. Returns true if 116 // frame, but only does so if the data is already cached. Returns true if
117 // cached frame data was found. 117 // cached frame data was found.
118 bool GetCachedFrameDataOnIO(int render_process_id, 118 bool GetCachedFrameDataOnIO(int render_process_id,
119 int frame_routing_id, 119 int frame_routing_id,
120 FrameData* frame_data_out); 120 FrameData* frame_data_out);
121 121
122 // Looks up the frame ID and stores it in the map. This method should be 122 // Retrieves the FrameData for a given |rfh|. The map may be updated with the
123 // result if the map did not contain the FrameData before the lookup.
124 FrameData GetFrameData(content::RenderFrameHost* rfh) WARN_UNUSED_RESULT;
125
126 // Looks up the FrameData and stores it in the map. This method should be
123 // called as early as possible, e.g. in a 127 // called as early as possible, e.g. in a
124 // WebContentsObserver::RenderFrameCreated notification. 128 // WebContentsObserver::RenderFrameCreated notification.
125 void CacheFrameData(content::RenderFrameHost* rfh); 129 void CacheFrameData(content::RenderFrameHost* rfh);
126 130
127 // Removes the frame ID mapping for a given frame. This method can be called 131 // Removes the FrameData mapping for a given frame. This method can be called
128 // at any time, but it is typically called when a frame is destroyed. 132 // at any time, but it is typically called when a frame is destroyed.
129 // If this method is not called, the cached mapping for the frame is retained 133 // If this method is not called, the cached mapping for the frame is retained
130 // forever. 134 // forever.
131 void RemoveFrameData(content::RenderFrameHost* rfh); 135 void RemoveFrameData(content::RenderFrameHost* rfh);
132 136
133 // Updates the tab and window id for the given RenderFrameHost, if any exists. 137 // Updates the tab and window id for the given RenderFrameHost, if any exists.
134 void UpdateTabAndWindowId(int tab_id, 138 void UpdateTabAndWindowId(int tab_id,
135 int window_id, 139 int window_id,
136 content::RenderFrameHost* rfh); 140 content::RenderFrameHost* rfh);
137 141
(...skipping 27 matching lines...) Expand all
165 // To avoid re-entrant processing of callbacks. 169 // To avoid re-entrant processing of callbacks.
166 bool is_iterating; 170 bool is_iterating;
167 }; 171 };
168 172
169 using FrameDataMap = std::map<RenderFrameIdKey, FrameData>; 173 using FrameDataMap = std::map<RenderFrameIdKey, FrameData>;
170 using FrameDataCallbacksMap = std::map<RenderFrameIdKey, FrameDataCallbacks>; 174 using FrameDataCallbacksMap = std::map<RenderFrameIdKey, FrameDataCallbacks>;
171 175
172 ExtensionApiFrameIdMap(); 176 ExtensionApiFrameIdMap();
173 virtual ~ExtensionApiFrameIdMap(); 177 virtual ~ExtensionApiFrameIdMap();
174 178
175 // Determines the value to be stored in |frame_id_map_| for a given key. This 179 // Determines the value to be stored in |frame_data_map_| for a given key.
176 // method is only called when |key| is not in |frame_id_map_|. 180 // This method is only called when |key| is not in |frame_data_map_|.
177 // virtual for testing. 181 // virtual for testing.
178 virtual FrameData KeyToValue(const RenderFrameIdKey& key) const; 182 virtual FrameData KeyToValue(const RenderFrameIdKey& key) const;
179 183
180 // Looks up the data for the given |key| and adds it to the |frame_data_map_|. 184 // Looks up the data for the given |key| and adds it to the |frame_data_map_|.
181 // |for_lookup| indicates whether this is for a pending lookup (as opposed to 185 // |is_from_io| indicates whether the lookup originated from the IO thread.
182 // preemptively caching the frame data). 186 FrameData LookupFrameDataOnUI(const RenderFrameIdKey& key, bool is_from_io);
183 FrameData LookupFrameDataOnUI(const RenderFrameIdKey& key, bool for_lookup);
184 187
185 // Called as soon as the frame ID is found for the given |key|, and runs all 188 // Called as soon as the frame data is found for the given |key|, and runs all
186 // queued callbacks with |cached_frame_id_pair|. 189 // queued callbacks with |cached_frame_data|.
187 void ReceivedFrameDataOnIO(const RenderFrameIdKey& key, 190 void ReceivedFrameDataOnIO(const RenderFrameIdKey& key,
188 const FrameData& cached_frame_id_pair); 191 const FrameData& cached_frame_data);
189 192
190 // Implementation of CacheFrameId(RenderFrameHost), separated for testing. 193 // Implementation of CacheFrameData(RenderFrameHost), separated for testing.
191 void CacheFrameData(const RenderFrameIdKey& key); 194 void CacheFrameData(const RenderFrameIdKey& key);
192 195
193 // Implementation of RemoveFrameId(RenderFrameHost), separated for testing. 196 // Implementation of RemoveFrameData(RenderFrameHost), separated for testing.
194 void RemoveFrameData(const RenderFrameIdKey& key); 197 void RemoveFrameData(const RenderFrameIdKey& key);
195 198
196 std::unique_ptr<ExtensionApiFrameIdMapHelper> helper_; 199 std::unique_ptr<ExtensionApiFrameIdMapHelper> helper_;
197 200
198 // Queued callbacks for use on the IO thread. 201 // Queued callbacks for use on the IO thread.
199 FrameDataCallbacksMap callbacks_map_; 202 FrameDataCallbacksMap callbacks_map_;
200 203
201 // This map is only modified on the UI thread and is used to minimize the 204 // This map is only modified on the UI thread and is used to minimize the
202 // number of thread hops on the IO thread. 205 // number of thread hops on the IO thread.
203 FrameDataMap frame_data_map_; 206 FrameDataMap frame_data_map_;
204 207
205 // This lock protects |frame_id_map_| from being concurrently written on the 208 // This lock protects |frame_data_map_| from being concurrently written on the
206 // UI thread and read on the IO thread. 209 // UI thread and read on the IO thread.
207 base::Lock frame_data_map_lock_; 210 base::Lock frame_data_map_lock_;
208 211
209 DISALLOW_COPY_AND_ASSIGN(ExtensionApiFrameIdMap); 212 DISALLOW_COPY_AND_ASSIGN(ExtensionApiFrameIdMap);
210 }; 213 };
211 214
212 } // namespace extensions 215 } // namespace extensions
213 216
214 #endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_ 217 #endif // EXTENSIONS_BROWSER_EXTENSION_API_FRAME_ID_MAP_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_event_details.cc ('k') | extensions/browser/extension_api_frame_id_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698