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

Side by Side Diff: components/domain_reliability/monitor.cc

Issue 292063002: Create a TrivialURLRequestContextGetter to shim an existing URLRequestContext. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd up to r272911 Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/tools/get_server_time/get_server_time.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 #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/http/http_response_headers.h" 15 #include "net/http/http_response_headers.h"
16 #include "net/url_request/url_request.h" 16 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_context.h" 17 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
19 19
20 namespace { 20 namespace {
21 21
22 bool OnIOThread() { 22 bool OnIOThread() {
23 return content::BrowserThread::CurrentlyOn(content::BrowserThread::IO); 23 return content::BrowserThread::CurrentlyOn(content::BrowserThread::IO);
24 } 24 }
25 25
26 // Shamelessly stolen from net/tools/get_server_time/get_server_time.cc.
27 // TODO(ttuttle): Merge them, if possible.
28 class TrivialURLRequestContextGetter : public net::URLRequestContextGetter {
29 public:
30 TrivialURLRequestContextGetter(
31 net::URLRequestContext* context,
32 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
33 : context_(context),
34 main_task_runner_(main_task_runner) {}
35
36 // net::URLRequestContextGetter implementation:
37 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE {
38 return context_;
39 }
40
41 virtual scoped_refptr<base::SingleThreadTaskRunner>
42 GetNetworkTaskRunner() const OVERRIDE {
43 return main_task_runner_;
44 }
45
46 private:
47 virtual ~TrivialURLRequestContextGetter() {}
48
49 net::URLRequestContext* context_;
50 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
51 };
52
53 } // namespace 26 } // namespace
54 27
55 namespace domain_reliability { 28 namespace domain_reliability {
56 29
57 DomainReliabilityMonitor::DomainReliabilityMonitor( 30 DomainReliabilityMonitor::DomainReliabilityMonitor(
58 net::URLRequestContext* url_request_context, 31 net::URLRequestContext* url_request_context,
59 const std::string& upload_reporter_string) 32 const std::string& upload_reporter_string)
60 : time_(new ActualTime()), 33 : time_(new ActualTime()),
61 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( 34 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>(
62 new TrivialURLRequestContextGetter( 35 new net::TrivialURLRequestContextGetter(
63 url_request_context, 36 url_request_context,
64 content::BrowserThread::GetMessageLoopProxyForThread( 37 content::BrowserThread::GetMessageLoopProxyForThread(
65 content::BrowserThread::IO)))), 38 content::BrowserThread::IO)))),
66 upload_reporter_string_(upload_reporter_string), 39 upload_reporter_string_(upload_reporter_string),
67 scheduler_params_( 40 scheduler_params_(
68 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), 41 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()),
69 dispatcher_(time_.get()), 42 dispatcher_(time_.get()),
70 uploader_( 43 uploader_(
71 DomainReliabilityUploader::Create(url_request_context_getter_)), 44 DomainReliabilityUploader::Create(url_request_context_getter_)),
72 was_cleared_(false), 45 was_cleared_(false),
73 cleared_mode_(MAX_CLEAR_MODE) { 46 cleared_mode_(MAX_CLEAR_MODE) {
74 DCHECK(OnIOThread()); 47 DCHECK(OnIOThread());
75 } 48 }
76 49
77 DomainReliabilityMonitor::DomainReliabilityMonitor( 50 DomainReliabilityMonitor::DomainReliabilityMonitor(
78 net::URLRequestContext* url_request_context, 51 net::URLRequestContext* url_request_context,
79 const std::string& upload_reporter_string, 52 const std::string& upload_reporter_string,
80 scoped_ptr<MockableTime> time) 53 scoped_ptr<MockableTime> time)
81 : time_(time.Pass()), 54 : time_(time.Pass()),
82 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>( 55 url_request_context_getter_(scoped_refptr<net::URLRequestContextGetter>(
83 new TrivialURLRequestContextGetter( 56 new net::TrivialURLRequestContextGetter(
84 url_request_context, 57 url_request_context,
85 content::BrowserThread::GetMessageLoopProxyForThread( 58 content::BrowserThread::GetMessageLoopProxyForThread(
86 content::BrowserThread::IO)))), 59 content::BrowserThread::IO)))),
87 upload_reporter_string_(upload_reporter_string), 60 upload_reporter_string_(upload_reporter_string),
88 scheduler_params_( 61 scheduler_params_(
89 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()), 62 DomainReliabilityScheduler::Params::GetFromFieldTrialsOrDefaults()),
90 dispatcher_(time_.get()), 63 dispatcher_(time_.get()),
91 uploader_( 64 uploader_(
92 DomainReliabilityUploader::Create(url_request_context_getter_)), 65 DomainReliabilityUploader::Create(url_request_context_getter_)),
93 was_cleared_(false), 66 was_cleared_(false),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 beacon.server_ip = request.response_info.socket_address.host(); 222 beacon.server_ip = request.response_info.socket_address.host();
250 else 223 else
251 beacon.server_ip.clear(); 224 beacon.server_ip.clear();
252 beacon.http_response_code = response_code; 225 beacon.http_response_code = response_code;
253 beacon.start_time = request.load_timing_info.request_start; 226 beacon.start_time = request.load_timing_info.request_start;
254 beacon.elapsed = time_->NowTicks() - beacon.start_time; 227 beacon.elapsed = time_->NowTicks() - beacon.start_time;
255 context_it->second->OnBeacon(request.url, beacon); 228 context_it->second->OnBeacon(request.url, beacon);
256 } 229 }
257 230
258 } // namespace domain_reliability 231 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « no previous file | net/tools/get_server_time/get_server_time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698