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

Side by Side Diff: components/metrics/net/net_metrics_log_uploader.cc

Issue 2708293002: Switch UKM service to properly mark upload data as UKM and not UMA. (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
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 #include "components/metrics/net/net_metrics_log_uploader.h" 5 #include "components/metrics/net/net_metrics_log_uploader.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "components/data_use_measurement/core/data_use_user_data.h" 8 #include "components/data_use_measurement/core/data_use_user_data.h"
9 #include "components/metrics/metrics_log_uploader.h"
9 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
10 #include "net/url_request/url_fetcher.h" 11 #include "net/url_request/url_fetcher.h"
11 #include "url/gurl.h" 12 #include "url/gurl.h"
12 13
13 namespace metrics { 14 namespace metrics {
14 15
15 NetMetricsLogUploader::NetMetricsLogUploader( 16 NetMetricsLogUploader::NetMetricsLogUploader(
16 net::URLRequestContextGetter* request_context_getter, 17 net::URLRequestContextGetter* request_context_getter,
17 const std::string& server_url, 18 const std::string& server_url,
18 const std::string& mime_type, 19 const std::string& mime_type,
20 MetricsLogUploader::MetricServiceType service_type,
19 const base::Callback<void(int)>& on_upload_complete) 21 const base::Callback<void(int)>& on_upload_complete)
20 : MetricsLogUploader(server_url, mime_type, on_upload_complete), 22 : MetricsLogUploader(server_url,
21 request_context_getter_(request_context_getter) { 23 mime_type,
22 } 24 service_type,
25 on_upload_complete),
26 request_context_getter_(request_context_getter) {}
23 27
24 NetMetricsLogUploader::~NetMetricsLogUploader() { 28 NetMetricsLogUploader::~NetMetricsLogUploader() {
25 } 29 }
26 30
27 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data, 31 void NetMetricsLogUploader::UploadLog(const std::string& compressed_log_data,
28 const std::string& log_hash) { 32 const std::string& log_hash) {
29 current_fetch_ = 33 current_fetch_ =
30 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this); 34 net::URLFetcher::Create(GURL(server_url_), net::URLFetcher::POST, this);
31 data_use_measurement::DataUseUserData::AttachToFetcher( 35
32 current_fetch_.get(), data_use_measurement::DataUseUserData::UMA); 36 // Default to UMA service.
37 auto service = data_use_measurement::DataUseUserData::UMA;
38 if (service_type_ == MetricsLogUploader::UKM)
Alexei Svitkine (slow) 2017/02/22 15:46:10 Can you do a switch instead? Switch guarantees if
rkaplow 2017/02/22 16:11:35 Done.
39 service = data_use_measurement::DataUseUserData::UKM;
40
41 data_use_measurement::DataUseUserData::AttachToFetcher(current_fetch_.get(),
42 service);
33 current_fetch_->SetRequestContext(request_context_getter_); 43 current_fetch_->SetRequestContext(request_context_getter_);
34 current_fetch_->SetUploadData(mime_type_, compressed_log_data); 44 current_fetch_->SetUploadData(mime_type_, compressed_log_data);
35 45
36 // Tell the server that we're uploading gzipped protobufs. 46 // Tell the server that we're uploading gzipped protobufs.
37 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip"); 47 current_fetch_->SetExtraRequestHeaders("content-encoding: gzip");
38 48
39 DCHECK(!log_hash.empty()); 49 DCHECK(!log_hash.empty());
40 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash); 50 current_fetch_->AddExtraRequestHeader("X-Chrome-UMA-Log-SHA1: " + log_hash);
41 51
42 // Drop cookies and auth data. 52 // Drop cookies and auth data.
(...skipping 10 matching lines...) Expand all
53 DCHECK_EQ(current_fetch_.get(), source); 63 DCHECK_EQ(current_fetch_.get(), source);
54 64
55 int response_code = source->GetResponseCode(); 65 int response_code = source->GetResponseCode();
56 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID) 66 if (response_code == net::URLFetcher::RESPONSE_CODE_INVALID)
57 response_code = -1; 67 response_code = -1;
58 current_fetch_.reset(); 68 current_fetch_.reset();
59 on_upload_complete_.Run(response_code); 69 on_upload_complete_.Run(response_code);
60 } 70 }
61 71
62 } // namespace metrics 72 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698