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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor.h

Issue 2377643002: predictors: Make the resource_prefetch_predictor accessible from Java. (Closed)
Patch Set: Address comments. Created 4 years, 2 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <set>
12 #include <string> 13 #include <string>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/linked_ptr.h" 18 #include "base/memory/linked_ptr.h"
18 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
19 #include "base/scoped_observer.h" 20 #include "base/scoped_observer.h"
20 #include "base/task/cancelable_task_tracker.h" 21 #include "base/task/cancelable_task_tracker.h"
21 #include "base/time/time.h" 22 #include "base/time/time.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 void OnMainFrameRequest(const URLRequestSummary& request); 187 void OnMainFrameRequest(const URLRequestSummary& request);
187 void OnMainFrameResponse(const URLRequestSummary& response); 188 void OnMainFrameResponse(const URLRequestSummary& response);
188 void OnMainFrameRedirect(const URLRequestSummary& response); 189 void OnMainFrameRedirect(const URLRequestSummary& response);
189 void OnSubresourceResponse(const URLRequestSummary& response); 190 void OnSubresourceResponse(const URLRequestSummary& response);
190 191
191 // Called when onload completes for a navigation. We treat this point as the 192 // Called when onload completes for a navigation. We treat this point as the
192 // "completion" of the navigation. The resources requested by the page up to 193 // "completion" of the navigation. The resources requested by the page up to
193 // this point are the only ones considered for prefetching. 194 // this point are the only ones considered for prefetching.
194 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info); 195 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info);
195 196
196 // Returns true if there is PrefetchData that can be used for the 197 // Returns true if there is PrefetchData that can be used for a URL and fills
197 // navigation and fills in the |prefetch_data| to resources that need to be 198 // in the |prefetch_data| to resources that need to be prefetched.
198 // prefetched. 199 bool GetPrefetchData(const GURL& main_frame_url, std::vector<GURL>* urls);
199 bool GetPrefetchData(const NavigationID& navigation_id,
200 std::vector<GURL>* urls,
201 PrefetchKeyType* key_type);
202 200
203 // Converts a PrefetchData into a list of URLs. 201 // Converts a PrefetchData into a list of URLs.
204 void PopulatePrefetcherRequest(const PrefetchData& data, 202 void PopulatePrefetcherRequest(const PrefetchData& data,
205 std::vector<GURL>* urls); 203 std::vector<GURL>* urls);
206 204
205 public:
207 // Starts prefetching if it is enabled and prefetching data exists for the 206 // Starts prefetching if it is enabled and prefetching data exists for the
208 // NavigationID either at the URL or at the host level. 207 // NavigationID either at the URL or at the host level.
209 void StartPrefetching(const NavigationID& navigation_id); 208 void StartPrefetching(const GURL& main_frame_url);
210 209
211 // Stops prefetching that may be in progress corresponding to |navigation_id|. 210 // Stops prefetching that may be in progress corresponding to |navigation_id|.
212 void StopPrefetching(const NavigationID& navigation_id); 211 void StopPrefetching(const GURL& main_frame_url);
213 212
213 private:
214 // Starts initialization by posting a task to the DB thread to read the 214 // Starts initialization by posting a task to the DB thread to read the
215 // predictor database. 215 // predictor database.
216 void StartInitialization(); 216 void StartInitialization();
217 217
218 // Callback for task to read predictor database. Takes ownership of 218 // Callback for task to read predictor database. Takes ownership of
219 // |url_data_map| and |host_data_map|. 219 // |url_data_map| and |host_data_map|.
220 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map, 220 void CreateCaches(std::unique_ptr<PrefetchDataMap> url_data_map,
221 std::unique_ptr<PrefetchDataMap> host_data_map); 221 std::unique_ptr<PrefetchDataMap> host_data_map);
222 222
223 // Called during initialization when history is read and the predictor 223 // Called during initialization when history is read and the predictor
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 298
299 ScopedObserver<history::HistoryService, history::HistoryServiceObserver> 299 ScopedObserver<history::HistoryService, history::HistoryServiceObserver>
300 history_service_observer_; 300 history_service_observer_;
301 301
302 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor); 302 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetchPredictor);
303 }; 303 };
304 304
305 } // namespace predictors 305 } // namespace predictors
306 306
307 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_ 307 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698