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 #include "components/domain_reliability/monitor.h" | 5 #include "components/domain_reliability/monitor.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
40 virtual scoped_refptr<base::SingleThreadTaskRunner> | 40 virtual scoped_refptr<base::SingleThreadTaskRunner> |
41 GetNetworkTaskRunner() const OVERRIDE { | 41 GetNetworkTaskRunner() const OVERRIDE { |
42 return main_task_runner_; | 42 return main_task_runner_; |
43 } | 43 } |
44 | 44 |
45 private: | 45 private: |
46 virtual ~TrivialURLRequestContextGetter() {} | 46 virtual ~TrivialURLRequestContextGetter() {} |
47 | 47 |
48 net::URLRequestContext* context_; | 48 net::URLRequestContext* context_; |
49 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 49 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
50 }; | 50 }; |
Ryan Sleevi
2014/04/26 02:37:39
Why have this at all? If you need a URLRequestCont
Deprecated (see juliatuttle)
2014/04/28 22:01:13
See .h for explanation, although I'm willing to re
| |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 namespace domain_reliability { | 54 namespace domain_reliability { |
55 | 55 |
56 DomainReliabilityMonitor::DomainReliabilityMonitor( | 56 DomainReliabilityMonitor::DomainReliabilityMonitor( |
57 net::URLRequestContext* url_request_context) | 57 net::URLRequestContext* url_request_context) |
58 : time_(new ActualTime()), | 58 : time_(new ActualTime()), |
59 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( | 59 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( |
60 new TrivialURLRequestContextGetter( | 60 new TrivialURLRequestContextGetter( |
(...skipping 20 matching lines...) Expand all Loading... | |
81 scheduler_params_( | 81 scheduler_params_( |
82 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), | 82 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), |
83 dispatcher_(time_.get()), | 83 dispatcher_(time_.get()), |
84 uploader_( | 84 uploader_( |
85 DomainReliabilityUploader::Create(url_request_context_getter_)) { | 85 DomainReliabilityUploader::Create(url_request_context_getter_)) { |
86 DCHECK(OnIOThread()); | 86 DCHECK(OnIOThread()); |
87 } | 87 } |
88 | 88 |
89 DomainReliabilityMonitor::~DomainReliabilityMonitor() { | 89 DomainReliabilityMonitor::~DomainReliabilityMonitor() { |
90 DCHECK(OnIOThread()); | 90 DCHECK(OnIOThread()); |
91 STLDeleteContainerPairSecondPointers( | 91 STLDeleteContainerPairSecondPointers(contexts_.begin(), contexts_.end()); |
92 contexts_.begin(), contexts_.end()); | |
93 } | 92 } |
94 | 93 |
95 void DomainReliabilityMonitor::AddBakedInConfigs() { | 94 void DomainReliabilityMonitor::AddBakedInConfigs() { |
96 base::Time now = base::Time::Now(); | 95 base::Time now = base::Time::Now(); |
97 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) { | 96 for (size_t i = 0; kBakedInJsonConfigs[i]; ++i) { |
98 std::string json(kBakedInJsonConfigs[i]); | 97 std::string json(kBakedInJsonConfigs[i]); |
99 scoped_ptr<const DomainReliabilityConfig> config = | 98 scoped_ptr<const DomainReliabilityConfig> config = |
100 DomainReliabilityConfig::FromJSON(json); | 99 DomainReliabilityConfig::FromJSON(json); |
101 if (config && config->IsExpired(now)) { | 100 if (config && config->IsExpired(now)) { |
102 LOG(WARNING) << "Baked-in Domain Reliability config for " | 101 LOG(WARNING) << "Baked-in Domain Reliability config for " |
103 << config->domain << " is expired."; | 102 << config->domain << " is expired."; |
104 continue; | 103 continue; |
105 } | 104 } |
106 AddContext(config.Pass()); | 105 AddContext(config.Pass()); |
107 } | 106 } |
108 } | 107 } |
109 | 108 |
110 void DomainReliabilityMonitor::OnBeforeRedirect(net::URLRequest* request) { | 109 void DomainReliabilityMonitor::OnBeforeRedirect(net::URLRequest* request) { |
111 DCHECK(OnIOThread()); | 110 DCHECK(OnIOThread()); |
112 RequestInfo request_info(*request); | |
113 // Record the redirect itself in addition to the final request. | 111 // Record the redirect itself in addition to the final request. |
114 OnRequestLegComplete(request_info); | 112 OnRequestLegComplete(RequestInfo(*request)); |
115 } | 113 } |
116 | 114 |
117 void DomainReliabilityMonitor::OnCompleted(net::URLRequest* request, | 115 void DomainReliabilityMonitor::OnCompleted(net::URLRequest* request, |
118 bool started) { | 116 bool started) { |
119 DCHECK(OnIOThread()); | 117 DCHECK(OnIOThread()); |
120 if (!started) | 118 if (!started) |
121 return; | 119 return; |
122 RequestInfo request_info(*request); | 120 RequestInfo request_info(*request); |
123 if (request_info.DefinitelyReachedNetwork()) { | 121 if (request_info.DefinitelyReachedNetwork()) { |
124 OnRequestLegComplete(request_info); | 122 OnRequestLegComplete(request_info); |
125 // A request was just using the network, so now is a good time to run any | 123 // A request was just using the network, so now is a good time to run any |
126 // pending and eligible uploads. | 124 // pending and eligible uploads. |
127 dispatcher_.RunEligibleTasks(); | 125 dispatcher_.RunEligibleTasks(); |
128 } | 126 } |
129 } | 127 } |
130 | 128 |
131 DomainReliabilityContext* DomainReliabilityMonitor::AddContextForTesting( | 129 DomainReliabilityContext* DomainReliabilityMonitor::AddContextForTesting( |
132 scoped_ptr<const DomainReliabilityConfig> config) { | 130 scoped_ptr<const DomainReliabilityConfig> config) { |
133 return AddContext(config.Pass()); | 131 return AddContext(config.Pass()); |
134 } | 132 } |
135 | 133 |
136 DomainReliabilityMonitor::RequestInfo::RequestInfo() {} | 134 DomainReliabilityMonitor::RequestInfo::RequestInfo() {} |
137 | 135 |
138 DomainReliabilityMonitor::RequestInfo::RequestInfo( | 136 DomainReliabilityMonitor::RequestInfo::RequestInfo( |
139 const net::URLRequest& request) | 137 const net::URLRequest& request) |
140 : url(request.url()), | 138 : url(request.url()), |
Ryan Sleevi
2014/04/26 02:37:39
If request.url().is_valid() is false, you'll never
Deprecated (see juliatuttle)
2014/04/28 22:01:13
I still need the URL to match against patterns in
| |
141 status(request.status()), | 139 status(request.status()), |
142 response_code(-1), | 140 response_code(-1), |
143 socket_address(request.GetSocketAddress()), | 141 socket_address(request.GetSocketAddress()), |
144 was_cached(request.was_cached()), | 142 was_cached(request.was_cached()), |
145 load_flags(request.load_flags()) { | 143 load_flags(request.load_flags()) { |
146 request.GetLoadTimingInfo(&load_timing_info); | 144 request.GetLoadTimingInfo(&load_timing_info); |
147 // Can't get response code of a canceled request -- there's no transaction. | 145 // Can't get response code of a canceled request -- there's no transaction. |
148 if (status.status() != net::URLRequestStatus::CANCELED) | 146 if (status.status() != net::URLRequestStatus::CANCELED) |
149 response_code = request.GetResponseCode(); | 147 response_code = request.GetResponseCode(); |
150 } | 148 } |
151 | 149 |
152 DomainReliabilityMonitor::RequestInfo::~RequestInfo() {} | 150 DomainReliabilityMonitor::RequestInfo::~RequestInfo() {} |
153 | 151 |
154 bool DomainReliabilityMonitor::RequestInfo::DefinitelyReachedNetwork() const { | 152 bool DomainReliabilityMonitor::RequestInfo::DefinitelyReachedNetwork() const { |
155 return status.status() != net::URLRequestStatus::CANCELED && !was_cached; | 153 return status.status() != net::URLRequestStatus::CANCELED && !was_cached; |
156 } | 154 } |
157 | 155 |
158 DomainReliabilityContext* DomainReliabilityMonitor::AddContext( | 156 DomainReliabilityContext* DomainReliabilityMonitor::AddContext( |
159 scoped_ptr<const DomainReliabilityConfig> config) { | 157 scoped_ptr<const DomainReliabilityConfig> config) { |
160 DCHECK(config); | 158 DCHECK(config); |
161 DCHECK(config->IsValid()); | 159 DCHECK(config->IsValid()); |
162 | 160 |
163 // Grab domain before we config.Pass(). | 161 // Grab domain before we config.Pass(). |
Ryan Sleevi
2014/04/26 02:37:39
// Grab a copy of the domain before transferring o
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Done.
| |
164 std::string domain = config->domain; | 162 std::string domain = config->domain; |
165 | 163 |
166 DomainReliabilityContext* context = new DomainReliabilityContext( | 164 DomainReliabilityContext* context = new DomainReliabilityContext( |
167 time_.get(), | 165 time_.get(), |
168 scheduler_params_, | 166 scheduler_params_, |
169 &dispatcher_, | 167 &dispatcher_, |
170 uploader_.get(), | 168 uploader_.get(), |
171 config.Pass()); | 169 config.Pass()); |
172 | 170 |
173 std::pair<ContextMap::iterator, bool> map_it = | 171 std::pair<ContextMap::iterator, bool> map_it = |
(...skipping 24 matching lines...) Expand all Loading... | |
198 bool got_status = DomainReliabilityUtil::GetBeaconStatus( | 196 bool got_status = DomainReliabilityUtil::GetBeaconStatus( |
199 request.status.error(), | 197 request.status.error(), |
200 request.response_code, | 198 request.response_code, |
201 &beacon_status); | 199 &beacon_status); |
202 if (!got_status) | 200 if (!got_status) |
203 return; | 201 return; |
204 | 202 |
205 DomainReliabilityBeacon beacon; | 203 DomainReliabilityBeacon beacon; |
206 beacon.status = beacon_status; | 204 beacon.status = beacon_status; |
207 beacon.chrome_error = request.status.error(); | 205 beacon.chrome_error = request.status.error(); |
208 beacon.server_ip = request.socket_address.host(); | 206 beacon.server_ip = request.socket_address.host(); |
Ryan Sleevi
2014/04/26 02:37:39
SECURITY/PRIVACY: Is there any risk that this may
Deprecated (see juliatuttle)
2014/04/28 22:01:13
Looking into it.
| |
209 beacon.http_response_code = request.response_code; | 207 beacon.http_response_code = request.response_code; |
210 beacon.start_time = request.load_timing_info.request_start; | 208 beacon.start_time = request.load_timing_info.request_start; |
211 beacon.elapsed = time_->NowTicks() - beacon.start_time; | 209 beacon.elapsed = time_->NowTicks() - beacon.start_time; |
212 context->AddBeacon(beacon, request.url); | 210 context->AddBeacon(beacon, request.url); |
213 } | 211 } |
214 | 212 |
215 } // namespace domain_reliability | 213 } // namespace domain_reliability |
OLD | NEW |