| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_LOADING_PREDICTOR_H_ | 5 #ifndef CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_ |
| 6 #define CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_ | 6 #define CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "chrome/browser/predictors/loading_data_collector.h" |
| 15 #include "chrome/browser/predictors/resource_prefetch_common.h" | 16 #include "chrome/browser/predictors/resource_prefetch_common.h" |
| 16 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 17 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 17 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace predictors { | 23 namespace predictors { |
| 23 | 24 |
| 24 class ResourcePrefetchPredictor; | 25 class ResourcePrefetchPredictor; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 45 void PrepareForPageLoad(const GURL& url, HintOrigin origin); | 46 void PrepareForPageLoad(const GURL& url, HintOrigin origin); |
| 46 | 47 |
| 47 // Indicates that a page load hint is no longer active. | 48 // Indicates that a page load hint is no longer active. |
| 48 void CancelPageLoadHint(const GURL& url); | 49 void CancelPageLoadHint(const GURL& url); |
| 49 | 50 |
| 50 // Starts initialization, will complete asynchronously. | 51 // Starts initialization, will complete asynchronously. |
| 51 void StartInitialization(); | 52 void StartInitialization(); |
| 52 | 53 |
| 53 // Don't use, internal only. | 54 // Don't use, internal only. |
| 54 ResourcePrefetchPredictor* resource_prefetch_predictor() const; | 55 ResourcePrefetchPredictor* resource_prefetch_predictor() const; |
| 56 LoadingDataCollector* loading_data_collector() const; |
| 55 | 57 |
| 56 // KeyedService: | 58 // KeyedService: |
| 57 void Shutdown() override; | 59 void Shutdown() override; |
| 58 | 60 |
| 59 void OnMainFrameRequest( | 61 void OnMainFrameRequest( |
| 60 const ResourcePrefetchPredictor::URLRequestSummary& summary); | 62 const ResourcePrefetchPredictor::URLRequestSummary& summary); |
| 61 void OnMainFrameRedirect( | 63 void OnMainFrameRedirect( |
| 62 const ResourcePrefetchPredictor::URLRequestSummary& summary); | 64 const ResourcePrefetchPredictor::URLRequestSummary& summary); |
| 63 void OnMainFrameResponse( | 65 void OnMainFrameResponse( |
| 64 const ResourcePrefetchPredictor::URLRequestSummary& summary); | 66 const ResourcePrefetchPredictor::URLRequestSummary& summary); |
| 65 | 67 |
| 66 private: | 68 private: |
| 67 // Cancels an active hint, from its iterator inside |active_hints_|. If the | 69 // Cancels an active hint, from its iterator inside |active_hints_|. If the |
| 68 // iterator is .end(), does nothing. Returns the iterator after deletion of | 70 // iterator is .end(), does nothing. Returns the iterator after deletion of |
| 69 // the entry. | 71 // the entry. |
| 70 std::map<GURL, base::TimeTicks>::iterator CancelActiveHint( | 72 std::map<GURL, base::TimeTicks>::iterator CancelActiveHint( |
| 71 std::map<GURL, base::TimeTicks>::iterator hint_it); | 73 std::map<GURL, base::TimeTicks>::iterator hint_it); |
| 72 void CleanupAbandonedHintsAndNavigations(const NavigationID& navigation_id); | 74 void CleanupAbandonedHintsAndNavigations(const NavigationID& navigation_id); |
| 73 | 75 |
| 74 // For testing. | 76 // For testing. |
| 75 void set_mock_resource_prefetch_predictor( | 77 void set_mock_resource_prefetch_predictor( |
| 76 std::unique_ptr<ResourcePrefetchPredictor> predictor) { | 78 std::unique_ptr<ResourcePrefetchPredictor> predictor) { |
| 77 resource_prefetch_predictor_ = std::move(predictor); | 79 resource_prefetch_predictor_ = std::move(predictor); |
| 78 } | 80 } |
| 79 | 81 |
| 80 LoadingPredictorConfig config_; | 82 LoadingPredictorConfig config_; |
| 81 Profile* profile_; | 83 Profile* profile_; |
| 82 std::unique_ptr<ResourcePrefetchPredictor> resource_prefetch_predictor_; | 84 std::unique_ptr<ResourcePrefetchPredictor> resource_prefetch_predictor_; |
| 85 std::unique_ptr<LoadingDataCollector> loading_data_collector_; |
| 83 std::map<GURL, base::TimeTicks> active_hints_; | 86 std::map<GURL, base::TimeTicks> active_hints_; |
| 84 // Initial URL. | 87 // Initial URL. |
| 85 std::map<NavigationID, GURL> active_navigations_; | 88 std::map<NavigationID, GURL> active_navigations_; |
| 86 | 89 |
| 87 friend class LoadingPredictorTest; | 90 friend class LoadingPredictorTest; |
| 88 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 91 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 89 TestMainFrameResponseCancelsHint); | 92 TestMainFrameResponseCancelsHint); |
| 90 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 93 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 91 TestMainFrameRequestCancelsStaleNavigations); | 94 TestMainFrameRequestCancelsStaleNavigations); |
| 92 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 95 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 93 TestMainFrameResponseClearsNavigations); | 96 TestMainFrameResponseClearsNavigations); |
| 94 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 97 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 95 TestMainFrameRequestDoesntCancelExternalHint); | 98 TestMainFrameRequestDoesntCancelExternalHint); |
| 96 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 99 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 97 TestDontTrackNonPrefetchableUrls); | 100 TestDontTrackNonPrefetchableUrls); |
| 98 | 101 |
| 99 DISALLOW_COPY_AND_ASSIGN(LoadingPredictor); | 102 DISALLOW_COPY_AND_ASSIGN(LoadingPredictor); |
| 100 }; | 103 }; |
| 101 | 104 |
| 102 } // namespace predictors | 105 } // namespace predictors |
| 103 | 106 |
| 104 #endif // CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_ | 107 #endif // CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_ |
| OLD | NEW |