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

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

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