OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ | |
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ | |
7 | |
8 #include <map> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/stl_util.h" | |
12 #include "chrome/browser/predictors/resource_prefetcher.h" | |
13 #include "chrome/browser/predictors/resource_prefetch_common.h" | |
14 | |
15 namespace net { | |
16 class URLRequestContextGetter; | |
17 } | |
18 | |
19 namespace predictors { | |
20 | |
21 struct NavigationID; | |
22 class ResourcePrefetchPredictor; | |
23 | |
24 // Manages prefetches for multple navigations. | |
25 // - Created and owned by the resource prefetch predictor. | |
26 // - 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 // - Will only allow one inflight prefresh per main frame URL. | |
29 class ResourcePrefetcherManager | |
30 : public base::RefCountedThreadSafe<ResourcePrefetcherManager> { | |
31 public: | |
32 // The 'predictor' should be live till ShutdownOnIOThread is called. | |
dominich
2012/08/02 15:00:50
nit: variable name ||
Shishir
2012/08/02 22:06:54
Done.
| |
33 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor, | |
34 const ResourcePrefetchPredictorConfig& config, | |
35 net::URLRequestContextGetter* getter); | |
36 | |
37 // UI thread. | |
38 void ShutdownOnUIThread(); | |
39 | |
40 // --- IO Thread methods. | |
41 | |
42 // The prefetchers need to be deleted on the IO thread. | |
43 void ShutdownOnIOThread(); | |
44 | |
45 // Will create a new ResourcePrefetcher for the main frame url of the input | |
46 // navigation if there isn't one already for the same URL. | |
47 void MaybeAddPrefetch(const NavigationID& navigation_id, | |
48 scoped_ptr<ResourcePrefetcher::RequestVector> requests); | |
49 | |
50 // Stops the ResourcePrefetcher for the input navigation, if one was in | |
51 // progress. | |
52 void MaybeRemovePrefetch(const NavigationID& navigation_id); | |
53 | |
54 // Called by the ResourcePrefetcher when it finishes. Takes ownership of | |
55 // requests. | |
56 virtual void ResourcePrefetcherFinished( | |
57 ResourcePrefetcher* prefetcher, | |
58 ResourcePrefetcher::RequestVector* requests); | |
59 | |
60 // Called by the ResourcePrefetcher. | |
61 virtual net::URLRequestContext* GetURLRequestContext(); | |
62 | |
63 private: | |
64 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; | |
65 friend class ResourcePrefetcherManagerTest; | |
66 | |
67 typedef std::map<GURL, ResourcePrefetcher*> PrefetcherMap; | |
68 | |
69 virtual ~ResourcePrefetcherManager(); | |
70 | |
71 // UI Thread. 'predictor_' needs to be called on the UI thread. | |
dominich
2012/08/02 15:00:50
nit: variable name ||
Shishir
2012/08/02 22:06:54
Done.
| |
72 void ResourcePrefetcherFinishedOnUI( | |
73 const NavigationID& navigation_id, | |
74 scoped_ptr<ResourcePrefetcher::RequestVector> requests); | |
75 | |
76 ResourcePrefetchPredictor* predictor_; | |
77 const ResourcePrefetchPredictorConfig const config_; | |
78 net::URLRequestContextGetter* const context_getter_; | |
79 | |
80 PrefetcherMap prefetcher_map_; // Owns the pointers. | |
dominich
2012/08/02 15:00:50
nit: owns what pointers?
Shishir
2012/08/02 22:06:54
Done.
| |
81 STLValueDeleter<PrefetcherMap> prefetcher_map_deleter_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); | |
84 }; | |
85 | |
86 } // namespace predictors | |
87 | |
88 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ | |
OLD | NEW |