Chromium Code Reviews| 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/linked_ptr.h" | |
| 11 #include "base/memory/ref_counted.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 | |
| 23 // Manages prefetches for multple navigations. | |
| 24 // - Created and owned by the resource prefetch predictor. | |
| 25 // - Created on the UI thread, but most functions are called in the IO thread. | |
| 26 // - Will only allow one inflight prefresh per main frame URL. | |
| 27 class ResourcePrefetcherManager | |
| 28 : public ResourcePrefetcher::Delegate, | |
| 29 public base::RefCountedThreadSafe<ResourcePrefetcherManager> { | |
|
dominich
2012/07/23 16:04:41
If this is created and owned by the resource prefe
Shishir
2012/08/01 22:35:24
Because this needs to be de-referenced on two diff
| |
| 30 public: | |
| 31 // Used to notify when prefetching is done for a single navigation. | |
| 32 // The Delegate will be called on the UI Thread and should be alive till | |
| 33 // ShutdownOnUIThread is called. | |
| 34 // manager. | |
|
dominich
2012/07/23 16:04:41
nit: extra word.
Shishir
2012/08/01 22:35:24
Done.
| |
| 35 class Delegate { | |
|
dominich
2012/07/23 16:04:41
I think this is such a tightly bound system that u
Shishir
2012/08/01 22:35:24
Removed.
| |
| 36 public: | |
| 37 virtual ~Delegate() { } | |
| 38 virtual void FinishedPrefetchForNavigation( | |
| 39 const NavigationID& navigation_id, | |
| 40 scoped_ptr<ResourcePrefetcher::RequestVector> requests) = 0; | |
| 41 }; | |
| 42 | |
| 43 ResourcePrefetcherManager(Delegate* delegate, | |
| 44 const ResourcePrefetchPredictorConfig& config, | |
| 45 net::URLRequestContextGetter* getter); | |
| 46 | |
| 47 // UI thread. | |
| 48 void ShutdownOnUIThread(); | |
| 49 | |
| 50 // --- IO Thread methods. | |
| 51 | |
| 52 // The prefetchers need to be deleted on the IO thread. | |
| 53 void ShutdownOnIOThread(); | |
| 54 | |
| 55 // Will create a new ResourcePrefetcher for the main frame url of the input | |
| 56 // navigation if there isn't one already for the same URL. | |
| 57 void MaybeAddPrefetch(const NavigationID& navigation_id, | |
| 58 scoped_ptr<ResourcePrefetcher::RequestVector> requests); | |
| 59 | |
| 60 // Stops the ResourcePrefetcher for the input navigation, if one was in | |
| 61 // progress. | |
| 62 void MaybeRemovePrefetch(const NavigationID& navigation_id); | |
| 63 | |
| 64 private: | |
| 65 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; | |
| 66 | |
| 67 virtual ~ResourcePrefetcherManager(); | |
| 68 | |
| 69 // ResourcePrefetcher::Delegate methods OVERRIDE. | |
| 70 virtual void ResourcePrefetcherFinished( | |
| 71 ResourcePrefetcher* prefetcher, | |
| 72 scoped_ptr<ResourcePrefetcher::RequestVector> requests) OVERRIDE; | |
| 73 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | |
| 74 | |
| 75 // UI Thread. | |
| 76 // The delegate needs to be called on the UI thread. | |
| 77 void ResourcePrefetcherFinishedOnUI( | |
| 78 const NavigationID& navigation_id, | |
| 79 scoped_ptr<ResourcePrefetcher::RequestVector> requests); | |
| 80 | |
| 81 Delegate* delegate_; // Can only be called on the UI thread. | |
| 82 ResourcePrefetchPredictorConfig config_; | |
| 83 net::URLRequestContextGetter* context_getter_; | |
| 84 std::map<GURL, linked_ptr<ResourcePrefetcher> > prefetchers_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); | |
| 87 }; | |
| 88 | |
| 89 } // namespace predictors | |
| 90 | |
| 91 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ | |
| OLD | NEW |