| 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 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "chrome/browser/predictors/resource_prefetch_common.h" | 15 #include "chrome/browser/predictors/loading_predictor_config.h" |
| 16 #include "chrome/browser/predictors/resource_prefetcher.h" | 16 #include "chrome/browser/predictors/resource_prefetcher.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class URLRequestContextGetter; | 19 class URLRequestContextGetter; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace predictors { | 22 namespace predictors { |
| 23 | 23 |
| 24 class ResourcePrefetchPredictor; | 24 class ResourcePrefetchPredictor; |
| 25 | 25 |
| 26 // Manages prefetches for multiple navigations. | 26 // Manages prefetches for multiple navigations. |
| 27 // - Created and owned by the resource prefetch predictor. | 27 // - Created and owned by the resource prefetch predictor. |
| 28 // - Needs to be refcounted as it is de-referenced on two different threads. | 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. | 29 // - Created on the UI thread, but most functions are called in the IO thread. |
| 30 // - Will only allow one inflight prefresh per host. | 30 // - Will only allow one inflight prefresh per host. |
| 31 class ResourcePrefetcherManager | 31 class ResourcePrefetcherManager |
| 32 : public ResourcePrefetcher::Delegate, | 32 : public ResourcePrefetcher::Delegate, |
| 33 public base::RefCountedThreadSafe<ResourcePrefetcherManager> { | 33 public base::RefCountedThreadSafe<ResourcePrefetcherManager> { |
| 34 public: | 34 public: |
| 35 // The |predictor| should be alive till ShutdownOnIOThread is called. | 35 // The |predictor| should be alive till ShutdownOnIOThread is called. |
| 36 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor, | 36 ResourcePrefetcherManager(ResourcePrefetchPredictor* predictor, |
| 37 const ResourcePrefetchPredictorConfig& config, | 37 const LoadingPredictorConfig& config, |
| 38 net::URLRequestContextGetter* getter); | 38 net::URLRequestContextGetter* getter); |
| 39 | 39 |
| 40 // UI thread. | 40 // UI thread. |
| 41 void ShutdownOnUIThread(); | 41 void ShutdownOnUIThread(); |
| 42 | 42 |
| 43 // --- IO Thread methods. | 43 // --- IO Thread methods. |
| 44 | 44 |
| 45 // The prefetchers need to be deleted on the IO thread. | 45 // The prefetchers need to be deleted on the IO thread. |
| 46 void ShutdownOnIOThread(); | 46 void ShutdownOnIOThread(); |
| 47 | 47 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 60 std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) override; | 60 std::unique_ptr<ResourcePrefetcher::PrefetcherStats> stats) override; |
| 61 net::URLRequestContext* GetURLRequestContext() override; | 61 net::URLRequestContext* GetURLRequestContext() override; |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; | 64 friend class base::RefCountedThreadSafe<ResourcePrefetcherManager>; |
| 65 friend class MockResourcePrefetcherManager; | 65 friend class MockResourcePrefetcherManager; |
| 66 | 66 |
| 67 ~ResourcePrefetcherManager() override; | 67 ~ResourcePrefetcherManager() override; |
| 68 | 68 |
| 69 ResourcePrefetchPredictor* predictor_; | 69 ResourcePrefetchPredictor* predictor_; |
| 70 const ResourcePrefetchPredictorConfig config_; | 70 const LoadingPredictorConfig config_; |
| 71 net::URLRequestContextGetter* const context_getter_; | 71 net::URLRequestContextGetter* const context_getter_; |
| 72 | 72 |
| 73 std::map<std::string, std::unique_ptr<ResourcePrefetcher>> prefetcher_map_; | 73 std::map<std::string, std::unique_ptr<ResourcePrefetcher>> prefetcher_map_; |
| 74 | 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); | 75 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcherManager); |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 } // namespace predictors | 78 } // namespace predictors |
| 79 | 79 |
| 80 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ | 80 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_MANAGER_H_ |
| OLD | NEW |