OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "extensions/browser/preload_check_test_util.h" | 5 #include "extensions/browser/preload_check_test_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 } | 29 } |
30 | 30 |
31 void PreloadCheckRunner::Run(PreloadCheck* check) { | 31 void PreloadCheckRunner::Run(PreloadCheck* check) { |
32 check->Start(GetCallback()); | 32 check->Start(GetCallback()); |
33 } | 33 } |
34 | 34 |
35 void PreloadCheckRunner::RunUntilComplete(PreloadCheck* check) { | 35 void PreloadCheckRunner::RunUntilComplete(PreloadCheck* check) { |
36 Run(check); | 36 Run(check); |
37 ASSERT_FALSE(called_); | 37 ASSERT_FALSE(called_); |
38 | 38 |
39 run_loop_ = base::MakeUnique<base::RunLoop>(); | 39 WaitForComplete(); |
Devlin
2017/04/06 02:03:53
Just a note - currently this is incompatible with
michaelpg
2017/04/06 22:31:16
RunUntilComplete requires the check to be async, t
| |
40 run_loop_->Run(); | |
41 ASSERT_TRUE(called_); | 40 ASSERT_TRUE(called_); |
42 } | 41 } |
43 | 42 |
44 PreloadCheck::ResultCallback PreloadCheckRunner::GetCallback() { | 43 PreloadCheck::ResultCallback PreloadCheckRunner::GetCallback() { |
45 return base::Bind(&PreloadCheckRunner::OnCheckComplete, | 44 return base::Bind(&PreloadCheckRunner::OnCheckComplete, |
46 base::Unretained(this)); | 45 base::Unretained(this)); |
47 } | 46 } |
48 | 47 |
49 void PreloadCheckRunner::WaitForIdle() { | 48 void PreloadCheckRunner::WaitForIdle() { |
50 run_loop_ = base::MakeUnique<base::RunLoop>(); | 49 run_loop_ = base::MakeUnique<base::RunLoop>(); |
51 run_loop_->RunUntilIdle(); | 50 run_loop_->RunUntilIdle(); |
52 } | 51 } |
53 | 52 |
53 void PreloadCheckRunner::WaitForComplete() { | |
54 run_loop_ = base::MakeUnique<base::RunLoop>(); | |
55 run_loop_->Run(); | |
56 } | |
57 | |
54 // PreloadCheckStub: | 58 // PreloadCheckStub: |
55 PreloadCheckStub::PreloadCheckStub() | 59 PreloadCheckStub::PreloadCheckStub(const Errors& errors) |
56 : PreloadCheck(nullptr), is_async_(false), weak_ptr_factory_(this) {} | 60 : PreloadCheck(nullptr), errors_(errors), weak_ptr_factory_(this) {} |
57 | 61 |
58 PreloadCheckStub::~PreloadCheckStub() {} | 62 PreloadCheckStub::~PreloadCheckStub() {} |
59 | 63 |
60 void PreloadCheckStub::AddError(Error error) { | |
61 errors_.insert(error); | |
62 } | |
63 | |
64 void PreloadCheckStub::Start(ResultCallback callback) { | 64 void PreloadCheckStub::Start(ResultCallback callback) { |
65 DCHECK(!callback.is_null()); | 65 DCHECK(!callback.is_null()); |
66 started_ = true; | |
66 if (is_async_) { | 67 if (is_async_) { |
67 // TODO(michaelpg): Bind the callback directly and remove RunCallback | 68 // TODO(michaelpg): Bind the callback directly and remove RunCallback |
68 // once crbug.com/704027 is addressed. | 69 // once crbug.com/704027 is addressed. |
69 base::ThreadTaskRunnerHandle::Get()->PostTask( | 70 base::ThreadTaskRunnerHandle::Get()->PostTask( |
70 FROM_HERE, | 71 FROM_HERE, |
71 base::Bind(&PreloadCheckStub::RunCallback, | 72 base::Bind(&PreloadCheckStub::RunCallback, |
72 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); | 73 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); |
73 } else { | 74 } else { |
74 std::move(callback).Run(errors_); | 75 std::move(callback).Run(errors_); |
75 } | 76 } |
76 } | 77 } |
77 | 78 |
78 void PreloadCheckStub::RunCallback(ResultCallback callback) { | 79 void PreloadCheckStub::RunCallback(ResultCallback callback) { |
79 std::move(callback).Run(errors_); | 80 std::move(callback).Run(errors_); |
80 } | 81 } |
81 | 82 |
82 base::string16 PreloadCheckStub::GetErrorMessage() const { | |
83 return message_; | |
84 } | |
85 | |
86 } // namespace extensions | 83 } // namespace extensions |
OLD | NEW |