Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(717)

Side by Side Diff: extensions/browser/preload_check_test_util.cc

Issue 2768723002: Update ExtensionInstallChecker to use PreloadCheck classes (Closed)
Patch Set: remove redundant DCHECKs that fail in tests Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/preload_check_test_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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()
56 : PreloadCheck(nullptr), is_async_(false), weak_ptr_factory_(this) {}
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 // TODO(michaelpg): Bind the callback directly and remove RunCallback
68 // once crbug.com/704027 is addressed.
69 base::ThreadTaskRunnerHandle::Get()->PostTask(
70 FROM_HERE,
71 base::Bind(&PreloadCheckStub::RunCallback,
72 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
73 } else {
74 std::move(callback).Run(errors_);
75 }
76 }
77
78 void PreloadCheckStub::RunCallback(ResultCallback callback) {
79 std::move(callback).Run(errors_);
80 }
81
82 base::string16 PreloadCheckStub::GetErrorMessage() const {
83 return message_;
84 }
85
50 } // namespace extensions 86 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/preload_check_test_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698