| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/profile_resetter/profile_reset_report.pb.h" | 8 #include "chrome/browser/profile_resetter/profile_reset_report.pb.h" |
| 9 #include "chrome/browser/profile_resetter/reset_report_uploader.h" | 9 #include "chrome/browser/profile_resetter/reset_report_uploader.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/storage_partition.h" |
| 11 #include "google_apis/google_api_keys.h" | 12 #include "google_apis/google_api_keys.h" |
| 12 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 13 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 14 #include "net/url_request/url_fetcher.h" | 15 #include "net/url_request/url_fetcher.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 const char kResetReportUrl[] = | 19 const char kResetReportUrl[] = |
| 19 "https://sb-ssl.google.com/safebrowsing/clientreport/chrome-reset"; | 20 "https://sb-ssl.google.com/safebrowsing/clientreport/chrome-reset"; |
| 20 | 21 |
| 21 GURL GetClientReportUrl(const std::string& report_url) { | 22 GURL GetClientReportUrl(const std::string& report_url) { |
| 22 GURL url(report_url); | 23 GURL url(report_url); |
| 23 std::string api_key = google_apis::GetAPIKey(); | 24 std::string api_key = google_apis::GetAPIKey(); |
| 24 if (!api_key.empty()) | 25 if (!api_key.empty()) |
| 25 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); | 26 url = url.Resolve("?key=" + net::EscapeQueryParamValue(api_key, true)); |
| 26 | 27 |
| 27 return url; | 28 return url; |
| 28 } | 29 } |
| 29 | 30 |
| 30 } // namespace | 31 } // namespace |
| 31 | 32 |
| 32 ResetReportUploader::ResetReportUploader(content::BrowserContext* context) | 33 ResetReportUploader::ResetReportUploader(content::BrowserContext* context) |
| 33 : url_request_context_getter_(context->GetRequestContext()) {} | 34 : url_request_context_getter_( |
| 35 content::BrowserContext::GetDefaultStoragePartition(context)-> |
| 36 GetURLRequestContext()) {} |
| 34 | 37 |
| 35 ResetReportUploader::~ResetReportUploader() {} | 38 ResetReportUploader::~ResetReportUploader() {} |
| 36 | 39 |
| 37 void ResetReportUploader::DispatchReport( | 40 void ResetReportUploader::DispatchReport( |
| 38 const reset_report::ChromeResetReport& report) { | 41 const reset_report::ChromeResetReport& report) { |
| 39 std::string request_data; | 42 std::string request_data; |
| 40 CHECK(report.SerializeToString(&request_data)); | 43 CHECK(report.SerializeToString(&request_data)); |
| 41 | 44 |
| 42 // Note fetcher will be deleted by OnURLFetchComplete. | 45 // Note fetcher will be deleted by OnURLFetchComplete. |
| 43 net::URLFetcher* fetcher = | 46 net::URLFetcher* fetcher = |
| 44 net::URLFetcher::Create(GetClientReportUrl(kResetReportUrl), | 47 net::URLFetcher::Create(GetClientReportUrl(kResetReportUrl), |
| 45 net::URLFetcher::POST, this) | 48 net::URLFetcher::POST, this) |
| 46 .release(); | 49 .release(); |
| 47 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 50 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 48 net::LOAD_DO_NOT_SAVE_COOKIES | | 51 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 49 net::LOAD_DISABLE_CACHE); | 52 net::LOAD_DISABLE_CACHE); |
| 50 fetcher->SetRequestContext(url_request_context_getter_.get()); | 53 fetcher->SetRequestContext(url_request_context_getter_.get()); |
| 51 fetcher->SetUploadData("application/octet-stream", request_data); | 54 fetcher->SetUploadData("application/octet-stream", request_data); |
| 52 fetcher->Start(); | 55 fetcher->Start(); |
| 53 } | 56 } |
| 54 | 57 |
| 55 void ResetReportUploader::OnURLFetchComplete(const net::URLFetcher* source) { | 58 void ResetReportUploader::OnURLFetchComplete(const net::URLFetcher* source) { |
| 56 delete source; | 59 delete source; |
| 57 } | 60 } |
| OLD | NEW |