| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "components/domain_reliability/baked_in_configs.h" | 12 #include "components/domain_reliability/baked_in_configs.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
| 17 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 bool OnIOThread() { | 21 bool OnIOThread() { |
| 22 return content::BrowserThread::CurrentlyOn(content::BrowserThread::IO); | 22 return content::BrowserThread::CurrentlyOn(content::BrowserThread::IO); |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Shamelessly stolen from net/tools/get_server_time/get_server_time.cc. | |
| 26 // TODO(ttuttle): Merge them, if possible. | |
| 27 class TrivialURLRequestContextGetter : public net::URLRequestContextGetter { | |
| 28 public: | |
| 29 TrivialURLRequestContextGetter( | |
| 30 net::URLRequestContext* context, | |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner) | |
| 32 : context_(context), | |
| 33 main_task_runner_(main_task_runner) {} | |
| 34 | |
| 35 // net::URLRequestContextGetter implementation: | |
| 36 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE { | |
| 37 return context_; | |
| 38 } | |
| 39 | |
| 40 virtual scoped_refptr<base::SingleThreadTaskRunner> | |
| 41 GetNetworkTaskRunner() const OVERRIDE { | |
| 42 return main_task_runner_; | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 virtual ~TrivialURLRequestContextGetter() {} | |
| 47 | |
| 48 net::URLRequestContext* context_; | |
| 49 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 50 }; | |
| 51 | |
| 52 } // namespace | 25 } // namespace |
| 53 | 26 |
| 54 namespace domain_reliability { | 27 namespace domain_reliability { |
| 55 | 28 |
| 56 DomainReliabilityMonitor::DomainReliabilityMonitor( | 29 DomainReliabilityMonitor::DomainReliabilityMonitor( |
| 57 net::URLRequestContext* url_request_context) | 30 net::URLRequestContext* url_request_context) |
| 58 : time_(new ActualTime()), | 31 : time_(new ActualTime()), |
| 59 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( | 32 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( |
| 60 new TrivialURLRequestContextGetter( | 33 new net::TrivialURLRequestContextGetter( |
| 61 url_request_context, | 34 url_request_context, |
| 62 content::BrowserThread::GetMessageLoopProxyForThread( | 35 content::BrowserThread::GetMessageLoopProxyForThread( |
| 63 content::BrowserThread::IO)))), | 36 content::BrowserThread::IO)))), |
| 64 scheduler_params_( | 37 scheduler_params_( |
| 65 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), | 38 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), |
| 66 dispatcher_(time_.get()), | 39 dispatcher_(time_.get()), |
| 67 uploader_( | 40 uploader_( |
| 68 DomainReliabilityUploader::Create(url_request_context_getter_)) { | 41 DomainReliabilityUploader::Create(url_request_context_getter_)) { |
| 69 DCHECK(OnIOThread()); | 42 DCHECK(OnIOThread()); |
| 70 } | 43 } |
| 71 | 44 |
| 72 DomainReliabilityMonitor::DomainReliabilityMonitor( | 45 DomainReliabilityMonitor::DomainReliabilityMonitor( |
| 73 net::URLRequestContext* url_request_context, | 46 net::URLRequestContext* url_request_context, |
| 74 scoped_ptr<MockableTime> time) | 47 scoped_ptr<MockableTime> time) |
| 75 : time_(time.Pass()), | 48 : time_(time.Pass()), |
| 76 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( | 49 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( |
| 77 new TrivialURLRequestContextGetter( | 50 new net::TrivialURLRequestContextGetter( |
| 78 url_request_context, | 51 url_request_context, |
| 79 content::BrowserThread::GetMessageLoopProxyForThread( | 52 content::BrowserThread::GetMessageLoopProxyForThread( |
| 80 content::BrowserThread::IO)))), | 53 content::BrowserThread::IO)))), |
| 81 scheduler_params_( | 54 scheduler_params_( |
| 82 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), | 55 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), |
| 83 dispatcher_(time_.get()), | 56 dispatcher_(time_.get()), |
| 84 uploader_( | 57 uploader_( |
| 85 DomainReliabilityUploader::Create(url_request_context_getter_)) { | 58 DomainReliabilityUploader::Create(url_request_context_getter_)) { |
| 86 DCHECK(OnIOThread()); | 59 DCHECK(OnIOThread()); |
| 87 } | 60 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 beacon.status = beacon_status; | 185 beacon.status = beacon_status; |
| 213 beacon.chrome_error = request.status.error(); | 186 beacon.chrome_error = request.status.error(); |
| 214 beacon.server_ip = request.socket_address.host(); | 187 beacon.server_ip = request.socket_address.host(); |
| 215 beacon.http_response_code = request.response_code; | 188 beacon.http_response_code = request.response_code; |
| 216 beacon.start_time = request.load_timing_info.request_start; | 189 beacon.start_time = request.load_timing_info.request_start; |
| 217 beacon.elapsed = time_->NowTicks() - beacon.start_time; | 190 beacon.elapsed = time_->NowTicks() - beacon.start_time; |
| 218 context->AddBeacon(beacon, request.url); | 191 context->AddBeacon(beacon, request.url); |
| 219 } | 192 } |
| 220 | 193 |
| 221 } // namespace domain_reliability | 194 } // namespace domain_reliability |
| OLD | NEW |