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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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( |
61 url_request_context, | 61 url_request_context, |
62 content::BrowserThread::GetMessageLoopProxyForThread( | 62 content::BrowserThread::GetMessageLoopProxyForThread( |
63 content::BrowserThread::IO)))), | 63 content::BrowserThread::IO)))), |
64 scheduler_params_( | 64 scheduler_params_( |
65 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), | 65 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), |
66 dispatcher_(time_.get()), | 66 dispatcher_(time_.get()), |
67 uploader_( | 67 uploader_( |
68 DomainReliabilityUploader::Create(url_request_context_getter_)) { | 68 DomainReliabilityUploader::Create(url_request_context_getter_)), |
69 was_cleared_(false), | |
70 cleared_mode_(MAX_CLEAR_MODE) { | |
69 DCHECK(OnIOThread()); | 71 DCHECK(OnIOThread()); |
70 } | 72 } |
71 | 73 |
72 DomainReliabilityMonitor::DomainReliabilityMonitor( | 74 DomainReliabilityMonitor::DomainReliabilityMonitor( |
73 net::URLRequestContext* url_request_context, | 75 net::URLRequestContext* url_request_context, |
74 scoped_ptr<MockableTime> time) | 76 scoped_ptr<MockableTime> time) |
75 : time_(time.Pass()), | 77 : time_(time.Pass()), |
76 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( | 78 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( |
77 new TrivialURLRequestContextGetter( | 79 new TrivialURLRequestContextGetter( |
78 url_request_context, | 80 url_request_context, |
79 content::BrowserThread::GetMessageLoopProxyForThread( | 81 content::BrowserThread::GetMessageLoopProxyForThread( |
80 content::BrowserThread::IO)))), | 82 content::BrowserThread::IO)))), |
81 scheduler_params_( | 83 scheduler_params_( |
82 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), | 84 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), |
83 dispatcher_(time_.get()), | 85 dispatcher_(time_.get()), |
84 uploader_( | 86 uploader_( |
85 DomainReliabilityUploader::Create(url_request_context_getter_)) { | 87 DomainReliabilityUploader::Create(url_request_context_getter_)), |
88 was_cleared_(false), | |
89 cleared_mode_(MAX_CLEAR_MODE) { | |
86 DCHECK(OnIOThread()); | 90 DCHECK(OnIOThread()); |
87 } | 91 } |
88 | 92 |
89 DomainReliabilityMonitor::~DomainReliabilityMonitor() { | 93 DomainReliabilityMonitor::~DomainReliabilityMonitor() { |
90 DCHECK(OnIOThread()); | 94 DCHECK(OnIOThread()); |
91 STLDeleteContainerPairSecondPointers( | 95 STLDeleteContainerPairSecondPointers( |
92 contexts_.begin(), contexts_.end()); | 96 contexts_.begin(), contexts_.end()); |
93 } | 97 } |
94 | 98 |
95 void DomainReliabilityMonitor::AddBakedInConfigs() { | 99 void DomainReliabilityMonitor::AddBakedInConfigs() { |
(...skipping 25 matching lines...) Expand all Loading... | |
121 return; | 125 return; |
122 RequestInfo request_info(*request); | 126 RequestInfo request_info(*request); |
123 if (request_info.DefinitelyReachedNetwork()) { | 127 if (request_info.DefinitelyReachedNetwork()) { |
124 OnRequestLegComplete(request_info); | 128 OnRequestLegComplete(request_info); |
125 // A request was just using the network, so now is a good time to run any | 129 // A request was just using the network, so now is a good time to run any |
126 // pending and eligible uploads. | 130 // pending and eligible uploads. |
127 dispatcher_.RunEligibleTasks(); | 131 dispatcher_.RunEligibleTasks(); |
128 } | 132 } |
129 } | 133 } |
130 | 134 |
135 void DomainReliabilityMonitor::ClearBrowsingData( | |
136 DomainReliabilityClearMode mode) { | |
137 DCHECK(OnIOThread()); | |
138 | |
139 was_cleared_ = true; | |
140 cleared_mode_ = mode; | |
141 | |
142 switch (mode) { | |
143 case CLEAR_BEACONS: { | |
144 ContextMap::const_iterator it; | |
145 for (it = contexts_.begin(); it != contexts_.end(); ++it) | |
146 it->second->ClearBeacons(); | |
147 break; | |
148 }; | |
149 case CLEAR_CONTEXTS: | |
150 STLDeleteContainerPairSecondPointers( | |
151 contexts_.begin(), contexts_.end()); | |
152 break; | |
153 default: | |
Mike West
2014/05/08 11:00:40
Nit: If you replace this with 'case MAX_CLEAR_MODE
Deprecated (see juliatuttle)
2014/05/08 15:47:39
Done.
| |
154 NOTREACHED(); | |
155 } | |
156 } | |
157 | |
131 DomainReliabilityContext* DomainReliabilityMonitor::AddContextForTesting( | 158 DomainReliabilityContext* DomainReliabilityMonitor::AddContextForTesting( |
132 scoped_ptr<const DomainReliabilityConfig> config) { | 159 scoped_ptr<const DomainReliabilityConfig> config) { |
133 return AddContext(config.Pass()); | 160 return AddContext(config.Pass()); |
134 } | 161 } |
135 | 162 |
136 DomainReliabilityMonitor::RequestInfo::RequestInfo() {} | 163 DomainReliabilityMonitor::RequestInfo::RequestInfo() {} |
137 | 164 |
138 DomainReliabilityMonitor::RequestInfo::RequestInfo( | 165 DomainReliabilityMonitor::RequestInfo::RequestInfo( |
139 const net::URLRequest& request) | 166 const net::URLRequest& request) |
140 : url(request.url()), | 167 : url(request.url()), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 beacon.status = beacon_status; | 239 beacon.status = beacon_status; |
213 beacon.chrome_error = request.status.error(); | 240 beacon.chrome_error = request.status.error(); |
214 beacon.server_ip = request.socket_address.host(); | 241 beacon.server_ip = request.socket_address.host(); |
215 beacon.http_response_code = request.response_code; | 242 beacon.http_response_code = request.response_code; |
216 beacon.start_time = request.load_timing_info.request_start; | 243 beacon.start_time = request.load_timing_info.request_start; |
217 beacon.elapsed = time_->NowTicks() - beacon.start_time; | 244 beacon.elapsed = time_->NowTicks() - beacon.start_time; |
218 context->AddBeacon(beacon, request.url); | 245 context->AddBeacon(beacon, request.url); |
219 } | 246 } |
220 | 247 |
221 } // namespace domain_reliability | 248 } // namespace domain_reliability |
OLD | NEW |