| 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 "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er_impl.h" | 5 #include "chrome/browser/safe_browsing/incident_reporting/incident_report_upload
er_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/common/safe_browsing/csd.pb.h" | 10 #include "chrome/common/safe_browsing/csd.pb.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // This is initialized here rather than in the class definition due to an | 26 // This is initialized here rather than in the class definition due to an |
| 27 // "extension" in MSVC that defies the standard. | 27 // "extension" in MSVC that defies the standard. |
| 28 // static | 28 // static |
| 29 const int IncidentReportUploaderImpl::kTestUrlFetcherId = 47; | 29 const int IncidentReportUploaderImpl::kTestUrlFetcherId = 47; |
| 30 | 30 |
| 31 IncidentReportUploaderImpl::~IncidentReportUploaderImpl() { | 31 IncidentReportUploaderImpl::~IncidentReportUploaderImpl() { |
| 32 } | 32 } |
| 33 | 33 |
| 34 // static | 34 // static |
| 35 scoped_ptr<IncidentReportUploader> IncidentReportUploaderImpl::UploadReport( | 35 std::unique_ptr<IncidentReportUploader> |
| 36 IncidentReportUploaderImpl::UploadReport( |
| 36 const OnResultCallback& callback, | 37 const OnResultCallback& callback, |
| 37 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 38 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 38 const ClientIncidentReport& report) { | 39 const ClientIncidentReport& report) { |
| 39 std::string post_data; | 40 std::string post_data; |
| 40 if (!report.SerializeToString(&post_data)) | 41 if (!report.SerializeToString(&post_data)) |
| 41 return scoped_ptr<IncidentReportUploader>(); | 42 return std::unique_ptr<IncidentReportUploader>(); |
| 42 return scoped_ptr<IncidentReportUploader>(new IncidentReportUploaderImpl( | 43 return std::unique_ptr<IncidentReportUploader>(new IncidentReportUploaderImpl( |
| 43 callback, request_context_getter, post_data)); | 44 callback, request_context_getter, post_data)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 IncidentReportUploaderImpl::IncidentReportUploaderImpl( | 47 IncidentReportUploaderImpl::IncidentReportUploaderImpl( |
| 47 const OnResultCallback& callback, | 48 const OnResultCallback& callback, |
| 48 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, | 49 const scoped_refptr<net::URLRequestContextGetter>& request_context_getter, |
| 49 const std::string& post_data) | 50 const std::string& post_data) |
| 50 : IncidentReportUploader(callback), | 51 : IncidentReportUploader(callback), |
| 51 url_fetcher_(net::URLFetcher::Create(kTestUrlFetcherId, | 52 url_fetcher_(net::URLFetcher::Create(kTestUrlFetcherId, |
| 52 GetIncidentReportUrl(), | 53 GetIncidentReportUrl(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 66 GURL url(kSbIncidentReportUrl); | 67 GURL url(kSbIncidentReportUrl); |
| 67 std::string api_key(google_apis::GetAPIKey()); | 68 std::string api_key(google_apis::GetAPIKey()); |
| 68 if (api_key.empty()) | 69 if (api_key.empty()) |
| 69 return url; | 70 return url; |
| 70 return url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 71 return url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 71 } | 72 } |
| 72 | 73 |
| 73 void IncidentReportUploaderImpl::OnURLFetchComplete( | 74 void IncidentReportUploaderImpl::OnURLFetchComplete( |
| 74 const net::URLFetcher* source) { | 75 const net::URLFetcher* source) { |
| 75 // Take ownership of the fetcher in this scope (source == url_fetcher_). | 76 // Take ownership of the fetcher in this scope (source == url_fetcher_). |
| 76 scoped_ptr<net::URLFetcher> url_fetcher(std::move(url_fetcher_)); | 77 std::unique_ptr<net::URLFetcher> url_fetcher(std::move(url_fetcher_)); |
| 77 | 78 |
| 78 UMA_HISTOGRAM_TIMES("SBIRS.ReportUploadTime", | 79 UMA_HISTOGRAM_TIMES("SBIRS.ReportUploadTime", |
| 79 base::TimeTicks::Now() - time_begin_); | 80 base::TimeTicks::Now() - time_begin_); |
| 80 | 81 |
| 81 Result result = UPLOAD_REQUEST_FAILED; | 82 Result result = UPLOAD_REQUEST_FAILED; |
| 82 scoped_ptr<ClientIncidentResponse> response; | 83 std::unique_ptr<ClientIncidentResponse> response; |
| 83 | 84 |
| 84 if (source->GetStatus().is_success() && | 85 if (source->GetStatus().is_success() && |
| 85 source->GetResponseCode() == net::HTTP_OK) { | 86 source->GetResponseCode() == net::HTTP_OK) { |
| 86 std::string data; | 87 std::string data; |
| 87 source->GetResponseAsString(&data); | 88 source->GetResponseAsString(&data); |
| 88 response.reset(new ClientIncidentResponse()); | 89 response.reset(new ClientIncidentResponse()); |
| 89 if (!response->ParseFromString(data)) { | 90 if (!response->ParseFromString(data)) { |
| 90 response.reset(); | 91 response.reset(); |
| 91 result = UPLOAD_INVALID_RESPONSE; | 92 result = UPLOAD_INVALID_RESPONSE; |
| 92 } else { | 93 } else { |
| 93 result = UPLOAD_SUCCESS; | 94 result = UPLOAD_SUCCESS; |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 // Callbacks have a tendency to delete the uploader, so no touching anything | 97 // Callbacks have a tendency to delete the uploader, so no touching anything |
| 97 // after this. | 98 // after this. |
| 98 callback_.Run(result, std::move(response)); | 99 callback_.Run(result, std::move(response)); |
| 99 } | 100 } |
| 100 | 101 |
| 101 } // namespace safe_browsing | 102 } // namespace safe_browsing |
| OLD | NEW |