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

Side by Side Diff: components/domain_reliability/uploader.cc

Issue 666133002: Standardize usage of virtual/override/final in components/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 | « components/domain_reliability/test_util.cc ('k') | components/domain_reliability/util.h » ('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 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/domain_reliability/uploader.h" 5 #include "components/domain_reliability/uploader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
(...skipping 28 matching lines...) Expand all
39 static_cast<const void*>(&UploadUserData::kUserDataKey); 39 static_cast<const void*>(&UploadUserData::kUserDataKey);
40 40
41 class DomainReliabilityUploaderImpl 41 class DomainReliabilityUploaderImpl
42 : public DomainReliabilityUploader, net::URLFetcherDelegate { 42 : public DomainReliabilityUploader, net::URLFetcherDelegate {
43 public: 43 public:
44 DomainReliabilityUploaderImpl(const scoped_refptr< 44 DomainReliabilityUploaderImpl(const scoped_refptr<
45 net::URLRequestContextGetter>& url_request_context_getter) 45 net::URLRequestContextGetter>& url_request_context_getter)
46 : url_request_context_getter_(url_request_context_getter), 46 : url_request_context_getter_(url_request_context_getter),
47 discard_uploads_(true) {} 47 discard_uploads_(true) {}
48 48
49 virtual ~DomainReliabilityUploaderImpl() { 49 ~DomainReliabilityUploaderImpl() override {
50 // Delete any in-flight URLFetchers. 50 // Delete any in-flight URLFetchers.
51 STLDeleteContainerPairFirstPointers( 51 STLDeleteContainerPairFirstPointers(
52 upload_callbacks_.begin(), upload_callbacks_.end()); 52 upload_callbacks_.begin(), upload_callbacks_.end());
53 } 53 }
54 54
55 // DomainReliabilityUploader implementation: 55 // DomainReliabilityUploader implementation:
56 virtual void UploadReport( 56 void UploadReport(
57 const std::string& report_json, 57 const std::string& report_json,
58 const GURL& upload_url, 58 const GURL& upload_url,
59 const DomainReliabilityUploader::UploadCallback& callback) override { 59 const DomainReliabilityUploader::UploadCallback& callback) override {
60 VLOG(1) << "Uploading report to " << upload_url; 60 VLOG(1) << "Uploading report to " << upload_url;
61 VLOG(2) << "Report JSON: " << report_json; 61 VLOG(2) << "Report JSON: " << report_json;
62 62
63 if (discard_uploads_) { 63 if (discard_uploads_) {
64 VLOG(1) << "Discarding report instead of uploading."; 64 VLOG(1) << "Discarding report instead of uploading.";
65 callback.Run(true); 65 callback.Run(true);
66 return; 66 return;
67 } 67 }
68 68
69 net::URLFetcher* fetcher = 69 net::URLFetcher* fetcher =
70 net::URLFetcher::Create(0, upload_url, net::URLFetcher::POST, this); 70 net::URLFetcher::Create(0, upload_url, net::URLFetcher::POST, this);
71 fetcher->SetRequestContext(url_request_context_getter_.get()); 71 fetcher->SetRequestContext(url_request_context_getter_.get());
72 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | 72 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES |
73 net::LOAD_DO_NOT_SAVE_COOKIES); 73 net::LOAD_DO_NOT_SAVE_COOKIES);
74 fetcher->SetUploadData(kJsonMimeType, report_json); 74 fetcher->SetUploadData(kJsonMimeType, report_json);
75 fetcher->SetAutomaticallyRetryOn5xx(false); 75 fetcher->SetAutomaticallyRetryOn5xx(false);
76 fetcher->SetURLRequestUserData( 76 fetcher->SetURLRequestUserData(
77 UploadUserData::kUserDataKey, 77 UploadUserData::kUserDataKey,
78 UploadUserData::CreateCreateDataCallback()); 78 UploadUserData::CreateCreateDataCallback());
79 fetcher->Start(); 79 fetcher->Start();
80 80
81 upload_callbacks_[fetcher] = callback; 81 upload_callbacks_[fetcher] = callback;
82 } 82 }
83 83
84 virtual void set_discard_uploads(bool discard_uploads) override { 84 void set_discard_uploads(bool discard_uploads) override {
85 discard_uploads_ = discard_uploads; 85 discard_uploads_ = discard_uploads;
86 VLOG(1) << "Setting discard_uploads to " << discard_uploads; 86 VLOG(1) << "Setting discard_uploads to " << discard_uploads;
87 } 87 }
88 88
89 // net::URLFetcherDelegate implementation: 89 // net::URLFetcherDelegate implementation:
90 virtual void OnURLFetchComplete( 90 void OnURLFetchComplete(const net::URLFetcher* fetcher) override {
91 const net::URLFetcher* fetcher) override {
92 DCHECK(fetcher); 91 DCHECK(fetcher);
93 92
94 UploadCallbackMap::iterator callback_it = upload_callbacks_.find(fetcher); 93 UploadCallbackMap::iterator callback_it = upload_callbacks_.find(fetcher);
95 DCHECK(callback_it != upload_callbacks_.end()); 94 DCHECK(callback_it != upload_callbacks_.end());
96 95
97 VLOG(1) << "Upload finished with " << fetcher->GetResponseCode(); 96 VLOG(1) << "Upload finished with " << fetcher->GetResponseCode();
98 97
99 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadResponseCode", 98 UMA_HISTOGRAM_SPARSE_SLOWLY("DomainReliability.UploadResponseCode",
100 fetcher->GetResponseCode()); 99 fetcher->GetResponseCode());
101 100
(...skipping 26 matching lines...) Expand all
128 new DomainReliabilityUploaderImpl(url_request_context_getter)); 127 new DomainReliabilityUploaderImpl(url_request_context_getter));
129 } 128 }
130 129
131 // static 130 // static
132 bool DomainReliabilityUploader::URLRequestIsUpload( 131 bool DomainReliabilityUploader::URLRequestIsUpload(
133 const net::URLRequest& request) { 132 const net::URLRequest& request) {
134 return request.GetUserData(UploadUserData::kUserDataKey) != NULL; 133 return request.GetUserData(UploadUserData::kUserDataKey) != NULL;
135 } 134 }
136 135
137 } // namespace domain_reliability 136 } // namespace domain_reliability
OLDNEW
« no previous file with comments | « components/domain_reliability/test_util.cc ('k') | components/domain_reliability/util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698