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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.h

Issue 2149193002: Sending the time of the pingback request in the request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 years, 5 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
« no previous file with comments | « no previous file | components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
24 struct DataReductionProxyPageLoadTiming; 28 struct DataReductionProxyPageLoadTiming;
29 class RecordPageloadMetricsRequest;
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.
66 // The caller must ensure that request_data| is non-null. The caller owns
67 // |request_data|.
58 std::unique_ptr<net::URLFetcher> MaybeCreateFetcherForDataAndStart( 68 std::unique_ptr<net::URLFetcher> MaybeCreateFetcherForDataAndStart(
59 const std::string& data); 69 RecordPageloadMetricsRequest* request_data);
60 70
61 net::URLRequestContextGetter* url_request_context_; 71 net::URLRequestContextGetter* url_request_context_;
62 72
63 // The URL for the data saver proxy's ping back service. 73 // The URL for the data saver proxy's ping back service.
64 const GURL pingback_url_; 74 const GURL pingback_url_;
65 75
66 // The currently running fetcher. 76 // The currently running fetcher.
67 std::unique_ptr<net::URLFetcher> current_fetcher_; 77 std::unique_ptr<net::URLFetcher> current_fetcher_;
68 78
69 // Serialized data to send to the data saver proxy server. 79 // Serialized data to send to the data saver proxy server.
70 std::list<std::string> data_to_send_; 80 std::list<std::unique_ptr<RecordPageloadMetricsRequest>> data_to_send_;
71 81
72 // The probability of sending a pingback to the server. 82 // The probability of sending a pingback to the server.
73 float pingback_reporting_fraction_; 83 float pingback_reporting_fraction_;
74 84
75 base::ThreadChecker thread_checker_; 85 base::ThreadChecker thread_checker_;
76 86
77 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient); 87 DISALLOW_COPY_AND_ASSIGN(DataReductionProxyPingbackClient);
78 }; 88 };
79 89
80 } // namespace data_reduction_proxy 90 } // namespace data_reduction_proxy
81 91
82 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_ 92 #endif // COMPONENTS_DATA_REDUCTION_PROXY_CORE_BROWSER_DATA_REDUCTION_PROXY_PIN GBACK_CLIENT_H_
OLDNEW
« no previous file with comments | « no previous file | components/data_reduction_proxy/core/browser/data_reduction_proxy_pingback_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698