| 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 // given |origin|. May trigger actions, such as prefetch and/or preconnect. | 46 // given |origin|. May trigger actions, such as prefetch and/or preconnect. |
| 46 void PrepareForPageLoad(const GURL& url, HintOrigin origin); | 47 void PrepareForPageLoad(const GURL& url, HintOrigin origin); |
| 47 | 48 |
| 48 // Indicates that a page load hint is no longer active. | 49 // Indicates that a page load hint is no longer active. |
| 49 void CancelPageLoadHint(const GURL& url); | 50 void CancelPageLoadHint(const GURL& url); |
| 50 | 51 |
| 51 // Starts initialization, will complete asynchronously. | 52 // Starts initialization, will complete asynchronously. |
| 52 void StartInitialization(); | 53 void StartInitialization(); |
| 53 | 54 |
| 54 // Don't use, internal only. | 55 // Don't use, internal only. |
| 55 ResourcePrefetchPredictor* resource_prefetch_predictor() const; | 56 ResourcePrefetchPredictor* resource_prefetch_predictor(); |
| 57 LoadingDataCollector* loading_data_collector(); |
| 56 | 58 |
| 57 // KeyedService: | 59 // KeyedService: |
| 58 void Shutdown() override; | 60 void Shutdown() override; |
| 59 | 61 |
| 60 void OnMainFrameRequest( | 62 void OnMainFrameRequest( |
| 61 const ResourcePrefetchPredictor::URLRequestSummary& summary); | 63 const ResourcePrefetchPredictor::URLRequestSummary& summary); |
| 62 void OnMainFrameRedirect( | 64 void OnMainFrameRedirect( |
| 63 const ResourcePrefetchPredictor::URLRequestSummary& summary); | 65 const ResourcePrefetchPredictor::URLRequestSummary& summary); |
| 64 void OnMainFrameResponse( | 66 void OnMainFrameResponse( |
| 65 const ResourcePrefetchPredictor::URLRequestSummary& summary); | 67 const ResourcePrefetchPredictor::URLRequestSummary& summary); |
| 66 | 68 |
| 67 private: | 69 private: |
| 68 // Cancels an active hint, from its iterator inside |active_hints_|. If the | 70 // Cancels an active hint, from its iterator inside |active_hints_|. If the |
| 69 // iterator is .end(), does nothing. Returns the iterator after deletion of | 71 // iterator is .end(), does nothing. Returns the iterator after deletion of |
| 70 // the entry. | 72 // the entry. |
| 71 std::map<GURL, base::TimeTicks>::iterator CancelActiveHint( | 73 std::map<GURL, base::TimeTicks>::iterator CancelActiveHint( |
| 72 std::map<GURL, base::TimeTicks>::iterator hint_it); | 74 std::map<GURL, base::TimeTicks>::iterator hint_it); |
| 73 void CleanupAbandonedHintsAndNavigations(const NavigationID& navigation_id); | 75 void CleanupAbandonedHintsAndNavigations(const NavigationID& navigation_id); |
| 74 | 76 |
| 75 // For testing. | 77 // For testing. |
| 76 void set_mock_resource_prefetch_predictor( | 78 void set_mock_resource_prefetch_predictor( |
| 77 std::unique_ptr<ResourcePrefetchPredictor> predictor) { | 79 std::unique_ptr<ResourcePrefetchPredictor> predictor) { |
| 78 resource_prefetch_predictor_ = std::move(predictor); | 80 resource_prefetch_predictor_ = std::move(predictor); |
| 79 } | 81 } |
| 80 | 82 |
| 81 LoadingPredictorConfig config_; | 83 LoadingPredictorConfig config_; |
| 82 Profile* profile_; | 84 Profile* profile_; |
| 83 std::unique_ptr<ResourcePrefetchPredictor> resource_prefetch_predictor_; | 85 std::unique_ptr<ResourcePrefetchPredictor> resource_prefetch_predictor_; |
| 84 std::unique_ptr<LoadingStatsCollector> stats_collector_; | 86 std::unique_ptr<LoadingStatsCollector> stats_collector_; |
| 87 std::unique_ptr<LoadingDataCollector> loading_data_collector_; |
| 85 std::map<GURL, base::TimeTicks> active_hints_; | 88 std::map<GURL, base::TimeTicks> active_hints_; |
| 86 // Initial URL. | 89 // Initial URL. |
| 87 std::map<NavigationID, GURL> active_navigations_; | 90 std::map<NavigationID, GURL> active_navigations_; |
| 88 | 91 |
| 89 friend class LoadingPredictorTest; | 92 friend class LoadingPredictorTest; |
| 90 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 93 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 91 TestMainFrameResponseCancelsHint); | 94 TestMainFrameResponseCancelsHint); |
| 92 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 95 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 93 TestMainFrameRequestCancelsStaleNavigations); | 96 TestMainFrameRequestCancelsStaleNavigations); |
| 94 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 97 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 95 TestMainFrameResponseClearsNavigations); | 98 TestMainFrameResponseClearsNavigations); |
| 96 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 99 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 97 TestMainFrameRequestDoesntCancelExternalHint); | 100 TestMainFrameRequestDoesntCancelExternalHint); |
| 98 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, | 101 FRIEND_TEST_ALL_PREFIXES(LoadingPredictorTest, |
| 99 TestDontTrackNonPrefetchableUrls); | 102 TestDontTrackNonPrefetchableUrls); |
| 100 | 103 |
| 101 DISALLOW_COPY_AND_ASSIGN(LoadingPredictor); | 104 DISALLOW_COPY_AND_ASSIGN(LoadingPredictor); |
| 102 }; | 105 }; |
| 103 | 106 |
| 104 } // namespace predictors | 107 } // namespace predictors |
| 105 | 108 |
| 106 #endif // CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_ | 109 #endif // CHROME_BROWSER_PREDICTORS_LOADING_PREDICTOR_H_ |
| OLD | NEW |