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