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

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: resolve conflict 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|.
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. Must be called after
90 // |SetDiscardUploads|.
96 void OnBeforeRedirect(net::URLRequest* request); 91 void OnBeforeRedirect(net::URLRequest* request);
97 92
98 // Should be called when |request| is complete. Will examine and possibly 93 // Should be called when |request| is complete. Will examine and possibly
99 // log the (final) request. (|started| should be true if the request was 94 // log the (final) request. |started| should be true if the request was
100 // actually started before it was terminated.) 95 // actually started before it was terminated. Must be called after
96 // |SetDiscardUploads|.
101 void OnCompleted(net::URLRequest* request, bool started); 97 void OnCompleted(net::URLRequest* request, bool started);
102 98
103 // Called to remove browsing data. With CLEAR_BEACONS, leaves contexts in 99 // Called to remove browsing data. With CLEAR_BEACONS, leaves contexts in
104 // place but clears beacons (which betray browsing history); with 100 // place but clears beacons (which betray browsing history); with
105 // CLEAR_CONTEXTS, removes all contexts (which can behave as cookies). 101 // CLEAR_CONTEXTS, removes all contexts (which can behave as cookies).
106 void ClearBrowsingData(DomainReliabilityClearMode mode); 102 void ClearBrowsingData(DomainReliabilityClearMode mode);
107 103
108 // Gets a Value containing data that can be formatted into a web page for 104 // Gets a Value containing data that can be formatted into a web page for
109 // debugging purposes. 105 // debugging purposes.
110 scoped_ptr<base::Value> GetWebUIData() const; 106 scoped_ptr<base::Value> GetWebUIData() const;
(...skipping 28 matching lines...) Expand all
139 // Creates a context, adds it to the monitor, and returns a pointer to it. 135 // 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.) 136 // (The pointer is only valid until the Monitor is destroyed.)
141 DomainReliabilityContext* AddContext( 137 DomainReliabilityContext* AddContext(
142 scoped_ptr<const DomainReliabilityConfig> config); 138 scoped_ptr<const DomainReliabilityConfig> config);
143 // Deletes all contexts from |contexts_| and clears the map. 139 // Deletes all contexts from |contexts_| and clears the map.
144 void ClearContexts(); 140 void ClearContexts();
145 void OnRequestLegComplete(const RequestInfo& info); 141 void OnRequestLegComplete(const RequestInfo& info);
146 142
147 DomainReliabilityContext* GetContextForHost(const std::string& host) const; 143 DomainReliabilityContext* GetContextForHost(const std::string& host) const;
148 144
149 void InitReportingPref(
150 PrefService* local_state_pref_service,
151 const char* reporting_pref_name);
152 void OnReportingPrefChanged();
153
154 bool OnPrefThread() const { 145 bool OnPrefThread() const {
155 return pref_task_runner_->BelongsToCurrentThread(); 146 return pref_task_runner_->BelongsToCurrentThread();
156 } 147 }
157 bool OnNetworkThread() const { 148 bool OnNetworkThread() const {
158 return network_task_runner_->BelongsToCurrentThread(); 149 return network_task_runner_->BelongsToCurrentThread();
159 } 150 }
160 151
161 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); 152 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr();
162 153
163 scoped_ptr<MockableTime> time_; 154 scoped_ptr<MockableTime> time_;
164 const std::string upload_reporter_string_; 155 const std::string upload_reporter_string_;
165 DomainReliabilityScheduler::Params scheduler_params_; 156 DomainReliabilityScheduler::Params scheduler_params_;
166 DomainReliabilityDispatcher dispatcher_; 157 DomainReliabilityDispatcher dispatcher_;
167 scoped_ptr<DomainReliabilityUploader> uploader_; 158 scoped_ptr<DomainReliabilityUploader> uploader_;
168 ContextMap contexts_; 159 ContextMap contexts_;
169 160
170 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; 161 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_;
171 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 162 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
172 163
173 BooleanPrefMember reporting_pref_;
174 bool moved_to_network_thread_; 164 bool moved_to_network_thread_;
165 bool discard_uploads_set_;
175 166
176 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; 167 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_;
177 168
178 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); 169 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor);
179 }; 170 };
180 171
181 } // namespace domain_reliability 172 } // namespace domain_reliability
182 173
183 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ 174 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl_io_data.cc ('k') | components/domain_reliability/monitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698