| 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/single_thread_task_runner.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/base/network_change_notifier.h" |
| 25 #include "net/http/http_response_info.h" | 26 #include "net/http/http_response_info.h" |
| 26 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 27 | 28 |
| 28 namespace base { | 29 namespace base { |
| 29 class ThreadChecker; | 30 class ThreadChecker; |
| 30 class Value; | 31 class Value; |
| 31 } // namespace base | 32 } // namespace base |
| 32 | 33 |
| 33 namespace net { | 34 namespace net { |
| 34 class URLRequest; | 35 class URLRequest; |
| 35 class URLRequestContext; | 36 class URLRequestContext; |
| 36 class URLRequestContextGetter; | 37 class URLRequestContextGetter; |
| 37 } // namespace net | 38 } // namespace net |
| 38 | 39 |
| 39 namespace domain_reliability { | 40 namespace domain_reliability { |
| 40 | 41 |
| 41 // The top-level object that measures requests and hands off the measurements | 42 // The top-level object that measures requests and hands off the measurements |
| 42 // to the proper |DomainReliabilityContext|. | 43 // to the proper |DomainReliabilityContext|. |
| 43 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor { | 44 class DOMAIN_RELIABILITY_EXPORT DomainReliabilityMonitor |
| 45 : public net::NetworkChangeNotifier::NetworkChangeObserver { |
| 44 public: | 46 public: |
| 45 // Creates a Monitor. |local_state_pref_service| must live on |pref_thread| | 47 // Creates a Monitor. |local_state_pref_service| must live on |pref_thread| |
| 46 // (which should be the current thread); |network_thread| is the thread | 48 // (which should be the current thread); |network_thread| is the thread |
| 47 // on which requests will actually be monitored and reported. | 49 // on which requests will actually be monitored and reported. |
| 48 DomainReliabilityMonitor( | 50 DomainReliabilityMonitor( |
| 49 const std::string& upload_reporter_string, | 51 const std::string& upload_reporter_string, |
| 50 scoped_refptr<base::SingleThreadTaskRunner> pref_thread, | 52 scoped_refptr<base::SingleThreadTaskRunner> pref_thread, |
| 51 scoped_refptr<base::SingleThreadTaskRunner> network_thread); | 53 scoped_refptr<base::SingleThreadTaskRunner> network_thread); |
| 52 | 54 |
| 53 // Same, but specifies a mock interface for time functions for testing. | 55 // Same, but specifies a mock interface for time functions for testing. |
| 54 DomainReliabilityMonitor( | 56 DomainReliabilityMonitor( |
| 55 const std::string& upload_reporter_string, | 57 const std::string& upload_reporter_string, |
| 56 scoped_refptr<base::SingleThreadTaskRunner> pref_thread, | 58 scoped_refptr<base::SingleThreadTaskRunner> pref_thread, |
| 57 scoped_refptr<base::SingleThreadTaskRunner> network_thread, | 59 scoped_refptr<base::SingleThreadTaskRunner> network_thread, |
| 58 scoped_ptr<MockableTime> time); | 60 scoped_ptr<MockableTime> time); |
| 59 | 61 |
| 60 // Must be called from the pref thread if |MoveToNetworkThread| was not | 62 // Must be called from the pref thread if |MoveToNetworkThread| was not |
| 61 // called, or from the network thread if it was called. | 63 // called, or from the network thread if it was called. |
| 62 ~DomainReliabilityMonitor(); | 64 virtual ~DomainReliabilityMonitor(); |
| 63 | 65 |
| 64 // Must be called before |InitURLRequestContext| on the same thread on which | 66 // Must be called before |InitURLRequestContext| on the same thread on which |
| 65 // the Monitor was constructed. Moves (most of) the Monitor to the network | 67 // the Monitor was constructed. Moves (most of) the Monitor to the network |
| 66 // thread passed in the constructor. | 68 // thread passed in the constructor. |
| 67 void MoveToNetworkThread(); | 69 void MoveToNetworkThread(); |
| 68 | 70 |
| 69 // All public methods below this point must be called on the network thread | 71 // All public methods below this point must be called on the network thread |
| 70 // after |MoveToNetworkThread| is called on the pref thread. | 72 // after |MoveToNetworkThread| is called on the pref thread. |
| 71 | 73 |
| 72 // Initializes the Monitor's URLRequestContextGetter. | 74 // Initializes the Monitor's URLRequestContextGetter. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 89 // examine and possibly log the redirect request. Must be called after | 91 // examine and possibly log the redirect request. Must be called after |
| 90 // |SetDiscardUploads|. | 92 // |SetDiscardUploads|. |
| 91 void OnBeforeRedirect(net::URLRequest* request); | 93 void OnBeforeRedirect(net::URLRequest* request); |
| 92 | 94 |
| 93 // Should be called when |request| is complete. Will examine and possibly | 95 // Should be called when |request| is complete. Will examine and possibly |
| 94 // log the (final) request. |started| should be true if the request was | 96 // log the (final) request. |started| should be true if the request was |
| 95 // actually started before it was terminated. Must be called after | 97 // actually started before it was terminated. Must be called after |
| 96 // |SetDiscardUploads|. | 98 // |SetDiscardUploads|. |
| 97 void OnCompleted(net::URLRequest* request, bool started); | 99 void OnCompleted(net::URLRequest* request, bool started); |
| 98 | 100 |
| 101 // net::NetworkChangeNotifier::NetworkChangeObserver implementation: |
| 102 virtual void OnNetworkChanged( |
| 103 net::NetworkChangeNotifier::ConnectionType type) override; |
| 104 |
| 99 // Called to remove browsing data. With CLEAR_BEACONS, leaves contexts in | 105 // Called to remove browsing data. With CLEAR_BEACONS, leaves contexts in |
| 100 // place but clears beacons (which betray browsing history); with | 106 // place but clears beacons (which betray browsing history); with |
| 101 // CLEAR_CONTEXTS, removes all contexts (which can behave as cookies). | 107 // CLEAR_CONTEXTS, removes all contexts (which can behave as cookies). |
| 102 void ClearBrowsingData(DomainReliabilityClearMode mode); | 108 void ClearBrowsingData(DomainReliabilityClearMode mode); |
| 103 | 109 |
| 104 // Gets a Value containing data that can be formatted into a web page for | 110 // Gets a Value containing data that can be formatted into a web page for |
| 105 // debugging purposes. | 111 // debugging purposes. |
| 106 scoped_ptr<base::Value> GetWebUIData() const; | 112 scoped_ptr<base::Value> GetWebUIData() const; |
| 107 | 113 |
| 108 DomainReliabilityContext* AddContextForTesting( | 114 DomainReliabilityContext* AddContextForTesting( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 bool OnPrefThread() const { | 151 bool OnPrefThread() const { |
| 146 return pref_task_runner_->BelongsToCurrentThread(); | 152 return pref_task_runner_->BelongsToCurrentThread(); |
| 147 } | 153 } |
| 148 bool OnNetworkThread() const { | 154 bool OnNetworkThread() const { |
| 149 return network_task_runner_->BelongsToCurrentThread(); | 155 return network_task_runner_->BelongsToCurrentThread(); |
| 150 } | 156 } |
| 151 | 157 |
| 152 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); | 158 base::WeakPtr<DomainReliabilityMonitor> MakeWeakPtr(); |
| 153 | 159 |
| 154 scoped_ptr<MockableTime> time_; | 160 scoped_ptr<MockableTime> time_; |
| 161 base::TimeTicks last_network_change_time_; |
| 155 const std::string upload_reporter_string_; | 162 const std::string upload_reporter_string_; |
| 156 DomainReliabilityScheduler::Params scheduler_params_; | 163 DomainReliabilityScheduler::Params scheduler_params_; |
| 157 DomainReliabilityDispatcher dispatcher_; | 164 DomainReliabilityDispatcher dispatcher_; |
| 158 scoped_ptr<DomainReliabilityUploader> uploader_; | 165 scoped_ptr<DomainReliabilityUploader> uploader_; |
| 159 ContextMap contexts_; | 166 ContextMap contexts_; |
| 160 | 167 |
| 161 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; | 168 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner_; |
| 162 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 169 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
| 163 | 170 |
| 164 bool moved_to_network_thread_; | 171 bool moved_to_network_thread_; |
| 165 bool discard_uploads_set_; | 172 bool discard_uploads_set_; |
| 166 | 173 |
| 167 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; | 174 base::WeakPtrFactory<DomainReliabilityMonitor> weak_factory_; |
| 168 | 175 |
| 169 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); | 176 DISALLOW_COPY_AND_ASSIGN(DomainReliabilityMonitor); |
| 170 }; | 177 }; |
| 171 | 178 |
| 172 } // namespace domain_reliability | 179 } // namespace domain_reliability |
| 173 | 180 |
| 174 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ | 181 #endif // COMPONENTS_DOMAIN_RELIABILITY_MONITOR_H_ |
| OLD | NEW |