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

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_usage_stats.h

Issue 412143009: Moved data reduction proxy initialization logic to ProfileImplIOData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 4 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_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_ 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_
6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_ 6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_STATS _H_
7 7
8 #include "base/callback.h"
8 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/threading/thread_checker.h" 10 #include "base/threading/thread_checker.h"
10 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h"
11 #include "net/base/host_port_pair.h" 12 #include "net/base/host_port_pair.h"
12 #include "net/base/network_change_notifier.h" 13 #include "net/base/network_change_notifier.h"
13 14
14 namespace data_reduction_proxy { 15 namespace data_reduction_proxy {
15 16
16 class DataReductionProxyUsageStats 17 class DataReductionProxyUsageStats
17 : public net::NetworkChangeNotifier::NetworkChangeObserver { 18 : public net::NetworkChangeNotifier::NetworkChangeObserver {
18 public: 19 public:
19 // MessageLoopProxy instances are owned by io_thread. |params| outlives 20 // MessageLoopProxy instance is owned by io_thread. |params| outlives
20 // this class instance. 21 // this class instance.
21 DataReductionProxyUsageStats(DataReductionProxyParams* params, 22 DataReductionProxyUsageStats(DataReductionProxyParams* params,
22 base::MessageLoopProxy* ui_thread_proxy, 23 base::MessageLoopProxy* ui_thread_proxy);
23 base::MessageLoopProxy* io_thread_proxy);
24 virtual ~DataReductionProxyUsageStats(); 24 virtual ~DataReductionProxyUsageStats();
25 25
26 /** 26 // Sets the callback to be called on the UI thread when the unavailability
27 * Callback intended to be called from |ChromeNetworkDelegate| when a 27 // status has changed.
28 * request completes. This method is used to gather usage stats. 28 void set_unavailable_callback(
29 */ 29 const base::Callback<void(bool)>& unavailable_callback) {
30 unavailable_callback_ = unavailable_callback;
31 }
32
33 // Callback intended to be called from |ChromeNetworkDelegate| when a
34 // request completes. This method is used to gather usage stats.
30 void OnUrlRequestCompleted(const net::URLRequest* request, bool started); 35 void OnUrlRequestCompleted(const net::URLRequest* request, bool started);
31 36
32 /** 37 private:
33 * Determines whether the data reduction proxy is unreachable. 38 // NetworkChangeNotifier::NetworkChangeObserver:
34 * Returns true if data reduction proxy is unreachable. 39 virtual void OnNetworkChanged(
35 */ 40 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
36 bool isDataReductionProxyUnreachable();
37 41
38 private: 42 // Counts requests that went through the data reduction proxy and counts
43 // requests that were eligible to go through the proxy.
44 void IncrementRequestCounts(bool actual);
45 void ClearRequestCounts();
46
47 // Checks if the availability status of the data reduction proxy has changed,
48 // and notifies the UIThread via NotifyUnavailabilityOnUIThread if so. The
49 // data reduction proxy is considered unavailable if and only if no requests
50 // went through the proxy but some eligible requests were service by other
51 // routes.
52 void MaybeNotifyUnavailability();
53 void NotifyUnavailabilityOnUIThread(bool unavailable);
54
39 DataReductionProxyParams* data_reduction_proxy_params_; 55 DataReductionProxyParams* data_reduction_proxy_params_;
40 base::MessageLoopProxy* ui_thread_proxy_; 56 base::MessageLoopProxy* ui_thread_proxy_;
41 base::MessageLoopProxy* io_thread_proxy_;
42 57
43 // The following 2 fields are used to determine if data reduction proxy is 58 // The following 2 fields are used to determine if data reduction proxy is
44 // unreachable. We keep a count of requests which should go through 59 // unreachable. We keep a count of requests which should go through
45 // data request proxy, as well as those which actually do. The proxy is 60 // data request proxy, as well as those which actually do. The proxy is
46 // unreachable if no successful requests are made through it despite a 61 // unreachable if no successful requests are made through it despite a
47 // non-zero number of requests being eligible. 62 // non-zero number of requests being eligible.
48 63
49 // Count of requests which will be tried to be sent through data reduction 64 // Count of requests which will be tried to be sent through data reduction
50 // proxy. The count is only based on the config and not the bad proxy list. 65 // proxy. The count is only based on the config and not the bad proxy list.
51 // Explicit bypasses are not part of this count. This is the desired behavior 66 // Explicit bypasses are not part of this count. This is the desired behavior
52 // since otherwise both counts would be identical. 67 // since otherwise both counts would be identical.
53 unsigned long eligible_num_requests_through_proxy_; 68 unsigned long eligible_num_requests_through_proxy_;
54 // Count of successfull requests through data reduction proxy. 69
70 // Count of successful requests through data reduction proxy.
55 unsigned long actual_num_requests_through_proxy_; 71 unsigned long actual_num_requests_through_proxy_;
56 72
57 // NetworkChangeNotifier::NetworkChangeObserver: 73 // Whether or not the data reduction proxy is unavailable.
58 virtual void OnNetworkChanged( 74 bool unavailable_;
59 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
60
61 void IncRequestCountsOnUiThread(bool actual);
62 void ClearRequestCountsOnUiThread();
63 75
64 base::ThreadChecker thread_checker_; 76 base::ThreadChecker thread_checker_;
65 77
78 // Called when the unavailability status has changed. Runs on the UI thread.
79 base::Callback<void(bool)> unavailable_callback_;
80
66 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats); 81 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyUsageStats);
67 }; 82 };
68 83
69 } // namespace data_reduction_proxy 84 } // namespace data_reduction_proxy
70 85
71 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_ 86 #endif // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_DATA_REDUCTION_PROXY_USAGE_ST ATS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698