| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 89 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 90 net::LOAD_DO_NOT_SAVE_COOKIES); | 90 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 91 fetcher->SetUploadData(kJsonMimeType, report_json); | 91 fetcher->SetUploadData(kJsonMimeType, report_json); |
| 92 fetcher->SetAutomaticallyRetryOn5xx(false); | 92 fetcher->SetAutomaticallyRetryOn5xx(false); |
| 93 fetcher->SetURLRequestUserData( | 93 fetcher->SetURLRequestUserData( |
| 94 UploadUserData::kUserDataKey, | 94 UploadUserData::kUserDataKey, |
| 95 UploadUserData::CreateCreateDataCallback(max_upload_depth + 1)); | 95 UploadUserData::CreateCreateDataCallback(max_upload_depth + 1)); |
| 96 fetcher->Start(); | 96 fetcher->Start(); |
| 97 | 97 |
| 98 upload_callbacks_[fetcher] = {std::move(owned_fetcher), callback}; | 98 upload_callbacks_[fetcher] = {std::move(owned_fetcher), callback}; |
| 99 |
| 100 base::TimeTicks now = base::TimeTicks::Now(); |
| 101 if (!last_upload_start_time_.is_null()) { |
| 102 UMA_HISTOGRAM_LONG_TIMES("DomainReliability.UploadIntervalGlobal", |
| 103 now - last_upload_start_time_); |
| 104 } |
| 105 last_upload_start_time_ = now; |
| 99 } | 106 } |
| 100 | 107 |
| 101 void set_discard_uploads(bool discard_uploads) override { | 108 void set_discard_uploads(bool discard_uploads) override { |
| 102 discard_uploads_ = discard_uploads; | 109 discard_uploads_ = discard_uploads; |
| 103 VLOG(1) << "Setting discard_uploads to " << discard_uploads; | 110 VLOG(1) << "Setting discard_uploads to " << discard_uploads; |
| 104 } | 111 } |
| 105 | 112 |
| 106 // net::URLFetcherDelegate implementation: | 113 // net::URLFetcherDelegate implementation: |
| 107 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { | 114 void OnURLFetchComplete(const net::URLFetcher* fetcher) override { |
| 108 DCHECK(fetcher); | 115 DCHECK(fetcher); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 153 |
| 147 private: | 154 private: |
| 148 using DomainReliabilityUploader::UploadCallback; | 155 using DomainReliabilityUploader::UploadCallback; |
| 149 | 156 |
| 150 MockableTime* time_; | 157 MockableTime* time_; |
| 151 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 158 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
| 152 std::map<const net::URLFetcher*, | 159 std::map<const net::URLFetcher*, |
| 153 std::pair<std::unique_ptr<net::URLFetcher>, UploadCallback>> | 160 std::pair<std::unique_ptr<net::URLFetcher>, UploadCallback>> |
| 154 upload_callbacks_; | 161 upload_callbacks_; |
| 155 bool discard_uploads_; | 162 bool discard_uploads_; |
| 163 base::TimeTicks last_upload_start_time_; |
| 156 }; | 164 }; |
| 157 | 165 |
| 158 } // namespace | 166 } // namespace |
| 159 | 167 |
| 160 DomainReliabilityUploader::DomainReliabilityUploader() {} | 168 DomainReliabilityUploader::DomainReliabilityUploader() {} |
| 161 DomainReliabilityUploader::~DomainReliabilityUploader() {} | 169 DomainReliabilityUploader::~DomainReliabilityUploader() {} |
| 162 | 170 |
| 163 // static | 171 // static |
| 164 std::unique_ptr<DomainReliabilityUploader> DomainReliabilityUploader::Create( | 172 std::unique_ptr<DomainReliabilityUploader> DomainReliabilityUploader::Create( |
| 165 MockableTime* time, | 173 MockableTime* time, |
| 166 const scoped_refptr<net::URLRequestContextGetter>& | 174 const scoped_refptr<net::URLRequestContextGetter>& |
| 167 url_request_context_getter) { | 175 url_request_context_getter) { |
| 168 return std::unique_ptr<DomainReliabilityUploader>( | 176 return std::unique_ptr<DomainReliabilityUploader>( |
| 169 new DomainReliabilityUploaderImpl(time, url_request_context_getter)); | 177 new DomainReliabilityUploaderImpl(time, url_request_context_getter)); |
| 170 } | 178 } |
| 171 | 179 |
| 172 // static | 180 // static |
| 173 int DomainReliabilityUploader::GetURLRequestUploadDepth( | 181 int DomainReliabilityUploader::GetURLRequestUploadDepth( |
| 174 const net::URLRequest& request) { | 182 const net::URLRequest& request) { |
| 175 UploadUserData* data = static_cast<UploadUserData*>( | 183 UploadUserData* data = static_cast<UploadUserData*>( |
| 176 request.GetUserData(UploadUserData::kUserDataKey)); | 184 request.GetUserData(UploadUserData::kUserDataKey)); |
| 177 if (!data) | 185 if (!data) |
| 178 return 0; | 186 return 0; |
| 179 return data->depth(); | 187 return data->depth(); |
| 180 } | 188 } |
| 181 | 189 |
| 182 } // namespace domain_reliability | 190 } // namespace domain_reliability |
| OLD | NEW |