| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/run_loop.h" | 5 #include "base/run_loop.h" |
| 6 #include "chrome/browser/safe_browsing/mock_permission_report_sender.h" | 6 #include "chrome/browser/safe_browsing/mock_permission_report_sender.h" |
| 7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
| 8 | 8 |
| 9 namespace safe_browsing { | 9 namespace safe_browsing { |
| 10 | 10 |
| 11 MockPermissionReportSender::MockPermissionReportSender() | 11 MockPermissionReportSender::MockPermissionReportSender() |
| 12 : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES), | 12 : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES), |
| 13 number_of_reports_(0) { | 13 number_of_reports_(0) { |
| 14 DCHECK(quit_closure_.is_null()); | 14 DCHECK(quit_closure_.is_null()); |
| 15 } | 15 } |
| 16 | 16 |
| 17 MockPermissionReportSender::~MockPermissionReportSender() { | 17 MockPermissionReportSender::~MockPermissionReportSender() { |
| 18 } | 18 } |
| 19 | 19 |
| 20 void MockPermissionReportSender::Send(const GURL& report_uri, | 20 void MockPermissionReportSender::Send(const GURL& report_uri, |
| 21 const std::string& report) { | 21 base::StringPiece content_type, |
| 22 base::StringPiece report) { |
| 22 latest_report_uri_ = report_uri; | 23 latest_report_uri_ = report_uri; |
| 23 latest_report_ = report; | 24 report.CopyToString(&latest_report_); |
| 25 content_type.CopyToString(&latest_content_type_); |
| 24 number_of_reports_++; | 26 number_of_reports_++; |
| 25 | 27 |
| 26 // BrowserThreads aren't initialized in the unittest, so don't post tasks | 28 // BrowserThreads aren't initialized in the unittest, so don't post tasks |
| 27 // to them. | 29 // to them. |
| 28 if (!content::BrowserThread::IsThreadInitialized(content::BrowserThread::UI)) | 30 if (!content::BrowserThread::IsThreadInitialized(content::BrowserThread::UI)) |
| 29 return; | 31 return; |
| 30 | 32 |
| 31 content::BrowserThread::PostTask( | 33 content::BrowserThread::PostTask( |
| 32 content::BrowserThread::UI, FROM_HERE, | 34 content::BrowserThread::UI, FROM_HERE, |
| 33 base::Bind( | 35 base::Bind( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 49 } | 51 } |
| 50 | 52 |
| 51 const GURL& MockPermissionReportSender::latest_report_uri() { | 53 const GURL& MockPermissionReportSender::latest_report_uri() { |
| 52 return latest_report_uri_; | 54 return latest_report_uri_; |
| 53 } | 55 } |
| 54 | 56 |
| 55 const std::string& MockPermissionReportSender::latest_report() { | 57 const std::string& MockPermissionReportSender::latest_report() { |
| 56 return latest_report_; | 58 return latest_report_; |
| 57 } | 59 } |
| 58 | 60 |
| 61 const std::string& MockPermissionReportSender::latest_content_type() { |
| 62 return latest_content_type_; |
| 63 } |
| 64 |
| 59 int MockPermissionReportSender::GetAndResetNumberOfReportsSent() { | 65 int MockPermissionReportSender::GetAndResetNumberOfReportsSent() { |
| 60 int new_reports = number_of_reports_; | 66 int new_reports = number_of_reports_; |
| 61 number_of_reports_ = 0; | 67 number_of_reports_ = 0; |
| 62 return new_reports; | 68 return new_reports; |
| 63 } | 69 } |
| 64 | 70 |
| 65 } // namespace safe_browsing | 71 } // namespace safe_browsing |
| OLD | NEW |