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 #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 DomainReliabilityMonitor(const std::string& upload_reporter_string); |
46 DomainReliabilityMonitor(const std::string& upload_reporter_string, | 49 DomainReliabilityMonitor(const std::string& upload_reporter_string, |
47 scoped_ptr<MockableTime> time); | 50 scoped_ptr<MockableTime> time); |
48 ~DomainReliabilityMonitor(); | 51 ~DomainReliabilityMonitor(); |
49 | 52 |
50 // Initializes the Monitor. | 53 // Initializes the Monitor's pref member that monitors the reporting pref. |
davidben
2014/08/20 21:49:03
Could you document the threading requirements of a
Deprecated (see juliatuttle)
2014/08/21 18:35:28
Done.
| |
51 void Init( | 54 void InitReportingPref( |
55 PrefService* local_state_pref_service, | |
56 const char* reporting_pref_name, | |
57 const scoped_refptr<base::SingleThreadTaskRunner>& | |
58 network_message_loop_proxy); | |
davidben
2014/08/20 21:49:03
s/message_loop_proxy/task_runner/?
Deprecated (see juliatuttle)
2014/08/21 18:35:28
Done.
| |
59 | |
60 // Initializes the Monitor's URLRequestContextGetter. | |
61 void InitURLRequestContext( | |
52 net::URLRequestContext* url_request_context, | 62 net::URLRequestContext* url_request_context, |
53 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 63 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
54 | 64 |
55 // Same, but for unittests where the Getter is readily available. | 65 // Same, but for unittests where the Getter is readily available. |
56 void Init( | 66 void InitURLRequestContext( |
57 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | 67 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); |
58 | 68 |
59 // Populates the monitor with contexts that were configured at compile time. | 69 // Populates the monitor with contexts that were configured at compile time. |
60 void AddBakedInConfigs(); | 70 void AddBakedInConfigs(); |
61 | 71 |
62 // Should be called when |request| is about to follow a redirect. Will | 72 // Should be called when |request| is about to follow a redirect. Will |
63 // examine and possibly log the redirect request. | 73 // examine and possibly log the redirect request. |
64 void OnBeforeRedirect(net::URLRequest* request); | 74 void OnBeforeRedirect(net::URLRequest* request); |
65 | 75 |
66 // Should be called when |request| is complete. Will examine and possibly | 76 // Should be called when |request| is complete. Will examine and possibly |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 }; | 115 }; |
106 | 116 |
107 // Creates a context, adds it to the monitor, and returns a pointer to it. | 117 // 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.) | 118 // (The pointer is only valid until the Monitor is destroyed.) |
109 DomainReliabilityContext* AddContext( | 119 DomainReliabilityContext* AddContext( |
110 scoped_ptr<const DomainReliabilityConfig> config); | 120 scoped_ptr<const DomainReliabilityConfig> config); |
111 // Deletes all contexts from |contexts_| and clears the map. | 121 // Deletes all contexts from |contexts_| and clears the map. |
112 void ClearContexts(); | 122 void ClearContexts(); |
113 void OnRequestLegComplete(const RequestInfo& info); | 123 void OnRequestLegComplete(const RequestInfo& info); |
114 | 124 |
125 void OnReportingPrefChanged(); | |
126 | |
115 DomainReliabilityContext* GetContextForHost(const std::string& host) const; | 127 DomainReliabilityContext* GetContextForHost(const std::string& host) const; |
116 | 128 |
117 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); | 129 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); |
118 | 130 |
119 scoped_ptr<base::ThreadChecker> thread_checker_; | 131 scoped_ptr<base::ThreadChecker> thread_checker_; |
120 scoped_ptr<MockableTime> time_; | 132 scoped_ptr<MockableTime> time_; |
121 const std::string upload_reporter_string_; | 133 const std::string upload_reporter_string_; |
122 DomainReliabilityScheduler::Params scheduler_params_; | 134 DomainReliabilityScheduler::Params scheduler_params_; |
123 DomainReliabilityDispatcher dispatcher_; | 135 DomainReliabilityDispatcher dispatcher_; |
124 scoped_ptr<DomainReliabilityUploader> uploader_; | 136 scoped_ptr<DomainReliabilityUploader> uploader_; |
125 ContextMap contexts_; | 137 ContextMap contexts_; |
126 | 138 |
139 const char* reporting_pref_name_; | |
140 BooleanPrefMember reporting_pref_; | |
141 bool reporting_pref_initialized_; | |
142 | |
127 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; | 143 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; |
128 | 144 |
129 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); | 145 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); |
130 }; | 146 }; |
131 | 147 |
132 } // namespace domain_reliability | 148 } // namespace domain_reliability |
133 | 149 |
134 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ | 150 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ |
OLD | NEW |