| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/process_singleton.h" | 5 #include "chrome/browser/process_singleton.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <signal.h> | 9 #include <signal.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 void TearDown() override { | 98 void TearDown() override { |
| 99 scoped_refptr<base::ThreadTestHelper> io_helper(new base::ThreadTestHelper( | 99 scoped_refptr<base::ThreadTestHelper> io_helper(new base::ThreadTestHelper( |
| 100 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); | 100 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); |
| 101 ASSERT_TRUE(io_helper->Run()); | 101 ASSERT_TRUE(io_helper->Run()); |
| 102 | 102 |
| 103 // Destruct the ProcessSingleton object before the IO thread so that its | 103 // Destruct the ProcessSingleton object before the IO thread so that its |
| 104 // internals are destructed properly. | 104 // internals are destructed properly. |
| 105 if (process_singleton_on_thread_) { | 105 if (process_singleton_on_thread_) { |
| 106 worker_thread_->task_runner()->PostTask( | 106 worker_thread_->task_runner()->PostTask( |
| 107 FROM_HERE, | 107 FROM_HERE, |
| 108 base::Bind(&ProcessSingletonPosixTest::DestructProcessSingleton, | 108 base::BindOnce(&ProcessSingletonPosixTest::DestructProcessSingleton, |
| 109 base::Unretained(this))); | 109 base::Unretained(this))); |
| 110 | 110 |
| 111 scoped_refptr<base::ThreadTestHelper> helper( | 111 scoped_refptr<base::ThreadTestHelper> helper( |
| 112 new base::ThreadTestHelper(worker_thread_->task_runner().get())); | 112 new base::ThreadTestHelper(worker_thread_->task_runner().get())); |
| 113 ASSERT_TRUE(helper->Run()); | 113 ASSERT_TRUE(helper->Run()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 io_thread_.Stop(); | 116 io_thread_.Stop(); |
| 117 testing::Test::TearDown(); | 117 testing::Test::TearDown(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void CreateProcessSingletonOnThread() { | 120 void CreateProcessSingletonOnThread() { |
| 121 ASSERT_EQ(NULL, worker_thread_.get()); | 121 ASSERT_EQ(NULL, worker_thread_.get()); |
| 122 worker_thread_.reset(new base::Thread("BlockingThread")); | 122 worker_thread_.reset(new base::Thread("BlockingThread")); |
| 123 worker_thread_->Start(); | 123 worker_thread_->Start(); |
| 124 | 124 |
| 125 worker_thread_->task_runner()->PostTask( | 125 worker_thread_->task_runner()->PostTask( |
| 126 FROM_HERE, | 126 FROM_HERE, |
| 127 base::Bind(&ProcessSingletonPosixTest::CreateProcessSingletonInternal, | 127 base::BindOnce( |
| 128 base::Unretained(this))); | 128 &ProcessSingletonPosixTest::CreateProcessSingletonInternal, |
| 129 base::Unretained(this))); |
| 129 | 130 |
| 130 scoped_refptr<base::ThreadTestHelper> helper( | 131 scoped_refptr<base::ThreadTestHelper> helper( |
| 131 new base::ThreadTestHelper(worker_thread_->task_runner().get())); | 132 new base::ThreadTestHelper(worker_thread_->task_runner().get())); |
| 132 ASSERT_TRUE(helper->Run()); | 133 ASSERT_TRUE(helper->Run()); |
| 133 } | 134 } |
| 134 | 135 |
| 135 TestableProcessSingleton* CreateProcessSingleton() { | 136 TestableProcessSingleton* CreateProcessSingleton() { |
| 136 return new TestableProcessSingleton(user_data_path_); | 137 return new TestableProcessSingleton(user_data_path_); |
| 137 } | 138 } |
| 138 | 139 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 found = true; | 208 found = true; |
| 208 break; | 209 break; |
| 209 } | 210 } |
| 210 } | 211 } |
| 211 ASSERT_TRUE(found); | 212 ASSERT_TRUE(found); |
| 212 ASSERT_EQ(0, kill_callbacks_); | 213 ASSERT_EQ(0, kill_callbacks_); |
| 213 } | 214 } |
| 214 | 215 |
| 215 void BlockWorkerThread() { | 216 void BlockWorkerThread() { |
| 216 worker_thread_->task_runner()->PostTask( | 217 worker_thread_->task_runner()->PostTask( |
| 217 FROM_HERE, base::Bind(&ProcessSingletonPosixTest::BlockThread, | 218 FROM_HERE, base::BindOnce(&ProcessSingletonPosixTest::BlockThread, |
| 218 base::Unretained(this))); | 219 base::Unretained(this))); |
| 219 } | 220 } |
| 220 | 221 |
| 221 void UnblockWorkerThread() { | 222 void UnblockWorkerThread() { |
| 222 wait_event_.Signal(); // Unblock the worker thread for shutdown. | 223 wait_event_.Signal(); // Unblock the worker thread for shutdown. |
| 223 signal_event_.Wait(); // Ensure thread unblocks before continuing. | 224 signal_event_.Wait(); // Ensure thread unblocks before continuing. |
| 224 } | 225 } |
| 225 | 226 |
| 226 void BlockThread() { | 227 void BlockThread() { |
| 227 wait_event_.Wait(); | 228 wait_event_.Wait(); |
| 228 signal_event_.Signal(); | 229 signal_event_.Signal(); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 // Test that if there is an existing lock file, and it's not locked, we replace | 446 // Test that if there is an existing lock file, and it's not locked, we replace |
| 446 // it. | 447 // it. |
| 447 TEST_F(ProcessSingletonPosixTest, CreateReplacesOldMacLock) { | 448 TEST_F(ProcessSingletonPosixTest, CreateReplacesOldMacLock) { |
| 448 std::unique_ptr<TestableProcessSingleton> process_singleton( | 449 std::unique_ptr<TestableProcessSingleton> process_singleton( |
| 449 CreateProcessSingleton()); | 450 CreateProcessSingleton()); |
| 450 EXPECT_EQ(0, base::WriteFile(lock_path_, "", 0)); | 451 EXPECT_EQ(0, base::WriteFile(lock_path_, "", 0)); |
| 451 EXPECT_TRUE(process_singleton->Create()); | 452 EXPECT_TRUE(process_singleton->Create()); |
| 452 VerifyFiles(); | 453 VerifyFiles(); |
| 453 } | 454 } |
| 454 #endif // defined(OS_MACOSX) | 455 #endif // defined(OS_MACOSX) |
| OLD | NEW |