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