OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/test/ash_test_environment.h" | |
6 | |
7 #include "ash/test/ash_test_views_delegate.h" | |
8 #include "base/memory/ptr_util.h" | |
9 #include "base/message_loop/message_loop.h" | |
10 #include "base/run_loop.h" | |
11 #include "base/threading/sequenced_worker_pool.h" | |
12 | |
13 namespace ash { | |
14 namespace test { | |
15 namespace { | |
16 | |
17 class AshTestEnvironmentDefault : public AshTestEnvironment { | |
18 public: | |
19 AshTestEnvironmentDefault() {} | |
20 | |
21 ~AshTestEnvironmentDefault() override { | |
22 base::RunLoop().RunUntilIdle(); | |
23 if (blocking_pool_) { | |
24 blocking_pool_->FlushForTesting(); | |
25 blocking_pool_->Shutdown(); | |
26 blocking_pool_ = nullptr; | |
27 } | |
28 base::RunLoop().RunUntilIdle(); | |
29 } | |
30 | |
31 // AshTestEnvironment: | |
32 base::SequencedWorkerPool* GetBlockingPool() override { | |
33 if (!blocking_pool_) { | |
34 const size_t kMaxNumberThreads = 3u; // Matches that of content. | |
35 blocking_pool_ = new base::SequencedWorkerPool( | |
36 kMaxNumberThreads, "AshBlocking", base::TaskPriority::USER_VISIBLE); | |
37 } | |
38 return blocking_pool_.get(); | |
39 } | |
40 std::unique_ptr<views::ViewsDelegate> CreateViewsDelegate() override { | |
41 return base::MakeUnique<AshTestViewsDelegate>(); | |
42 } | |
43 | |
44 private: | |
45 base::MessageLoopForUI message_loop_; | |
46 scoped_refptr<base::SequencedWorkerPool> blocking_pool_; | |
47 | |
48 DISALLOW_COPY_AND_ASSIGN(AshTestEnvironmentDefault); | |
49 }; | |
50 | |
51 } // namespace | |
52 | |
53 // static | |
54 std::unique_ptr<AshTestEnvironment> AshTestEnvironment::Create() { | |
55 return base::MakeUnique<AshTestEnvironmentDefault>(); | |
56 } | |
57 | |
58 } // namespace test | |
59 } // namespace ash | |
OLD | NEW |