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

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

Issue 2373443002: predictors: Key the resource prefetcher by URL, not navigation. (Closed)
Patch Set: 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_PREFETCHER_MANAGER_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "chrome/browser/predictors/resource_prefetch_common.h" 13 #include "chrome/browser/predictors/resource_prefetch_common.h"
14 #include "chrome/browser/predictors/resource_prefetcher.h" 14 #include "chrome/browser/predictors/resource_prefetcher.h"
15 15
16 namespace net { 16 namespace net {
17 class URLRequestContextGetter; 17 class URLRequestContextGetter;
18 } 18 }
19 19
20 namespace predictors { 20 namespace predictors {
21 21
22 struct NavigationID; 22 struct NavigationID;
23 class ResourcePrefetchPredictor; 23 class ResourcePrefetchPredictor;
24 24
25 // Manages prefetches for multiple navigations. 25 // Manages prefetches for multiple navigations.
26 // - Created and owned by the resource prefetch predictor. 26 // - Created and owned by the resource prefetch predictor.
27 // - Needs to be refcounted as it is de-referenced on two different threads. 27 // - Needs to be refcounted as it is de-referenced on two different threads.
28 // - Created on the UI thread, but most functions are called in the IO thread. 28 // - Created on the UI thread, but most functions are called in the IO thread.
29 // - Will only allow one inflight prefresh per main frame URL. 29 // - Will only allow one inflight prefresh per host.
30 class ResourcePrefetcherManager 30 class ResourcePrefetcherManager
31 : public ResourcePrefetcher::Delegate, 31 : public ResourcePrefetcher::Delegate,
32 public base::RefCountedThreadSafe<ResourcePrefetcherManager> { 32 public base::RefCountedThreadSafe<ResourcePrefetcherManager> {
33 public: 33 public:
34 // The |predictor| should be alive till ShutdownOnIOThread is called. 34 // The |predictor| should be alive till ShutdownOnIOThread is called.
35 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor, 35 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor,
36 const ResourcePrefetchPredictorConfig& config, 36 const ResourcePrefetchPredictorConfig& config,
37 net::URLRequestContextGetter* getter); 37 net::URLRequestContextGetter* getter);
38 38
39 // UI thread. 39 // UI thread.
40 void ShutdownOnUIThread(); 40 void ShutdownOnUIThread();
41 41
42 // --- IO Thread methods. 42 // --- IO Thread methods.
43 43
44 // The prefetchers need to be deleted on the IO thread. 44 // The prefetchers need to be deleted on the IO thread.
45 void ShutdownOnIOThread(); 45 void ShutdownOnIOThread();
46 46
47 // Will create a new ResourcePrefetcher for the main frame url of the input 47 // Will create a new ResourcePrefetcher for the main frame url of the input
48 // navigation if there isn't one already for the same URL or host (for host 48 // navigation if there isn't one already for the same host.
49 // based).
50 void MaybeAddPrefetch(const NavigationID& navigation_id, 49 void MaybeAddPrefetch(const NavigationID& navigation_id,
51 PrefetchKeyType key_type,
52 const std::vector<GURL>& urls); 50 const std::vector<GURL>& urls);
53 51
54 // Stops the ResourcePrefetcher for the input navigation, if one was in 52 // Stops the ResourcePrefetcher for the input navigation, if one was in
55 // progress. 53 // progress.
56 void MaybeRemovePrefetch(const NavigationID& navigation_id); 54 void MaybeRemovePrefetch(const NavigationID& navigation_id);
57 55
58 // ResourcePrefetcher::Delegate methods. 56 // ResourcePrefetcher::Delegate methods.
59 void ResourcePrefetcherFinished(ResourcePrefetcher* prefetcher) override; 57 void ResourcePrefetcherFinished(ResourcePrefetcher* prefetcher) override;
60 net::URLRequestContext* GetURLRequestContext() override; 58 net::URLRequestContext* GetURLRequestContext() override;
61 59
62 private: 60 private:
63 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; 61 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>;
64 friend class MockResourcePrefetcherManager; 62 friend class MockResourcePrefetcherManager;
65 63
66 ~ResourcePrefetcherManager() override; 64 ~ResourcePrefetcherManager() override;
67 65
68 ResourcePrefetchPredictor* predictor_; 66 ResourcePrefetchPredictor* predictor_;
69 const ResourcePrefetchPredictorConfig config_; 67 const ResourcePrefetchPredictorConfig config_;
70 net::URLRequestContextGetter* const context_getter_; 68 net::URLRequestContextGetter* const context_getter_;
71 69
72 std::map<std::string, std::unique_ptr<ResourcePrefetcher>> prefetcher_map_; 70 std::map<std::string, std::unique_ptr<ResourcePrefetcher>> prefetcher_map_;
73 71
74 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); 72 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager);
75 }; 73 };
76 74
77 } // namespace predictors 75 } // namespace predictors
78 76
79 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ 77 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetcher.cc ('k') | chrome/browser/predictors/resource_prefetcher_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698