| 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_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ | 5 #ifndef COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ |
| 6 #define COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ | 6 #define COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/string_piece.h" |
| 12 #include "components/metrics/metrics_log_uploader.h" | 13 #include "components/metrics/metrics_log_uploader.h" |
| 13 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
| 15 #include "url/gurl.h" |
| 14 | 16 |
| 15 namespace net { | 17 namespace net { |
| 16 class URLFetcher; | 18 class URLFetcher; |
| 17 class URLRequestContextGetter; | 19 class URLRequestContextGetter; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace metrics { | 22 namespace metrics { |
| 21 | 23 |
| 22 // Implementation of MetricsLogUploader using the Chrome network stack. | 24 // Implementation of MetricsLogUploader using the Chrome network stack. |
| 23 class NetMetricsLogUploader : public MetricsLogUploader, | 25 class NetMetricsLogUploader : public MetricsLogUploader, |
| 24 public net::URLFetcherDelegate { | 26 public net::URLFetcherDelegate { |
| 25 public: | 27 public: |
| 26 // Constructs a NetMetricsLogUploader with the specified request context and | 28 // Constructs a NetMetricsLogUploader which uploads data to |server_url| with |
| 27 // other params (see comments on MetricsLogUploader for details). The caller | 29 // the specified |mime_type|. The |service_type| marks which service the |
| 28 // must ensure that |request_context_getter| remains valid for the lifetime | 30 // data usage should be attributed to. The |on_upload_complete| callback will |
| 29 // of this class. | 31 // be called with the HTTP response code of the upload or with -1 on an error. |
| 32 // The caller must ensure that |request_context_getter| remains valid for the |
| 33 // lifetime of this class. |
| 30 NetMetricsLogUploader(net::URLRequestContextGetter* request_context_getter, | 34 NetMetricsLogUploader(net::URLRequestContextGetter* request_context_getter, |
| 31 const std::string& server_url, | 35 base::StringPiece server_url, |
| 32 const std::string& mime_type, | 36 base::StringPiece mime_type, |
| 33 MetricsLogUploader::MetricServiceType service_type, | 37 MetricsLogUploader::MetricServiceType service_type, |
| 34 const base::Callback<void(int)>& on_upload_complete); | 38 const base::Callback<void(int)>& on_upload_complete); |
| 35 ~NetMetricsLogUploader() override; | 39 ~NetMetricsLogUploader() override; |
| 36 | 40 |
| 37 // MetricsLogUploader: | 41 // MetricsLogUploader: |
| 38 void UploadLog(const std::string& compressed_log_data, | 42 void UploadLog(const std::string& compressed_log_data, |
| 39 const std::string& log_hash) override; | 43 const std::string& log_hash) override; |
| 40 | 44 |
| 41 private: | 45 private: |
| 42 // net::URLFetcherDelegate: | 46 // net::URLFetcherDelegate: |
| 43 void OnURLFetchComplete(const net::URLFetcher* source) override; | 47 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 44 | 48 |
| 45 // The request context for fetches done using the network stack. | 49 // The request context for fetches done using the network stack. |
| 46 net::URLRequestContextGetter* const request_context_getter_; | 50 net::URLRequestContextGetter* const request_context_getter_; |
| 47 | 51 |
| 52 const GURL server_url_; |
| 53 const std::string mime_type_; |
| 54 const MetricsLogUploader::MetricServiceType service_type_; |
| 55 const base::Callback<void(int)> on_upload_complete_; |
| 56 |
| 48 // The outstanding transmission appears as a URL Fetch operation. | 57 // The outstanding transmission appears as a URL Fetch operation. |
| 49 std::unique_ptr<net::URLFetcher> current_fetch_; | 58 std::unique_ptr<net::URLFetcher> current_fetch_; |
| 50 | 59 |
| 51 DISALLOW_COPY_AND_ASSIGN(NetMetricsLogUploader); | 60 DISALLOW_COPY_AND_ASSIGN(NetMetricsLogUploader); |
| 52 }; | 61 }; |
| 53 | 62 |
| 54 } // namespace metrics | 63 } // namespace metrics |
| 55 | 64 |
| 56 #endif // COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ | 65 #endif // COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ |
| OLD | NEW |