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

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

Issue 491753003: Domain Reliability: Don't upload when metrics reporting is off. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make sure constructor and destructor are on correct threads. Created 6 years, 4 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
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 COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ 5 #ifndef COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
6 #define COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ 6 #define COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/prefs/pref_member.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "components/domain_reliability/beacon.h" 15 #include "components/domain_reliability/beacon.h"
15 #include "components/domain_reliability/clear_mode.h" 16 #include "components/domain_reliability/clear_mode.h"
16 #include "components/domain_reliability/config.h" 17 #include "components/domain_reliability/config.h"
17 #include "components/domain_reliability/context.h" 18 #include "components/domain_reliability/context.h"
18 #include "components/domain_reliability/dispatcher.h" 19 #include "components/domain_reliability/dispatcher.h"
19 #include "components/domain_reliability/domain_reliability_export.h" 20 #include "components/domain_reliability/domain_reliability_export.h"
20 #include "components/domain_reliability/scheduler.h" 21 #include "components/domain_reliability/scheduler.h"
21 #include "components/domain_reliability/uploader.h" 22 #include "components/domain_reliability/uploader.h"
22 #include "components/domain_reliability/util.h" 23 #include "components/domain_reliability/util.h"
23 #include "net/base/load_timing_info.h" 24 #include "net/base/load_timing_info.h"
24 #include "net/http/http_response_info.h" 25 #include "net/http/http_response_info.h"
25 #include "net/url_request/url_request_status.h" 26 #include "net/url_request/url_request_status.h"
26 27
28 class PrefService;
29
27 namespace base { 30 namespace base {
28 class SingleThreadTaskRunner; 31 class SingleThreadTaskRunner;
29 class ThreadChecker; 32 class ThreadChecker;
30 class Value; 33 class Value;
31 } // namespace base 34 } // namespace base
32 35
33 namespace net { 36 namespace net {
34 class URLRequest; 37 class URLRequest;
35 class URLRequestContext; 38 class URLRequestContext;
36 class URLRequestContextGetter; 39 class URLRequestContextGetter;
37 } // namespace net 40 } // namespace net
38 41
39 namespace domain_reliability { 42 namespace domain_reliability {
40 43
41 // The top-level object that measures requests and hands off the measurements 44 // The top-level object that measures requests and hands off the measurements
42 // to the proper |DomainReliabilityContext|. 45 // to the proper |DomainReliabilityContext|.
43 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor { 46 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor {
44 public: 47 public:
45 explicit DomainReliabilityMonitor(const std::string& upload_reporter_string); 48 // Creates a Monitor. |local_state_pref_service| must live on |pref_thread|
46 DomainReliabilityMonitor(const std::string& upload_reporter_string, 49 // (which should be the current thread); |network_thread| is the thread
47 scoped_ptr<MockableTime> time); 50 // on which requests will actually be monitored and reported.
51 DomainReliabilityMonitor(
52 const std::string& upload_reporter_string,
53 scoped_refptr<base::SingleThreadTaskRunner> pref_thread,
54 scoped_refptr<base::SingleThreadTaskRunner> network_thread,
55 PrefService* local_state_pref_service,
56 const char* reporting_pref_name);
57
58 // Same, but specifies a mock interface for time functions for testing.
59 DomainReliabilityMonitor(
60 const std::string& upload_reporter_string,
61 scoped_refptr<base::SingleThreadTaskRunner> pref_thread,
62 scoped_refptr<base::SingleThreadTaskRunner> network_thread,
63 PrefService* local_state_pref_service,
64 const char* reporting_pref_name,
65 scoped_ptr<MockableTime> time);
66
48 ~DomainReliabilityMonitor(); 67 ~DomainReliabilityMonitor();
49 68
50 // Initializes the Monitor. 69 // Must be called before |InitURLRequestContext| on the same thread on which
51 void Init( 70 // the Monitor was constructed. Moves (most of) the Monitor to the network
52 net::URLRequestContext* url_request_context, 71 // thread passed in the constructor.
53 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); 72 void MoveToNetworkThread();
73
74 // Must be called from the pref thread before the Monitor is destructed.
75 void DestroyReportingPref();
76
77 // All public methods below this point must be called on the network thread:
78
79 // Initializes the Monitor's URLRequestContextGetter.
80 //
81 // Must be called on the network thread, after |MoveToNetworkThread|.
82 void InitURLRequestContext(net::URLRequestContext* url_request_context);
54 83
55 // Same, but for unittests where the Getter is readily available. 84 // Same, but for unittests where the Getter is readily available.
56 void Init( 85 void InitURLRequestContext(
57 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); 86 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
58 87
59 // Populates the monitor with contexts that were configured at compile time. 88 // Populates the monitor with contexts that were configured at compile time.
60 void AddBakedInConfigs(); 89 void AddBakedInConfigs();
61 90
62 // Should be called when |request| is about to follow a redirect. Will 91 // Should be called when |request| is about to follow a redirect. Will
63 // examine and possibly log the redirect request. 92 // examine and possibly log the redirect request.
64 void OnBeforeRedirect(net::URLRequest* request); 93 void OnBeforeRedirect(net::URLRequest* request);
65 94
66 // Should be called when |request| is complete. Will examine and possibly 95 // Should be called when |request| is complete. Will examine and possibly
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Creates a context, adds it to the monitor, and returns a pointer to it. 136 // Creates a context, adds it to the monitor, and returns a pointer to it.
108 // (The pointer is only valid until the Monitor is destroyed.) 137 // (The pointer is only valid until the Monitor is destroyed.)
109 DomainReliabilityContext* AddContext( 138 DomainReliabilityContext* AddContext(
110 scoped_ptr<const DomainReliabilityConfig> config); 139 scoped_ptr<const DomainReliabilityConfig> config);
111 // Deletes all contexts from |contexts_| and clears the map. 140 // Deletes all contexts from |contexts_| and clears the map.
112 void ClearContexts(); 141 void ClearContexts();
113 void OnRequestLegComplete(const RequestInfo& info); 142 void OnRequestLegComplete(const RequestInfo& info);
114 143
115 DomainReliabilityContext* GetContextForHost(const std::string& host) const; 144 DomainReliabilityContext* GetContextForHost(const std::string& host) const;
116 145
146 void InitReportingPref(
147 PrefService* local_state_pref_service,
148 const char* reporting_pref_name);
149 void OnReportingPrefChanged();
150
151 bool OnPrefThread() const {
152 return pref_task_runner_->BelongsToCurrentThread();
153 }
154 bool OnNetworkThread() const {
155 return network_task_runner_->BelongsToCurrentThread();
156 }
157
117 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); 158 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr();
118 159
119 scoped_ptr<base::ThreadChecker> thread_checker_;
120 scoped_ptr<MockableTime> time_; 160 scoped_ptr<MockableTime> time_;
121 const std::string upload_reporter_string_; 161 const std::string upload_reporter_string_;
122 DomainReliabilityScheduler::Params scheduler_params_; 162 DomainReliabilityScheduler::Params scheduler_params_;
123 DomainReliabilityDispatcher dispatcher_; 163 DomainReliabilityDispatcher dispatcher_;
124 scoped_ptr<DomainReliabilityUploader> uploader_; 164 scoped_ptr<DomainReliabilityUploader> uploader_;
125 ContextMap contexts_; 165 ContextMap contexts_;
126 166
167 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_;
168 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
169
170 BooleanPrefMember reporting_pref_;
171 bool moved_to_network_thread_;
172
127 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; 173 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_;
128 174
129 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); 175 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor);
130 }; 176 };
131 177
132 } // namespace domain_reliability 178 } // namespace domain_reliability
133 179
134 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ 180 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698