OLD | NEW |
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 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
12 #include "chrome/browser/predictors/resource_prefetch_common.h" | 13 #include "chrome/browser/predictors/resource_prefetch_common.h" |
13 #include "chrome/browser/predictors/resource_prefetcher.h" | 14 #include "chrome/browser/predictors/resource_prefetcher.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 class URLRequestContextGetter; | 17 class URLRequestContextGetter; |
17 } | 18 } |
18 | 19 |
19 namespace predictors { | 20 namespace predictors { |
20 | 21 |
21 struct NavigationID; | 22 struct NavigationID; |
22 class ResourcePrefetchPredictor; | 23 class ResourcePrefetchPredictor; |
23 | 24 |
24 // Manages prefetches for multple navigations. | 25 // Manages prefetches for multiple navigations. |
25 // - Created and owned by the resource prefetch predictor. | 26 // - Created and owned by the resource prefetch predictor. |
26 // - 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. |
27 // - 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. |
28 // - Will only allow one inflight prefresh per main frame URL. | 29 // - Will only allow one inflight prefresh per main frame URL. |
29 class ResourcePrefetcherManager | 30 class ResourcePrefetcherManager |
30 : public ResourcePrefetcher::Delegate, | 31 : public ResourcePrefetcher::Delegate, |
31 public base::RefCountedThreadSafe<ResourcePrefetcherManager> { | 32 public base::RefCountedThreadSafe<ResourcePrefetcherManager> { |
32 public: | 33 public: |
33 // The |predictor| should be alive till ShutdownOnIOThread is called. | 34 // The |predictor| should be alive till ShutdownOnIOThread is called. |
34 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor, | 35 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor, |
(...skipping 20 matching lines...) Expand all Loading... |
55 void MaybeRemovePrefetch(const NavigationID& navigation_id); | 56 void MaybeRemovePrefetch(const NavigationID& navigation_id); |
56 | 57 |
57 // ResourcePrefetcher::Delegate methods. | 58 // ResourcePrefetcher::Delegate methods. |
58 void ResourcePrefetcherFinished(ResourcePrefetcher* prefetcher) override; | 59 void ResourcePrefetcherFinished(ResourcePrefetcher* prefetcher) override; |
59 net::URLRequestContext* GetURLRequestContext() override; | 60 net::URLRequestContext* GetURLRequestContext() override; |
60 | 61 |
61 private: | 62 private: |
62 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; | 63 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; |
63 friend class MockResourcePrefetcherManager; | 64 friend class MockResourcePrefetcherManager; |
64 | 65 |
65 typedef std::map<std::string, ResourcePrefetcher*> PrefetcherMap; | |
66 | |
67 ~ResourcePrefetcherManager() override; | 66 ~ResourcePrefetcherManager() override; |
68 | 67 |
69 ResourcePrefetchPredictor* predictor_; | 68 ResourcePrefetchPredictor* predictor_; |
70 const ResourcePrefetchPredictorConfig config_; | 69 const ResourcePrefetchPredictorConfig config_; |
71 net::URLRequestContextGetter* const context_getter_; | 70 net::URLRequestContextGetter* const context_getter_; |
72 | 71 |
73 PrefetcherMap prefetcher_map_; // Owns the ResourcePrefetcher pointers. | 72 std::map<std::string, std::unique_ptr<ResourcePrefetcher>> prefetcher_map_; |
74 | 73 |
75 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); | 74 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); |
76 }; | 75 }; |
77 | 76 |
78 } // namespace predictors | 77 } // namespace predictors |
79 | 78 |
80 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ | 79 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ |
OLD | NEW |