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" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "extensions/common/extension.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
13 | 16 |
14 namespace extensions { | 17 namespace extensions { |
15 | 18 |
| 19 // PreloadCheckRunner: |
16 PreloadCheckRunner::PreloadCheckRunner() : called_(false) {} | 20 PreloadCheckRunner::PreloadCheckRunner() : called_(false) {} |
17 PreloadCheckRunner::~PreloadCheckRunner() {} | 21 PreloadCheckRunner::~PreloadCheckRunner() {} |
18 | 22 |
19 void PreloadCheckRunner::OnCheckComplete(PreloadCheck::Errors errors) { | 23 void PreloadCheckRunner::OnCheckComplete(PreloadCheck::Errors errors) { |
20 ASSERT_FALSE(called_); | 24 ASSERT_FALSE(called_); |
21 called_ = true; | 25 called_ = true; |
22 errors_ = errors; | 26 errors_ = errors; |
23 if (run_loop_) | 27 if (run_loop_) |
24 run_loop_->Quit(); | 28 run_loop_->Quit(); |
25 } | 29 } |
(...skipping 14 matching lines...) Expand all Loading... |
40 PreloadCheck::ResultCallback PreloadCheckRunner::GetCallback() { | 44 PreloadCheck::ResultCallback PreloadCheckRunner::GetCallback() { |
41 return base::Bind(&PreloadCheckRunner::OnCheckComplete, | 45 return base::Bind(&PreloadCheckRunner::OnCheckComplete, |
42 base::Unretained(this)); | 46 base::Unretained(this)); |
43 } | 47 } |
44 | 48 |
45 void PreloadCheckRunner::WaitForIdle() { | 49 void PreloadCheckRunner::WaitForIdle() { |
46 run_loop_ = base::MakeUnique<base::RunLoop>(); | 50 run_loop_ = base::MakeUnique<base::RunLoop>(); |
47 run_loop_->RunUntilIdle(); | 51 run_loop_->RunUntilIdle(); |
48 } | 52 } |
49 | 53 |
| 54 // PreloadCheckStub: |
| 55 PreloadCheckStub::PreloadCheckStub(bool is_async) |
| 56 : PreloadCheck(nullptr), is_async_(is_async) {} |
| 57 |
| 58 PreloadCheckStub::~PreloadCheckStub() {} |
| 59 |
| 60 void PreloadCheckStub::AddError(Error error) { |
| 61 errors_.insert(error); |
| 62 } |
| 63 |
| 64 void PreloadCheckStub::Start(ResultCallback callback) { |
| 65 DCHECK(!callback.is_null()); |
| 66 if (is_async_) { |
| 67 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 68 FROM_HERE, base::Bind(&PreloadCheckStub::StartInternal, |
| 69 base::Unretained(this), base::Passed(&callback))); |
| 70 } else { |
| 71 StartInternal(std::move(callback)); |
| 72 } |
| 73 } |
| 74 |
| 75 void PreloadCheckStub::StartInternal(ResultCallback callback) { |
| 76 std::move(callback).Run(errors_); |
| 77 } |
| 78 |
| 79 base::string16 PreloadCheckStub::GetErrorMessage() const { |
| 80 return message_; |
| 81 } |
| 82 |
50 } // namespace extensions | 83 } // namespace extensions |
OLD | NEW |