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 // Creates a Monitor. |InitReportingPref| and |InitURLRequestContext| must be |
| 49 // called (in that order) before any other methods are called. (See those |
| 50 // methods for further threading details.) |
| 51 DomainReliabilityMonitor(const std::string& upload_reporter_string); |
46 DomainReliabilityMonitor(const std::string& upload_reporter_string, | 52 DomainReliabilityMonitor(const std::string& upload_reporter_string, |
47 scoped_ptr<MockableTime> time); | 53 scoped_ptr<MockableTime> time); |
48 ~DomainReliabilityMonitor(); | 54 ~DomainReliabilityMonitor(); |
49 | 55 |
50 // Initializes the Monitor. | 56 // Begins monitoring |reporting_pref_name| in |local_state_pref_service| to |
51 void Init( | 57 // let the user control whether Domain Reliability uploads are sent. (When the |
| 58 // pref is true, they are sent; when it is false, they are discarded.) |
| 59 // |
| 60 // Must be called before |InitURLRequestContext|, on the thread that owns |
| 61 // |local_state_pref_service|. |network_task_runner| must be a task runner |
| 62 // for the thread on which the URLRequestContext passed later lives. |
| 63 void InitReportingPref( |
| 64 PrefService* local_state_pref_service, |
| 65 const char* reporting_pref_name, |
| 66 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 67 network_task_runner); |
| 68 |
| 69 // Initializes the Monitor's URLRequestContextGetter. |
| 70 // |
| 71 // Must be called after |InitReportingPref|, on the thread that owns |
| 72 // |url_request_context|. |task_runner| must be a task runner on that |
| 73 // (current) thread. |
| 74 void InitURLRequestContext( |
52 net::URLRequestContext* url_request_context, | 75 net::URLRequestContext* url_request_context, |
53 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); | 76 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
54 | 77 |
55 // Same, but for unittests where the Getter is readily available. | 78 // Same, but for unittests where the Getter is readily available. |
56 void Init( | 79 void InitURLRequestContext( |
57 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | 80 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); |
58 | 81 |
| 82 // Must be called from the same thread as |InitReportingPref|. |
| 83 void DestroyReportingPref(); |
| 84 |
59 // Populates the monitor with contexts that were configured at compile time. | 85 // Populates the monitor with contexts that were configured at compile time. |
60 void AddBakedInConfigs(); | 86 void AddBakedInConfigs(); |
61 | 87 |
62 // 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 |
63 // examine and possibly log the redirect request. | 89 // examine and possibly log the redirect request. |
64 void OnBeforeRedirect(net::URLRequest* request); | 90 void OnBeforeRedirect(net::URLRequest* request); |
65 | 91 |
66 // Should be called when |request| is complete. Will examine and possibly | 92 // Should be called when |request| is complete. Will examine and possibly |
67 // 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 |
68 // actually started before it was terminated.) | 94 // actually started before it was terminated.) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 }; | 131 }; |
106 | 132 |
107 // 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. |
108 // (The pointer is only valid until the Monitor is destroyed.) | 134 // (The pointer is only valid until the Monitor is destroyed.) |
109 DomainReliabilityContext* AddContext( | 135 DomainReliabilityContext* AddContext( |
110 scoped_ptr<const DomainReliabilityConfig> config); | 136 scoped_ptr<const DomainReliabilityConfig> config); |
111 // Deletes all contexts from |contexts_| and clears the map. | 137 // Deletes all contexts from |contexts_| and clears the map. |
112 void ClearContexts(); | 138 void ClearContexts(); |
113 void OnRequestLegComplete(const RequestInfo& info); | 139 void OnRequestLegComplete(const RequestInfo& info); |
114 | 140 |
| 141 void OnReportingPrefChanged(); |
| 142 |
115 DomainReliabilityContext* GetContextForHost(const std::string& host) const; | 143 DomainReliabilityContext* GetContextForHost(const std::string& host) const; |
116 | 144 |
117 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); | 145 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); |
118 | 146 |
119 scoped_ptr<base::ThreadChecker> thread_checker_; | 147 scoped_ptr<base::ThreadChecker> thread_checker_; |
120 scoped_ptr<MockableTime> time_; | 148 scoped_ptr<MockableTime> time_; |
121 const std::string upload_reporter_string_; | 149 const std::string upload_reporter_string_; |
122 DomainReliabilityScheduler::Params scheduler_params_; | 150 DomainReliabilityScheduler::Params scheduler_params_; |
123 DomainReliabilityDispatcher dispatcher_; | 151 DomainReliabilityDispatcher dispatcher_; |
124 scoped_ptr<DomainReliabilityUploader> uploader_; | 152 scoped_ptr<DomainReliabilityUploader> uploader_; |
125 ContextMap contexts_; | 153 ContextMap contexts_; |
126 | 154 |
| 155 BooleanPrefMember reporting_pref_; |
| 156 bool reporting_pref_initialized_; |
| 157 |
127 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; | 158 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; |
128 | 159 |
129 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); | 160 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); |
130 }; | 161 }; |
131 | 162 |
132 } // namespace domain_reliability | 163 } // namespace domain_reliability |
133 | 164 |
134 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ | 165 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ |
OLD | NEW |