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

Unified Diff: chrome/browser/safe_browsing/incident_report_uploader_impl.cc

Issue 470213002: Moving all the incident reporting stuff to a common folder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@binsign
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/incident_report_uploader_impl.cc
diff --git a/chrome/browser/safe_browsing/incident_report_uploader_impl.cc b/chrome/browser/safe_browsing/incident_report_uploader_impl.cc
deleted file mode 100644
index 287356d85cc7e18c8b8ff9b9dfd39cb7823034f0..0000000000000000000000000000000000000000
--- a/chrome/browser/safe_browsing/incident_report_uploader_impl.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/safe_browsing/incident_report_uploader_impl.h"
-
-#include "base/metrics/histogram.h"
-#include "chrome/common/safe_browsing/csd.pb.h"
-#include "google_apis/google_api_keys.h"
-#include "net/base/escape.h"
-#include "net/base/load_flags.h"
-#include "net/http/http_status_code.h"
-#include "net/url_request/url_fetcher.h"
-
-namespace safe_browsing {
-
-namespace {
-
-const char kSbIncidentReportUrl[] =
- "https://sb-ssl.google.com/safebrowsing/clientreport/incident";
-
-} // namespace
-
-// This is initialized here rather than in the class definition due to an
-// "extension" in MSVC that defies the standard.
-// static
-const int IncidentReportUploaderImpl::kTestUrlFetcherId = 47;
-
-IncidentReportUploaderImpl::~IncidentReportUploaderImpl() {
-}
-
-// static
-scoped_ptr<IncidentReportUploader> IncidentReportUploaderImpl::UploadReport(
- const OnResultCallback& callback,
- const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
- const ClientIncidentReport& report) {
- std::string post_data;
- if (!report.SerializeToString(&post_data))
- return scoped_ptr<IncidentReportUploader>();
- return scoped_ptr<IncidentReportUploader>(new IncidentReportUploaderImpl(
- callback, request_context_getter, post_data));
-}
-
-IncidentReportUploaderImpl::IncidentReportUploaderImpl(
- const OnResultCallback& callback,
- const scoped_refptr<net::URLRequestContextGetter>& request_context_getter,
- const std::string& post_data)
- : IncidentReportUploader(callback),
- url_fetcher_(net::URLFetcher::Create(kTestUrlFetcherId,
- GetIncidentReportUrl(),
- net::URLFetcher::POST,
- this)),
- time_begin_(base::TimeTicks::Now()) {
- UMA_HISTOGRAM_COUNTS("SBIRS.ReportPayloadSize", post_data.size());
- url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE);
- url_fetcher_->SetAutomaticallyRetryOn5xx(false);
- url_fetcher_->SetRequestContext(request_context_getter.get());
- url_fetcher_->SetUploadData("application/octet-stream", post_data);
- url_fetcher_->Start();
-}
-
-// static
-GURL IncidentReportUploaderImpl::GetIncidentReportUrl() {
- GURL url(kSbIncidentReportUrl);
- std::string api_key(google_apis::GetAPIKey());
- if (api_key.empty())
- return url;
- return url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true));
-}
-
-void IncidentReportUploaderImpl::OnURLFetchComplete(
- const net::URLFetcher* source) {
- // Take ownership of the fetcher in this scope (source == url_fetcher_).
- scoped_ptr<net::URLFetcher> url_fetcher(url_fetcher_.Pass());
-
- UMA_HISTOGRAM_TIMES("SBIRS.ReportUploadTime",
- base::TimeTicks::Now() - time_begin_);
-
- Result result = UPLOAD_REQUEST_FAILED;
- scoped_ptr<ClientIncidentResponse> response;
-
- if (source->GetStatus().is_success() &&
- source->GetResponseCode() == net::HTTP_OK) {
- std::string data;
- source->GetResponseAsString(&data);
- response.reset(new ClientIncidentResponse());
- if (!response->ParseFromString(data)) {
- response.reset();
- result = UPLOAD_INVALID_RESPONSE;
- } else {
- result = UPLOAD_SUCCESS;
- }
- }
- // Callbacks have a tendency to delete the uploader, so no touching anything
- // after this.
- callback_.Run(result, response.Pass());
-}
-
-} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698