Chromium Code Reviews| 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 #include "components/domain_reliability/uploader.h" | 5 #include "components/domain_reliability/uploader.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 51 |
| 52 class DomainReliabilityUploaderImpl | 52 class DomainReliabilityUploaderImpl |
| 53 : public DomainReliabilityUploader, net::URLFetcherDelegate { | 53 : public DomainReliabilityUploader, net::URLFetcherDelegate { |
| 54 public: | 54 public: |
| 55 DomainReliabilityUploaderImpl( | 55 DomainReliabilityUploaderImpl( |
| 56 MockableTime* time, | 56 MockableTime* time, |
| 57 const scoped_refptr< | 57 const scoped_refptr< |
| 58 net::URLRequestContextGetter>& url_request_context_getter) | 58 net::URLRequestContextGetter>& url_request_context_getter) |
| 59 : time_(time), | 59 : time_(time), |
| 60 url_request_context_getter_(url_request_context_getter), | 60 url_request_context_getter_(url_request_context_getter), |
| 61 discard_uploads_(true) {} | 61 discard_uploads_(true), |
| 62 shutdown_(false) {} | |
| 62 | 63 |
| 63 ~DomainReliabilityUploaderImpl() override {} | 64 ~DomainReliabilityUploaderImpl() override { |
| 65 DCHECK(shutdown_); | |
|
mmenke
2016/12/14 19:12:17
include base/logging.h
Julia Tuttle
2016/12/15 21:53:00
Done.
| |
| 66 } | |
| 64 | 67 |
| 65 // DomainReliabilityUploader implementation: | 68 // DomainReliabilityUploader implementation: |
| 66 void UploadReport( | 69 void UploadReport( |
| 67 const std::string& report_json, | 70 const std::string& report_json, |
| 68 int max_upload_depth, | 71 int max_upload_depth, |
| 69 const GURL& upload_url, | 72 const GURL& upload_url, |
| 70 const DomainReliabilityUploader::UploadCallback& callback) override { | 73 const DomainReliabilityUploader::UploadCallback& callback) override { |
| 71 VLOG(1) << "Uploading report to " << upload_url; | 74 VLOG(1) << "Uploading report to " << upload_url; |
| 72 VLOG(2) << "Report JSON: " << report_json; | 75 VLOG(2) << "Report JSON: " << report_json; |
| 73 | 76 |
| 74 if (discard_uploads_) { | 77 if (discard_uploads_ || shutdown_) { |
| 75 VLOG(1) << "Discarding report instead of uploading."; | 78 VLOG(1) << "Discarding report instead of uploading."; |
| 76 UploadResult result; | 79 UploadResult result; |
| 77 result.status = UploadResult::SUCCESS; | 80 result.status = UploadResult::SUCCESS; |
| 78 callback.Run(result); | 81 callback.Run(result); |
| 79 return; | 82 return; |
| 80 } | 83 } |
| 81 | 84 |
| 82 std::unique_ptr<net::URLFetcher> owned_fetcher = | 85 std::unique_ptr<net::URLFetcher> owned_fetcher = |
| 83 net::URLFetcher::Create(0, upload_url, net::URLFetcher::POST, this); | 86 net::URLFetcher::Create(0, upload_url, net::URLFetcher::POST, this); |
| 84 net::URLFetcher* fetcher = owned_fetcher.get(); | 87 net::URLFetcher* fetcher = owned_fetcher.get(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 100 now - last_upload_start_time_); | 103 now - last_upload_start_time_); |
| 101 } | 104 } |
| 102 last_upload_start_time_ = now; | 105 last_upload_start_time_ = now; |
| 103 } | 106 } |
| 104 | 107 |
| 105 void set_discard_uploads(bool discard_uploads) override { | 108 void set_discard_uploads(bool discard_uploads) override { |
| 106 discard_uploads_ = discard_uploads; | 109 discard_uploads_ = discard_uploads; |
| 107 VLOG(1) << "Setting discard_uploads to " << discard_uploads; | 110 VLOG(1) << "Setting discard_uploads to " << discard_uploads; |
| 108 } | 111 } |
| 109 | 112 |
| 113 void Shutdown() override { | |
| 114 DCHECK(!shutdown_); | |
| 115 shutdown_ = true; | |
| 116 upload_callbacks_.clear(); | |
| 117 } | |
| 118 | |
| 110 // net::URLFetcherDelegate implementation: | 119 // net::URLFetcherDelegate implementation: |
| 111 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { | 120 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { |
| 112 DCHECK(fetcher); | 121 DCHECK(fetcher); |
| 113 | 122 |
| 114 auto callback_it = upload_callbacks_.find(fetcher); | 123 auto callback_it = upload_callbacks_.find(fetcher); |
| 115 DCHECK(callback_it != upload_callbacks_.end()); | 124 DCHECK(callback_it != upload_callbacks_.end()); |
| 116 | 125 |
| 117 int net_error = GetNetErrorFromURLRequestStatus(fetcher->GetStatus()); | 126 int net_error = GetNetErrorFromURLRequestStatus(fetcher->GetStatus()); |
| 118 int http_response_code = fetcher->GetResponseCode(); | 127 int http_response_code = fetcher->GetResponseCode(); |
| 119 base::TimeDelta retry_after; | 128 base::TimeDelta retry_after; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 148 upload_callbacks_.erase(callback_it); | 157 upload_callbacks_.erase(callback_it); |
| 149 } | 158 } |
| 150 | 159 |
| 151 private: | 160 private: |
| 152 using DomainReliabilityUploader::UploadCallback; | 161 using DomainReliabilityUploader::UploadCallback; |
| 153 | 162 |
| 154 MockableTime* time_; | 163 MockableTime* time_; |
| 155 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 164 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 156 std::map<const net::URLFetcher*, | 165 std::map<const net::URLFetcher*, |
| 157 std::pair<std::unique_ptr<net::URLFetcher>, UploadCallback>> | 166 std::pair<std::unique_ptr<net::URLFetcher>, UploadCallback>> |
| 158 upload_callbacks_; | 167 upload_callbacks_; |
|
mmenke
2016/12/14 19:12:17
A bit afield from this CL, but do you mind rename
Julia Tuttle
2016/12/15 21:53:00
Sure, I'll just call it uploads_.
| |
| 159 bool discard_uploads_; | 168 bool discard_uploads_; |
| 160 base::TimeTicks last_upload_start_time_; | 169 base::TimeTicks last_upload_start_time_; |
| 170 bool shutdown_; | |
| 161 }; | 171 }; |
| 162 | 172 |
| 163 } // namespace | 173 } // namespace |
| 164 | 174 |
| 165 DomainReliabilityUploader::DomainReliabilityUploader() {} | 175 DomainReliabilityUploader::DomainReliabilityUploader() {} |
| 166 DomainReliabilityUploader::~DomainReliabilityUploader() {} | 176 DomainReliabilityUploader::~DomainReliabilityUploader() {} |
| 167 | 177 |
| 168 // static | 178 // static |
| 169 std::unique_ptr<DomainReliabilityUploader> DomainReliabilityUploader::Create( | 179 std::unique_ptr<DomainReliabilityUploader> DomainReliabilityUploader::Create( |
| 170 MockableTime* time, | 180 MockableTime* time, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 183 // static | 193 // static |
| 184 int DomainReliabilityUploader::GetURLRequestUploadDepth( | 194 int DomainReliabilityUploader::GetURLRequestUploadDepth( |
| 185 const net::URLRequest& request) { | 195 const net::URLRequest& request) { |
| 186 UploadUserData* data = static_cast<UploadUserData*>( | 196 UploadUserData* data = static_cast<UploadUserData*>( |
| 187 request.GetUserData(UploadUserData::kUserDataKey)); | 197 request.GetUserData(UploadUserData::kUserDataKey)); |
| 188 if (!data) | 198 if (!data) |
| 189 return 0; | 199 return 0; |
| 190 return data->depth(); | 200 return data->depth(); |
| 191 } | 201 } |
| 192 | 202 |
| 203 void DomainReliabilityUploader::Shutdown() {} | |
| 204 | |
| 193 } // namespace domain_reliability | 205 } // namespace domain_reliability |
| OLD | NEW |