Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: chrome/browser/predictors/loading_data_collector.h

Issue 2937623007: predictors: Move more methods from ResourcePrefetchPredictor into LoadingDataCollector. (Closed)
Patch Set: Make InitializationState type public. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_DATA_COLLECTOR_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_
6 #define CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_ 6 #define CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "chrome/browser/predictors/resource_prefetch_predictor.h" 10 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
11 #include "content/public/common/resource_type.h" 11 #include "content/public/common/resource_type.h"
12 12
13 namespace net { 13 namespace net {
14 class URLRequest; 14 class URLRequest;
15 } 15 }
16 16
17 namespace predictors { 17 namespace predictors {
18 18
19 // Records navigation events as reported by various observers to the database 19 // Records navigation events as reported by various observers to the database
20 // and stats collection classes. All the non-static methods of this class need 20 // and stats collection classes. All the non-static methods of this class need
21 // to be called on the UI thread. 21 // to be called on the UI thread.
22 class LoadingDataCollector 22 class LoadingDataCollector
23 : public base::SupportsWeakPtr<LoadingDataCollector> { 23 : public base::SupportsWeakPtr<LoadingDataCollector> {
24 public: 24 public:
25 explicit LoadingDataCollector( 25 explicit LoadingDataCollector(
26 predictors::ResourcePrefetchPredictor* predictor); 26 predictors::ResourcePrefetchPredictor* predictor,
27 predictors::LoadingStatsCollector* stats_collector,
28 const LoadingPredictorConfig& config);
27 ~LoadingDataCollector(); 29 ~LoadingDataCollector();
28 30
29 // Thread safe. 31 // Thread safe.
30 static bool ShouldRecordRequest(net::URLRequest* request, 32 static bool ShouldRecordRequest(net::URLRequest* request,
31 content::ResourceType resource_type); 33 content::ResourceType resource_type);
32 static bool ShouldRecordResponse(net::URLRequest* response); 34 static bool ShouldRecordResponse(net::URLRequest* response);
33 static bool ShouldRecordRedirect(net::URLRequest* response); 35 static bool ShouldRecordRedirect(net::URLRequest* response);
34 36
35 // 'LoadingPredictorObserver' and 'ResourcePrefetchPredictorTabHelper' call 37 // 'LoadingPredictorObserver' and 'ResourcePrefetchPredictorTabHelper' call
36 // the below functions to inform the predictor of main frame and resource 38 // the below functions to inform the collector of main frame and resource
37 // requests. Should only be called if the corresponding Should* functions 39 // requests. Should only be called if the corresponding Should* functions
38 // return true. 40 // return true.
39 void RecordURLRequest( 41 void RecordURLRequest(
40 const predictors::ResourcePrefetchPredictor::URLRequestSummary& request); 42 const predictors::ResourcePrefetchPredictor::URLRequestSummary& request);
41 void RecordURLResponse( 43 void RecordURLResponse(
42 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response); 44 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response);
43 void RecordURLRedirect( 45 void RecordURLRedirect(
44 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response); 46 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response);
45 47
46 // Called when the main frame of a page completes loading. 48 // Called when the main frame of a page completes loading.
47 void RecordMainFrameLoadComplete(const NavigationID& navigation_id); 49 void RecordMainFrameLoadComplete(const NavigationID& navigation_id);
48 50
49 // Called after the main frame's first contentful paint. 51 // Called after the main frame's first contentful paint.
50 void RecordFirstContentfulPaint( 52 virtual void RecordFirstContentfulPaint(
alexilin 2017/06/14 11:41:54 Why virtual?
trevordixon 2017/06/16 05:11:28 So a MockLoadingDataCollector can override it. Doe
alexilin 2017/06/16 09:31:57 Yes, it has to be virtual to be overriden by mock
51 const NavigationID& navigation_id, 53 const NavigationID& navigation_id,
52 const base::TimeTicks& first_contentful_paint); 54 const base::TimeTicks& first_contentful_paint);
53 55
54 private: 56 private:
55 friend class ResourcePrefetchPredictorBrowserTest; 57 friend class ResourcePrefetchPredictorBrowserTest;
56 58
57 FRIEND_TEST_ALL_PREFIXES(LoadingDataCollectorTest, HandledResourceTypes); 59 FRIEND_TEST_ALL_PREFIXES(LoadingDataCollectorTest, HandledResourceTypes);
58 60
59 // Returns true if the main page request is supported for prediction. 61 // Returns true if the main page request is supported for prediction.
60 static bool IsHandledMainPage(net::URLRequest* request); 62 static bool IsHandledMainPage(net::URLRequest* request);
61 63
62 // Returns true if the subresource request is supported for prediction. 64 // Returns true if the subresource request is supported for prediction.
63 static bool IsHandledSubresource(net::URLRequest* request, 65 static bool IsHandledSubresource(net::URLRequest* request,
64 content::ResourceType resource_type); 66 content::ResourceType resource_type);
65 67
66 // Returns true if the subresource has a supported type. 68 // Returns true if the subresource has a supported type.
67 static bool IsHandledResourceType(content::ResourceType resource_type, 69 static bool IsHandledResourceType(content::ResourceType resource_type,
68 const std::string& mime_type); 70 const std::string& mime_type);
69 71
70 static void SetAllowPortInUrlsForTesting(bool state); 72 static void SetAllowPortInUrlsForTesting(bool state);
71 73
74 // Functions called on different network events pertaining to the loading of
75 // main frame resource or sub resources.
76 void OnMainFrameRequest(
77 const predictors::ResourcePrefetchPredictor::URLRequestSummary& request);
78 void OnMainFrameRedirect(
79 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response);
80 void OnSubresourceResponse(
81 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response);
82 void OnSubresourceRedirect(
83 const predictors::ResourcePrefetchPredictor::URLRequestSummary& response);
84
85 // Called when onload completes for a navigation. We treat this point as the
86 // "completion" of the navigation. The resources requested by the page up to
87 // this point are the only ones considered for prefetching.
alexilin 2017/06/14 11:41:54 s/for prefetching//
trevordixon 2017/06/16 05:11:28 Done.
88 void OnNavigationComplete(const NavigationID& nav_id_without_timing_info);
89
90 // Cleanup inflight_navigations_ and call a cleanup for stats_collector_.
91 void CleanupAbandonedNavigations(const NavigationID& navigation_id);
92
93 typedef std::map<
alexilin 2017/06/14 11:41:54 This formatting looks strange. Did you run `git cl
trevordixon 2017/06/16 05:11:28 Yes, this is what it did!
alexilin 2017/06/16 09:31:57 Ok, it's much better after stripping namespaces!
94 NavigationID,
95 std::unique_ptr<
96 predictors::ResourcePrefetchPredictor::PageRequestSummary>>
97 NavigationMap;
98
72 predictors::ResourcePrefetchPredictor* const predictor_; 99 predictors::ResourcePrefetchPredictor* const predictor_;
100 predictors::LoadingStatsCollector* const stats_collector_;
101 const LoadingPredictorConfig config_;
102
103 NavigationMap inflight_navigations_;
73 }; 104 };
74 105
75 } // namespace predictors 106 } // namespace predictors
76 107
77 #endif // CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_ 108 #endif // CHROME_BROWSER_PREDICTORS_LOADING_DATA_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698