OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVIC
E_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVIC
E_H_ |
6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVIC
E_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SERVIC
E_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 class URLRequestContextGetter; | 25 class URLRequestContextGetter; |
26 class URLRequestStatus; | 26 class URLRequestStatus; |
27 } | 27 } |
28 | 28 |
29 namespace data_reduction_proxy { | 29 namespace data_reduction_proxy { |
30 | 30 |
31 typedef base::Callback<void(const std::string&, const net::URLRequestStatus&)> | 31 typedef base::Callback<void(const std::string&, const net::URLRequestStatus&)> |
32 FetcherResponseCallback; | 32 FetcherResponseCallback; |
33 | 33 |
34 class DataReductionProxySettings; | 34 class DataReductionProxySettings; |
35 class DataReductionProxyStatisticsPrefs; | 35 class DataReductionProxyCompressionStats; |
36 | |
37 | 36 |
38 // Contains and initializes all Data Reduction Proxy objects that have a | 37 // Contains and initializes all Data Reduction Proxy objects that have a |
39 // lifetime based on the UI thread. | 38 // lifetime based on the UI thread. |
40 class DataReductionProxyService : public base::NonThreadSafe, | 39 class DataReductionProxyService : public base::NonThreadSafe, |
41 public net::URLFetcherDelegate { | 40 public net::URLFetcherDelegate { |
42 public: | 41 public: |
43 // The caller must ensure that |settings| and |request_context| remain alive | 42 // The caller must ensure that |settings| and |request_context| remain alive |
44 // for the lifetime of the |DataReductionProxyService| instance. This instance | 43 // for the lifetime of the |DataReductionProxyService| instance. This instance |
45 // will take ownership of |statistics_prefs|. | 44 // will take ownership of |compression_stats|. |
46 // TODO(jeremyim): DataReductionProxyService should own | 45 // TODO(jeremyim): DataReductionProxyService should own |
47 // DataReductionProxySettings and not vice versa. | 46 // DataReductionProxySettings and not vice versa. |
48 DataReductionProxyService( | 47 DataReductionProxyService( |
49 scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs, | 48 scoped_ptr<DataReductionProxyCompressionStats> compression_stats, |
50 DataReductionProxySettings* settings, | 49 DataReductionProxySettings* settings, |
51 net::URLRequestContextGetter* request_context_getter); | 50 net::URLRequestContextGetter* request_context_getter); |
52 | 51 |
53 ~DataReductionProxyService() override; | 52 ~DataReductionProxyService() override; |
54 | 53 |
55 void Shutdown(); | 54 void Shutdown(); |
56 | 55 |
57 // Requests the given |secure_proxy_check_url|. Upon completion, returns the | 56 // Requests the given |secure_proxy_check_url|. Upon completion, returns the |
58 // results to the caller via the |fetcher_callback|. Virtualized for unit | 57 // results to the caller via the |fetcher_callback|. Virtualized for unit |
59 // testing. | 58 // testing. |
60 virtual void SecureProxyCheck(const GURL& secure_proxy_check_url, | 59 virtual void SecureProxyCheck(const GURL& secure_proxy_check_url, |
61 FetcherResponseCallback fetcher_callback); | 60 FetcherResponseCallback fetcher_callback); |
62 | 61 |
63 // Constructs statistics prefs. This should not be called if a valid | 62 // Constructs compression stats. This should not be called if a valid |
64 // statistics prefs is passed into the constructor. | 63 // compression stats is passed into the constructor. |
65 void EnableCompressionStatisticsLogging( | 64 void EnableCompressionStatisticsLogging( |
66 PrefService* prefs, | 65 PrefService* prefs, |
67 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | 66 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, |
68 const base::TimeDelta& commit_delay); | 67 const base::TimeDelta& commit_delay); |
69 | 68 |
70 DataReductionProxyStatisticsPrefs* statistics_prefs() const { | 69 DataReductionProxyCompressionStats* compression_stats() const { |
71 return statistics_prefs_.get(); | 70 return compression_stats_.get(); |
72 } | 71 } |
73 | 72 |
74 DataReductionProxySettings* settings() const { | 73 DataReductionProxySettings* settings() const { |
75 return settings_; | 74 return settings_; |
76 } | 75 } |
77 | 76 |
78 base::WeakPtr<DataReductionProxyService> GetWeakPtr(); | 77 base::WeakPtr<DataReductionProxyService> GetWeakPtr(); |
79 | 78 |
80 protected: | 79 protected: |
81 // Virtualized for testing. Returns a fetcher to check if it is permitted to | 80 // Virtualized for testing. Returns a fetcher to check if it is permitted to |
82 // use the secure proxy. | 81 // use the secure proxy. |
83 virtual net::URLFetcher* GetURLFetcherForSecureProxyCheck( | 82 virtual net::URLFetcher* GetURLFetcherForSecureProxyCheck( |
84 const GURL& secure_proxy_check_url); | 83 const GURL& secure_proxy_check_url); |
85 | 84 |
86 private: | 85 private: |
87 // net::URLFetcherDelegate: | 86 // net::URLFetcherDelegate: |
88 void OnURLFetchComplete(const net::URLFetcher* source) override; | 87 void OnURLFetchComplete(const net::URLFetcher* source) override; |
89 | 88 |
90 net::URLRequestContextGetter* url_request_context_getter_; | 89 net::URLRequestContextGetter* url_request_context_getter_; |
91 | 90 |
92 // The URLFetcher being used for the secure proxy check. | 91 // The URLFetcher being used for the secure proxy check. |
93 scoped_ptr<net::URLFetcher> fetcher_; | 92 scoped_ptr<net::URLFetcher> fetcher_; |
94 FetcherResponseCallback fetcher_callback_; | 93 FetcherResponseCallback fetcher_callback_; |
95 | 94 |
96 // Tracks compression statistics to be displayed to the user. | 95 // Tracks compression statistics to be displayed to the user. |
97 scoped_ptr<DataReductionProxyStatisticsPrefs> statistics_prefs_; | 96 scoped_ptr<DataReductionProxyCompressionStats> compression_stats_; |
98 | 97 |
99 DataReductionProxySettings* settings_; | 98 DataReductionProxySettings* settings_; |
100 | 99 |
101 base::WeakPtrFactory<DataReductionProxyService> weak_factory_; | 100 base::WeakPtrFactory<DataReductionProxyService> weak_factory_; |
102 | 101 |
103 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyService); | 102 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyService); |
104 }; | 103 }; |
105 | 104 |
106 } // namespace data_reduction_proxy | 105 } // namespace data_reduction_proxy |
107 | 106 |
108 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SER
VICE_H_ | 107 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_SER
VICE_H_ |
OLD | NEW |