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

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

Issue 2654913004: predictors: Add prefetcher histograms for speculative prefetch. (Closed)
Patch Set: Fix types. Created 3 years, 11 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
« no previous file with comments | « no previous file | chrome/browser/predictors/resource_prefetcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_H_ 5 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_
6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ 6 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <list> 10 #include <list>
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <utility> 13 #include <utility>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/scoped_vector.h" 17 #include "base/memory/scoped_vector.h"
18 #include "base/threading/thread_checker.h" 18 #include "base/threading/thread_checker.h"
19 #include "chrome/browser/predictors/resource_prefetch_common.h" 19 #include "chrome/browser/predictors/resource_prefetch_common.h"
20 #include "net/url_request/redirect_info.h" 20 #include "net/url_request/redirect_info.h"
21 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace net { 24 namespace net {
25 class URLRequestContext; 25 class URLRequestContext;
26 } 26 }
27 27
28 namespace predictors { 28 namespace predictors {
29 29
30 namespace internal {
31 constexpr char kResourcePrefetchPredictorCachePatternHistogram[] =
32 "ResourcePrefetchPredictor.CachePattern";
33 constexpr char kResourcePrefetchPredictorPrefetchedCountHistogram[] =
34 "ResourcePrefetchPredictor.PrefetchedCount";
35 constexpr char kResourcePrefetchPredictorPrefetchedSizeHistogram[] =
36 "ResourcePrefetchPredictor.PrefetchedSizeKB";
37 } // namespace internal
38
30 // Responsible for prefetching resources for a single main frame URL based on 39 // Responsible for prefetching resources for a single main frame URL based on
31 // the input list of resources. 40 // the input list of resources.
32 // - Limits the max number of resources in flight for any host and also across 41 // - Limits the max number of resources in flight for any host and also across
33 // hosts. 42 // hosts.
34 // - When stopped, will wait for the pending requests to finish. 43 // - When stopped, will wait for the pending requests to finish.
35 // - Lives entirely on the IO thread. 44 // - Lives entirely on the IO thread.
36 class ResourcePrefetcher : public net::URLRequest::Delegate { 45 class ResourcePrefetcher : public net::URLRequest::Delegate {
37 public: 46 public:
38 // Used to communicate when the prefetching is done. All methods are invoked 47 // Used to communicate when the prefetching is done. All methods are invoked
39 // on the IO thread. 48 // on the IO thread.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // out the Start() call to net::URLRequest for unittesting. 83 // out the Start() call to net::URLRequest for unittesting.
75 virtual void StartURLRequest(net::URLRequest* request); 84 virtual void StartURLRequest(net::URLRequest* request);
76 85
77 // Marks the request as finished, with the given status. 86 // Marks the request as finished, with the given status.
78 void FinishRequest(net::URLRequest* request); 87 void FinishRequest(net::URLRequest* request);
79 88
80 // Reads the response data from the response - required for the resource to 89 // Reads the response data from the response - required for the resource to
81 // be cached correctly. Stubbed out during testing. 90 // be cached correctly. Stubbed out during testing.
82 virtual void ReadFullResponse(net::URLRequest* request); 91 virtual void ReadFullResponse(net::URLRequest* request);
83 92
93 // Called after successfull reading of response to save stats for histograms.
94 void RequestComplete(net::URLRequest* request);
95
84 // net::URLRequest::Delegate methods. 96 // net::URLRequest::Delegate methods.
85 void OnReceivedRedirect(net::URLRequest* request, 97 void OnReceivedRedirect(net::URLRequest* request,
86 const net::RedirectInfo& redirect_info, 98 const net::RedirectInfo& redirect_info,
87 bool* defer_redirect) override; 99 bool* defer_redirect) override;
88 void OnAuthRequired(net::URLRequest* request, 100 void OnAuthRequired(net::URLRequest* request,
89 net::AuthChallengeInfo* auth_info) override; 101 net::AuthChallengeInfo* auth_info) override;
90 void OnCertificateRequested( 102 void OnCertificateRequested(
91 net::URLRequest* request, 103 net::URLRequest* request,
92 net::SSLCertRequestInfo* cert_request_info) override; 104 net::SSLCertRequestInfo* cert_request_info) override;
93 void OnSSLCertificateError(net::URLRequest* request, 105 void OnSSLCertificateError(net::URLRequest* request,
94 const net::SSLInfo& ssl_info, 106 const net::SSLInfo& ssl_info,
95 bool fatal) override; 107 bool fatal) override;
96 void OnResponseStarted(net::URLRequest* request, int net_error) override; 108 void OnResponseStarted(net::URLRequest* request, int net_error) override;
97 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; 109 void OnReadCompleted(net::URLRequest* request, int bytes_read) override;
98 110
99 enum PrefetcherState { 111 enum PrefetcherState {
100 INITIALIZED = 0, // Prefetching hasn't started. 112 INITIALIZED = 0, // Prefetching hasn't started.
101 RUNNING = 1, // Prefetching started, allowed to add more requests. 113 RUNNING = 1, // Prefetching started, allowed to add more requests.
102 STOPPED = 2, // Prefetching started, not allowed to add more requests. 114 STOPPED = 2, // Prefetching started, not allowed to add more requests.
103 FINISHED = 3 // No more inflight request, new requests not possible. 115 FINISHED = 3 // No more inflight request, new requests not possible.
104 }; 116 };
105 117
106 base::ThreadChecker thread_checker_; 118 base::ThreadChecker thread_checker_;
107 PrefetcherState state_; 119 PrefetcherState state_;
108 Delegate* const delegate_; 120 Delegate* const delegate_;
109 ResourcePrefetchPredictorConfig const config_; 121 ResourcePrefetchPredictorConfig const config_;
110 GURL main_frame_url_; 122 GURL main_frame_url_;
111 std::unique_ptr<GURL> urls_; 123
124 // For histogram reports.
125 size_t prefetched_count_;
126 int64_t prefetched_bytes_;
112 127
113 std::map<net::URLRequest*, std::unique_ptr<net::URLRequest>> 128 std::map<net::URLRequest*, std::unique_ptr<net::URLRequest>>
114 inflight_requests_; 129 inflight_requests_;
115 std::list<GURL> request_queue_; 130 std::list<GURL> request_queue_;
116 std::map<std::string, size_t> host_inflight_counts_; 131 std::map<std::string, size_t> host_inflight_counts_;
117 132
118 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcher); 133 DISALLOW_COPY_AND_ASSIGN(ResourcePrefetcher);
119 }; 134 };
120 135
121 } // namespace predictors 136 } // namespace predictors
122 137
123 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_ 138 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCHER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/predictors/resource_prefetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698