Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_PINGBA CK_CLIENT_H_ | 5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PINGBA CK_CLIENT_H_ |
| 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PINGBA CK_CLIENT_H_ | 6 #define COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PINGBA CK_CLIENT_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
| 14 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 | 16 |
| 17 namespace base { | |
| 18 class Time; | |
| 19 } | |
| 20 | |
| 17 namespace net { | 21 namespace net { |
| 18 class URLFetcher; | 22 class URLFetcher; |
| 19 class URLRequestContextGetter; | 23 class URLRequestContextGetter; |
| 20 } | 24 } |
| 21 | 25 |
| 22 namespace data_reduction_proxy { | 26 namespace data_reduction_proxy { |
| 23 class DataReductionProxyData; | 27 class DataReductionProxyData; |
| 28 class RecordPageloadMetricsRequest; | |
|
tbansal1
2016/07/15 17:44:04
lexicographical order.
RyanSturm
2016/07/15 18:16:03
Done.
| |
| 24 struct DataReductionProxyPageLoadTiming; | 29 struct DataReductionProxyPageLoadTiming; |
| 25 | 30 |
| 26 // Manages pingbacks about page load timing information to the data saver proxy | 31 // Manages pingbacks about page load timing information to the data saver proxy |
| 27 // server. This class is not thread safe. | 32 // server. This class is not thread safe. |
| 28 class DataReductionProxyPingbackClient : public net::URLFetcherDelegate { | 33 class DataReductionProxyPingbackClient : public net::URLFetcherDelegate { |
| 29 public: | 34 public: |
| 30 // The caller must ensure that |url_request_context| remains alive for the | 35 // The caller must ensure that |url_request_context| remains alive for the |
| 31 // lifetime of the |DataReductionProxyPingbackClient| instance. | 36 // lifetime of the |DataReductionProxyPingbackClient| instance. |
| 32 explicit DataReductionProxyPingbackClient( | 37 explicit DataReductionProxyPingbackClient( |
| 33 net::URLRequestContextGetter* url_request_context); | 38 net::URLRequestContextGetter* url_request_context); |
| 34 ~DataReductionProxyPingbackClient() override; | 39 ~DataReductionProxyPingbackClient() override; |
| 35 | 40 |
| 36 // Sends a pingback to the data saver proxy server about various timing | 41 // Sends a pingback to the data saver proxy server about various timing |
| 37 // information. | 42 // information. |
| 38 virtual void SendPingback(const DataReductionProxyData& data, | 43 virtual void SendPingback(const DataReductionProxyData& data, |
| 39 const DataReductionProxyPageLoadTiming& timing); | 44 const DataReductionProxyPageLoadTiming& timing); |
| 40 | 45 |
| 41 // Sets the probability of actually sending a pingback to the server for any | 46 // Sets the probability of actually sending a pingback to the server for any |
| 42 // call to SendPingback. | 47 // call to SendPingback. |
| 43 void SetPingbackReportingFraction(float pingback_reporting_fraction); | 48 void SetPingbackReportingFraction(float pingback_reporting_fraction); |
| 44 | 49 |
| 45 protected: | 50 protected: |
| 46 // Generates a float in the range [0, 1). Virtualized in testing. | 51 // Generates a float in the range [0, 1). Virtualized in testing. |
| 47 virtual float GenerateRandomFloat() const; | 52 virtual float GenerateRandomFloat() const; |
| 48 | 53 |
| 54 // Returns the current time. Virtualized in testing. | |
| 55 virtual base::Time CurrentTime() const; | |
| 56 | |
| 49 private: | 57 private: |
| 50 // URLFetcherDelegate implmentation: | 58 // URLFetcherDelegate implmentation: |
| 51 void OnURLFetchComplete(const net::URLFetcher* source) override; | 59 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 52 | 60 |
| 53 // Whether a pingback should be sent. | 61 // Whether a pingback should be sent. |
| 54 bool ShouldSendPingback() const; | 62 bool ShouldSendPingback() const; |
| 55 | 63 |
| 56 // Creates an URLFetcher that will POST to |secure_proxy_url_| using | 64 // Creates an URLFetcher that will POST to |secure_proxy_url_| using |
| 57 // |url_request_context_|. The max retires is set to 5. | 65 // |url_request_context_|. The max retires is set to 5. |
| 58 std::unique_ptr<net::URLFetcher> MaybeCreateFetcherForDataAndStart( | 66 std::unique_ptr<net::URLFetcher> MaybeCreateFetcherForDataAndStart( |
| 59 const std::string& data); | 67 RecordPageloadMetricsRequest* request_data); |
|
tbansal1
2016/07/15 17:44:04
Say something about the ownership in comments. e.g
RyanSturm
2016/07/15 18:16:03
Done.
| |
| 60 | 68 |
| 61 net::URLRequestContextGetter* url_request_context_; | 69 net::URLRequestContextGetter* url_request_context_; |
| 62 | 70 |
| 63 // The URL for the data saver proxy's ping back service. | 71 // The URL for the data saver proxy's ping back service. |
| 64 const GURL pingback_url_; | 72 const GURL pingback_url_; |
| 65 | 73 |
| 66 // The currently running fetcher. | 74 // The currently running fetcher. |
| 67 std::unique_ptr<net::URLFetcher> current_fetcher_; | 75 std::unique_ptr<net::URLFetcher> current_fetcher_; |
| 68 | 76 |
| 69 // Serialized data to send to the data saver proxy server. | 77 // Serialized data to send to the data saver proxy server. |
| 70 std::list<std::string> data_to_send_; | 78 std::list<std::unique_ptr<RecordPageloadMetricsRequest>> data_to_send_; |
| 71 | 79 |
| 72 // The probability of sending a pingback to the server. | 80 // The probability of sending a pingback to the server. |
| 73 float pingback_reporting_fraction_; | 81 float pingback_reporting_fraction_; |
| 74 | 82 |
| 75 base::ThreadChecker thread_checker_; | 83 base::ThreadChecker thread_checker_; |
| 76 | 84 |
| 77 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient); | 85 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient); |
| 78 }; | 86 }; |
| 79 | 87 |
| 80 } // namespace data_reduction_proxy | 88 } // namespace data_reduction_proxy |
| 81 | 89 |
| 82 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_ | 90 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_ |
| OLD | NEW |