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

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

Issue 615313006: Domain Reliability: Get correct reporting pref once, on startup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix ordering on SetDiscardUploads Created 6 years, 2 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
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/single_thread_task_runner.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/domain_reliability/beacon.h" 15 #include "components/domain_reliability/beacon.h"
16 #include "components/domain_reliability/clear_mode.h" 16 #include "components/domain_reliability/clear_mode.h"
17 #include "components/domain_reliability/config.h" 17 #include "components/domain_reliability/config.h"
18 #include "components/domain_reliability/context.h" 18 #include "components/domain_reliability/context.h"
19 #include "components/domain_reliability/dispatcher.h" 19 #include "components/domain_reliability/dispatcher.h"
20 #include "components/domain_reliability/domain_reliability_export.h" 20 #include "components/domain_reliability/domain_reliability_export.h"
21 #include "components/domain_reliability/scheduler.h" 21 #include "components/domain_reliability/scheduler.h"
22 #include "components/domain_reliability/uploader.h" 22 #include "components/domain_reliability/uploader.h"
23 #include "components/domain_reliability/util.h" 23 #include "components/domain_reliability/util.h"
24 #include "net/base/load_timing_info.h" 24 #include "net/base/load_timing_info.h"
25 #include "net/http/http_response_info.h" 25 #include "net/http/http_response_info.h"
26 #include "net/url_request/url_request_status.h" 26 #include "net/url_request/url_request_status.h"
27 27
28 class PrefService;
29
30 namespace base { 28 namespace base {
31 class SingleThreadTaskRunner;
32 class ThreadChecker; 29 class ThreadChecker;
33 class Value; 30 class Value;
34 } // namespace base 31 } // namespace base
35 32
36 namespace net { 33 namespace net {
37 class URLRequest; 34 class URLRequest;
38 class URLRequestContext; 35 class URLRequestContext;
39 class URLRequestContextGetter; 36 class URLRequestContextGetter;
40 } // namespace net 37 } // namespace net
41 38
42 namespace domain_reliability { 39 namespace domain_reliability {
43 40
44 // The top-level object that measures requests and hands off the measurements 41 // The top-level object that measures requests and hands off the measurements
45 // to the proper |DomainReliabilityContext|. 42 // to the proper |DomainReliabilityContext|.
46 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor { 43 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor {
47 public: 44 public:
48 // Creates a Monitor. |local_state_pref_service| must live on |pref_thread| 45 // Creates a Monitor. |local_state_pref_service| must live on |pref_thread|
49 // (which should be the current thread); |network_thread| is the thread 46 // (which should be the current thread); |network_thread| is the thread
50 // on which requests will actually be monitored and reported. 47 // on which requests will actually be monitored and reported.
51 DomainReliabilityMonitor( 48 DomainReliabilityMonitor(
52 const std::string& upload_reporter_string, 49 const std::string& upload_reporter_string,
53 scoped_refptr<base::SingleThreadTaskRunner> pref_thread, 50 scoped_refptr<base::SingleThreadTaskRunner> pref_thread,
54 scoped_refptr<base::SingleThreadTaskRunner> network_thread, 51 scoped_refptr<base::SingleThreadTaskRunner> network_thread);
55 PrefService* local_state_pref_service,
56 const char* reporting_pref_name);
57 52
58 // Same, but specifies a mock interface for time functions for testing. 53 // Same, but specifies a mock interface for time functions for testing.
59 DomainReliabilityMonitor( 54 DomainReliabilityMonitor(
60 const std::string& upload_reporter_string, 55 const std::string& upload_reporter_string,
61 scoped_refptr<base::SingleThreadTaskRunner> pref_thread, 56 scoped_refptr<base::SingleThreadTaskRunner> pref_thread,
62 scoped_refptr<base::SingleThreadTaskRunner> network_thread, 57 scoped_refptr<base::SingleThreadTaskRunner> network_thread,
63 PrefService* local_state_pref_service,
64 const char* reporting_pref_name,
65 scoped_ptr<MockableTime> time); 58 scoped_ptr<MockableTime> time);
66 59
67 // Must be called from the pref thread if |MoveToNetworkThread| was not 60 // Must be called from the pref thread if |MoveToNetworkThread| was not
68 // called, or from the network thread if it was called. 61 // called, or from the network thread if it was called.
69 ~DomainReliabilityMonitor(); 62 ~DomainReliabilityMonitor();
70 63
71 // Must be called before |InitURLRequestContext| on the same thread on which 64 // Must be called before |InitURLRequestContext| on the same thread on which
72 // the Monitor was constructed. Moves (most of) the Monitor to the network 65 // the Monitor was constructed. Moves (most of) the Monitor to the network
73 // thread passed in the constructor. 66 // thread passed in the constructor.
74 void MoveToNetworkThread(); 67 void MoveToNetworkThread();
75 68
76 // Must be called from the pref thread before the Monitor is destructed if 69 // All public methods below this point must be called on the network thread
77 // |MoveToNetworkThread| was called. 70 // after |MoveToNetworkThread| is called on the pref thread.
78 void DestroyReportingPref();
79
80 // All public methods below this point must be called on the network thread:
81 71
82 // Initializes the Monitor's URLRequestContextGetter. 72 // Initializes the Monitor's URLRequestContextGetter.
83 // 73 //
84 // Must be called on the network thread, after |MoveToNetworkThread|. 74 // Must be called on the network thread, after |MoveToNetworkThread|.
85 void InitURLRequestContext(net::URLRequestContext* url_request_context); 75 void InitURLRequestContext(net::URLRequestContext* url_request_context);
86 76
87 // Same, but for unittests where the Getter is readily available. 77 // Same, but for unittests where the Getter is readily available.
88 void InitURLRequestContext( 78 void InitURLRequestContext(
89 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); 79 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter);
90 80
91 // Populates the monitor with contexts that were configured at compile time. 81 // Populates the monitor with contexts that were configured at compile time.
92 void AddBakedInConfigs(); 82 void AddBakedInConfigs();
93 83
84 // Sets whether the uploader will discard uploads. Must be called after
85 // |InitURLRequestContext|.
davidben 2014/10/03 00:12:25 It also must be called before OnBeforeRedirect and
Deprecated (see juliatuttle) 2014/10/03 00:42:08 Done.
86 void SetDiscardUploads(bool discard_uploads);
87
94 // Should be called when |request| is about to follow a redirect. Will 88 // Should be called when |request| is about to follow a redirect. Will
95 // examine and possibly log the redirect request. 89 // examine and possibly log the redirect request.
96 void OnBeforeRedirect(net::URLRequest* request); 90 void OnBeforeRedirect(net::URLRequest* request);
97 91
98 // Should be called when |request| is complete. Will examine and possibly 92 // Should be called when |request| is complete. Will examine and possibly
99 // log the (final) request. (|started| should be true if the request was 93 // log the (final) request. (|started| should be true if the request was
100 // actually started before it was terminated.) 94 // actually started before it was terminated.)
101 void OnCompleted(net::URLRequest* request, bool started); 95 void OnCompleted(net::URLRequest* request, bool started);
102 96
103 // Called to remove browsing data. With CLEAR_BEACONS, leaves contexts in 97 // Called to remove browsing data. With CLEAR_BEACONS, leaves contexts in
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // Creates a context, adds it to the monitor, and returns a pointer to it. 133 // Creates a context, adds it to the monitor, and returns a pointer to it.
140 // (The pointer is only valid until the Monitor is destroyed.) 134 // (The pointer is only valid until the Monitor is destroyed.)
141 DomainReliabilityContext* AddContext( 135 DomainReliabilityContext* AddContext(
142 scoped_ptr<const DomainReliabilityConfig> config); 136 scoped_ptr<const DomainReliabilityConfig> config);
143 // Deletes all contexts from |contexts_| and clears the map. 137 // Deletes all contexts from |contexts_| and clears the map.
144 void ClearContexts(); 138 void ClearContexts();
145 void OnRequestLegComplete(const RequestInfo& info); 139 void OnRequestLegComplete(const RequestInfo& info);
146 140
147 DomainReliabilityContext* GetContextForHost(const std::string& host) const; 141 DomainReliabilityContext* GetContextForHost(const std::string& host) const;
148 142
149 void InitReportingPref(
150 PrefService* local_state_pref_service,
151 const char* reporting_pref_name);
152 void OnReportingPrefChanged();
153
154 bool OnPrefThread() const { 143 bool OnPrefThread() const {
155 return pref_task_runner_->BelongsToCurrentThread(); 144 return pref_task_runner_->BelongsToCurrentThread();
156 } 145 }
157 bool OnNetworkThread() const { 146 bool OnNetworkThread() const {
158 return network_task_runner_->BelongsToCurrentThread(); 147 return network_task_runner_->BelongsToCurrentThread();
159 } 148 }
160 149
161 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); 150 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr();
162 151
163 scoped_ptr<MockableTime> time_; 152 scoped_ptr<MockableTime> time_;
164 const std::string upload_reporter_string_; 153 const std::string upload_reporter_string_;
165 DomainReliabilityScheduler::Params scheduler_params_; 154 DomainReliabilityScheduler::Params scheduler_params_;
166 DomainReliabilityDispatcher dispatcher_; 155 DomainReliabilityDispatcher dispatcher_;
167 scoped_ptr<DomainReliabilityUploader> uploader_; 156 scoped_ptr<DomainReliabilityUploader> uploader_;
168 ContextMap contexts_; 157 ContextMap contexts_;
169 158
170 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; 159 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_;
171 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 160 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
172 161
173 BooleanPrefMember reporting_pref_;
174 bool moved_to_network_thread_; 162 bool moved_to_network_thread_;
163 bool discard_uploads_set_;
175 164
176 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; 165 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_;
177 166
178 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); 167 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor);
179 }; 168 };
180 169
181 } // namespace domain_reliability 170 } // namespace domain_reliability
182 171
183 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ 172 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698