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

Side by Side Diff: chrome/browser/browser_process_impl_unittest.cc

Issue 2675383002: Use TaskScheduler instead of WorkerPool in tcp_socket_posix.cc. (Closed)
Patch Set: add ScopedTaskScheduler Created 3 years, 10 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 | « no previous file | net/socket/tcp_socket_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/browser_process_impl.h" 5 #include "chrome/browser/browser_process_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/metrics/user_metrics.h" 12 #include "base/metrics/user_metrics.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/test/scoped_task_scheduler.h"
13 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
14 #include "build/build_config.h" 16 #include "build/build_config.h"
15 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h" 18 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache_factory.h"
17 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
18 #include "content/public/test/test_browser_thread.h" 20 #include "content/public/test/test_browser_thread.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 class BrowserProcessImplTest : public ::testing::Test { 23 class BrowserProcessImplTest : public ::testing::Test {
22 protected: 24 protected:
(...skipping 16 matching lines...) Expand all
39 g_browser_process = nullptr; 41 g_browser_process = nullptr;
40 browser_process_impl_.reset(); 42 browser_process_impl_.reset();
41 // Restore the original browser process. 43 // Restore the original browser process.
42 g_browser_process = stashed_browser_process_; 44 g_browser_process = stashed_browser_process_;
43 } 45 }
44 46
45 // Creates the secondary threads (all threads except the UI thread). 47 // Creates the secondary threads (all threads except the UI thread).
46 // The UI thread needs to be alive while BrowserProcessImpl is alive, and is 48 // The UI thread needs to be alive while BrowserProcessImpl is alive, and is
47 // managed separately. 49 // managed separately.
48 void StartSecondaryThreads() { 50 void StartSecondaryThreads() {
51 scoped_task_scheduler_ = base::MakeUnique<base::test::ScopedTaskScheduler>(
52 base::MessageLoop::current());
49 file_thread_->StartIOThread(); 53 file_thread_->StartIOThread();
50 io_thread_->StartIOThread(); 54 io_thread_->StartIOThread();
51 } 55 }
52 56
53 // Destroys the secondary threads (all threads except the UI thread). 57 // Destroys the secondary threads (all threads except the UI thread).
54 // The UI thread needs to be alive while BrowserProcessImpl is alive, and is 58 // The UI thread needs to be alive while BrowserProcessImpl is alive, and is
55 // managed separately. 59 // managed separately.
56 void DestroySecondaryThreads() { 60 void DestroySecondaryThreads() {
57 // Spin the runloop to allow posted tasks to be processed. 61 // Spin the runloop to allow posted tasks to be processed.
58 base::RunLoop().RunUntilIdle(); 62 base::RunLoop().RunUntilIdle();
59 io_thread_.reset(); 63 io_thread_.reset();
60 base::RunLoop().RunUntilIdle(); 64 base::RunLoop().RunUntilIdle();
61 file_thread_.reset(); 65 file_thread_.reset();
62 base::RunLoop().RunUntilIdle(); 66 base::RunLoop().RunUntilIdle();
67 scoped_task_scheduler_.reset();
63 } 68 }
64 69
65 BrowserProcessImpl* browser_process_impl() { 70 BrowserProcessImpl* browser_process_impl() {
66 return browser_process_impl_.get(); 71 return browser_process_impl_.get();
67 } 72 }
68 73
69 private: 74 private:
70 BrowserProcess* stashed_browser_process_; 75 BrowserProcess* stashed_browser_process_;
71 base::MessageLoop loop_; 76 base::MessageLoop loop_;
72 content::TestBrowserThread ui_thread_; 77 content::TestBrowserThread ui_thread_;
78 std::unique_ptr<base::test::ScopedTaskScheduler> scoped_task_scheduler_;
73 std::unique_ptr<content::TestBrowserThread> file_thread_; 79 std::unique_ptr<content::TestBrowserThread> file_thread_;
74 std::unique_ptr<content::TestBrowserThread> io_thread_; 80 std::unique_ptr<content::TestBrowserThread> io_thread_;
75 base::CommandLine command_line_; 81 base::CommandLine command_line_;
76 std::unique_ptr<BrowserProcessImpl> browser_process_impl_; 82 std::unique_ptr<BrowserProcessImpl> browser_process_impl_;
77 }; 83 };
78 84
79 85
80 // Android does not have the NTPResourceCache. 86 // Android does not have the NTPResourceCache.
81 // This test crashes on ChromeOS because it relies on NetworkHandler which 87 // This test crashes on ChromeOS because it relies on NetworkHandler which
82 // cannot be used in test. 88 // cannot be used in test.
(...skipping 12 matching lines...) Expand all
95 // Pass ownership to the ProfileManager so that it manages the destruction. 101 // Pass ownership to the ProfileManager so that it manages the destruction.
96 browser_process_impl()->profile_manager()->RegisterTestingProfile( 102 browser_process_impl()->profile_manager()->RegisterTestingProfile(
97 profile.release(), false, false); 103 profile.release(), false, false);
98 104
99 // Tear down the BrowserProcessImpl and the threads. 105 // Tear down the BrowserProcessImpl and the threads.
100 browser_process_impl()->StartTearDown(); 106 browser_process_impl()->StartTearDown();
101 DestroySecondaryThreads(); 107 DestroySecondaryThreads();
102 browser_process_impl()->PostDestroyThreads(); 108 browser_process_impl()->PostDestroyThreads();
103 } 109 }
104 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 110 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « no previous file | net/socket/tcp_socket_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698