Chromium Code Reviews| 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 "chrome/browser/safe_browsing/mock_permission_report_sender.h" | 5 #include "chrome/browser/safe_browsing/mock_permission_report_sender.h" |
| 6 | 6 |
| 7 #include "base/run_loop.h" | |
| 8 | |
| 7 namespace safe_browsing { | 9 namespace safe_browsing { |
| 8 | 10 |
| 9 MockPermissionReportSender::MockPermissionReportSender() | 11 MockPermissionReportSender::MockPermissionReportSender() |
| 10 : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) { | 12 : net::ReportSender(nullptr, DO_NOT_SEND_COOKIES) { |
| 13 DCHECK(thread_checker_.CalledOnValidThread()); | |
|
Sam McNally
2016/08/17 07:52:38
Using a ThreadChecker in a class that's shared amo
kcarattini
2016/08/19 03:59:46
Done.
| |
| 11 number_of_reports_ = 0; | 14 number_of_reports_ = 0; |
| 12 } | 15 } |
| 13 | 16 |
| 14 MockPermissionReportSender::~MockPermissionReportSender() {} | 17 MockPermissionReportSender::~MockPermissionReportSender() { |
| 18 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 19 } | |
| 15 | 20 |
| 16 void MockPermissionReportSender::Send(const GURL& report_uri, | 21 void MockPermissionReportSender::Send(const GURL& report_uri, |
| 17 const std::string& report) { | 22 const std::string& report) { |
| 23 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 24 base::RunLoop run_loop; | |
| 25 quit_closure_ = run_loop.QuitClosure(); | |
| 26 content::BrowserThread::PostTaskAndReply( | |
|
Sam McNally
2016/08/17 07:52:38
You don't need the RunLoop here. The IO thread doe
kcarattini
2016/08/19 03:59:46
Done.
| |
| 27 content::BrowserThread::UI, FROM_HERE, | |
| 28 base::Bind( | |
| 29 &MockPermissionReportSender::SetReportOnUIThread, | |
| 30 base::Unretained(this)), | |
| 31 run_loop.QuitClosure()); | |
| 32 run_loop.Run(); | |
| 33 } | |
| 34 | |
| 35 // UI thread | |
| 36 void MockReportSender::WaitForReportSet() { | |
| 37 report_set_ = false; | |
|
Sam McNally
2016/08/17 07:52:38
I don't think |report_set_| is needed.
kcarattini
2016/08/19 03:59:46
Done. I still don't quite understand how this is s
kcarattini
2016/08/22 05:09:05
I've figured this out now, thanks!
| |
| 38 base::RunLoop run_loop; | |
| 39 quit_closure_ = run_loop.QuitClosure(); | |
| 40 run_loop.Run(); | |
| 41 } | |
| 42 | |
| 43 // UI thread | |
| 44 void MockReportSender::SetReportOnUIThread() { | |
| 18 latest_report_uri_ = report_uri; | 45 latest_report_uri_ = report_uri; |
| 19 latest_report_ = report; | 46 latest_report_ = report; |
| 20 number_of_reports_++; | 47 number_of_reports_++; |
| 48 | |
| 49 report_set_ = true; | |
| 50 NotifyReportSet(); | |
| 51 } | |
| 52 | |
| 53 // UI thread | |
| 54 void MockReportSender::NotifyReportSet() { | |
| 55 if (!quit_closure_.is_null() && report_set_) { | |
| 56 quit_closure_.Run(); | |
| 57 quit_closure_.Reset(); | |
| 58 } | |
| 21 } | 59 } |
| 22 | 60 |
| 23 const GURL& MockPermissionReportSender::latest_report_uri() { | 61 const GURL& MockPermissionReportSender::latest_report_uri() { |
| 62 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 24 return latest_report_uri_; | 63 return latest_report_uri_; |
| 25 } | 64 } |
| 26 | 65 |
| 27 const std::string& MockPermissionReportSender::latest_report() { | 66 const std::string& MockPermissionReportSender::latest_report() { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 28 return latest_report_; | 68 return latest_report_; |
| 29 } | 69 } |
| 30 | 70 |
| 31 int MockPermissionReportSender::GetAndResetNumberOfReportsSent() { | 71 int MockPermissionReportSender::GetAndResetNumberOfReportsSent() { |
| 72 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 73 | |
| 32 int new_reports = number_of_reports_; | 74 int new_reports = number_of_reports_; |
| 33 number_of_reports_ = 0; | 75 number_of_reports_ = 0; |
| 34 return new_reports; | 76 return new_reports; |
| 35 } | 77 } |
| 36 | 78 |
| 37 } // namespace safe_browsing | 79 } // namespace safe_browsing |
| OLD | NEW |