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

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

Issue 2768723002: Update ExtensionInstallChecker to use PreloadCheck classes (Closed)
Patch Set: newline 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
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(bool is_async)
56 : PreloadCheck(nullptr), is_async_(is_async), 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 base::ThreadTaskRunnerHandle::Get()->PostTask(
68 FROM_HERE,
69 base::Bind(&PreloadCheckStub::StartInternal,
Devlin 2017/03/22 15:08:46 Another option would be to do PostTask(FROM_HERE,
michaelpg 2017/03/24 02:34:17 Since I'm using a OnceCallback (new best practice)
70 weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback)));
71 } else {
72 StartInternal(std::move(callback));
73 }
74 }
75
76 void PreloadCheckStub::StartInternal(ResultCallback callback) {
Devlin 2017/03/22 15:08:46 StartInternal is a funny name for something that d
michaelpg 2017/03/24 02:34:16 RunCallback sound good?
77 std::move(callback).Run(errors_);
78 }
79
80 base::string16 PreloadCheckStub::GetErrorMessage() const {
81 return message_;
82 }
83
50 } // namespace extensions 84 } // namespace extensions
OLDNEW
« extensions/browser/preload_check_test_util.h ('K') | « 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