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 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ 6 #define COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ 7 8 #include <string> 9 10 #include "base/memory/scoped_ptr.h" 11 #include "components/metrics/metrics_log_uploader.h" 12 #include "net/url_request/url_fetcher_delegate.h" 13 14 namespace net { 15 class URLFetcher; 16 class URLRequestContextGetter; 17 } 18 19 namespace metrics { 20 21 // Implementation of MetricsLogUploader using the Chrome network stack. 22 class NetMetricsLogUploader : public MetricsLogUploader, 23 public net::URLFetcherDelegate { 24 public: 25 // Constructs a NetMetricsLogUploader with the specified request context and 26 // other params (see comments on MetricsLogUploader for details). The caller 27 // must ensure that |request_context_getter| remains valid for the lifetime 28 // of this class. 29 NetMetricsLogUploader(net::URLRequestContextGetter* request_context_getter, 30 const std::string& server_url, 31 const std::string& mime_type, 32 const base::Callback<void(int)>& on_upload_complete); 33 virtual ~NetMetricsLogUploader(); 34 35 // MetricsLogUploader: 36 virtual bool UploadLog(const std::string& compressed_log_data, 37 const std::string& log_hash) OVERRIDE; 38 39 private: 40 // net::URLFetcherDelegate: 41 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; 42 43 // The request context for fetches done using the network stack. 44 net::URLRequestContextGetter* const request_context_getter_; 45 46 // The outstanding transmission appears as a URL Fetch operation. 47 scoped_ptr<net::URLFetcher> current_fetch_; 48 49 DISALLOW_COPY_AND_ASSIGN(NetMetricsLogUploader); 50 }; 51 52 } // namespace metrics 53 54 #endif // COMPONENTS_METRICS_NET_NET_METRICS_LOG_UPLOADER_H_ 55