| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/service_process_util.h" | 5 #include "chrome/common/service_process_util.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 10 #include "base/location.h" | 12 #include "base/location.h" |
| 11 #include "base/process/kill.h" | 13 #include "base/process/kill.h" |
| 12 #include "base/process/launch.h" | 14 #include "base/process/launch.h" |
| 13 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 15 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 16 | 18 |
| 17 #if !defined(OS_MACOSX) | 19 #if !defined(OS_MACOSX) |
| 18 #include "base/at_exit.h" | 20 #include "base/at_exit.h" |
| 19 #include "base/memory/scoped_ptr.h" | |
| 20 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/test/multiprocess_test.h" | 23 #include "base/test/multiprocess_test.h" |
| 23 #include "base/test/test_timeouts.h" | 24 #include "base/test/test_timeouts.h" |
| 24 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "components/version_info/version_info.h" | 27 #include "components/version_info/version_info.h" |
| 27 #include "content/public/common/content_switches.h" | 28 #include "content/public/common/content_switches.h" |
| 28 #include "testing/multiprocess_func_list.h" | 29 #include "testing/multiprocess_func_list.h" |
| 29 | 30 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 ASSERT_TRUE(state.Initialize()); | 120 ASSERT_TRUE(state.Initialize()); |
| 120 ASSERT_TRUE(state.SignalReady(IOMessageLoopProxy(), base::Closure())); | 121 ASSERT_TRUE(state.SignalReady(IOMessageLoopProxy(), base::Closure())); |
| 121 LaunchAndWait("ServiceProcessStateTestReadyTrue"); | 122 LaunchAndWait("ServiceProcessStateTestReadyTrue"); |
| 122 state.SignalStopped(); | 123 state.SignalStopped(); |
| 123 LaunchAndWait("ServiceProcessStateTestReadyFalse"); | 124 LaunchAndWait("ServiceProcessStateTestReadyFalse"); |
| 124 } | 125 } |
| 125 | 126 |
| 126 TEST_F(ServiceProcessStateTest, AutoRun) { | 127 TEST_F(ServiceProcessStateTest, AutoRun) { |
| 127 ServiceProcessState state; | 128 ServiceProcessState state; |
| 128 ASSERT_TRUE(state.AddToAutoRun()); | 129 ASSERT_TRUE(state.AddToAutoRun()); |
| 129 scoped_ptr<base::CommandLine> autorun_command_line; | 130 std::unique_ptr<base::CommandLine> autorun_command_line; |
| 130 #if defined(OS_WIN) | 131 #if defined(OS_WIN) |
| 131 std::string value_name = GetServiceProcessScopedName("_service_run"); | 132 std::string value_name = GetServiceProcessScopedName("_service_run"); |
| 132 base::string16 value; | 133 base::string16 value; |
| 133 EXPECT_TRUE(base::win::ReadCommandFromAutoRun(HKEY_CURRENT_USER, | 134 EXPECT_TRUE(base::win::ReadCommandFromAutoRun(HKEY_CURRENT_USER, |
| 134 base::UTF8ToWide(value_name), | 135 base::UTF8ToWide(value_name), |
| 135 &value)); | 136 &value)); |
| 136 autorun_command_line.reset( | 137 autorun_command_line.reset( |
| 137 new base::CommandLine(base::CommandLine::FromString(value))); | 138 new base::CommandLine(base::CommandLine::FromString(value))); |
| 138 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | 139 #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
| 139 #if defined(GOOGLE_CHROME_BUILD) | 140 #if defined(GOOGLE_CHROME_BUILD) |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 base::SingleThreadTaskRunner* GetIOMessageLoopProxy() { | 294 base::SingleThreadTaskRunner* GetIOMessageLoopProxy() { |
| 294 return io_thread_.task_runner().get(); | 295 return io_thread_.task_runner().get(); |
| 295 } | 296 } |
| 296 void Run() { loop_.Run(); } | 297 void Run() { loop_.Run(); } |
| 297 | 298 |
| 298 private: | 299 private: |
| 299 base::ScopedTempDir temp_dir_; | 300 base::ScopedTempDir temp_dir_; |
| 300 base::MessageLoopForUI loop_; | 301 base::MessageLoopForUI loop_; |
| 301 base::Thread io_thread_; | 302 base::Thread io_thread_; |
| 302 base::FilePath executable_path_, bundle_path_; | 303 base::FilePath executable_path_, bundle_path_; |
| 303 scoped_ptr<MockLaunchd> mock_launchd_; | 304 std::unique_ptr<MockLaunchd> mock_launchd_; |
| 304 scoped_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; | 305 std::unique_ptr<Launchd::ScopedInstance> scoped_launchd_instance_; |
| 305 ServiceProcessState service_process_state_; | 306 ServiceProcessState service_process_state_; |
| 306 }; | 307 }; |
| 307 | 308 |
| 308 void DeleteFunc(const base::FilePath& file) { | 309 void DeleteFunc(const base::FilePath& file) { |
| 309 EXPECT_TRUE(base::DeleteFile(file, true)); | 310 EXPECT_TRUE(base::DeleteFile(file, true)); |
| 310 } | 311 } |
| 311 | 312 |
| 312 void MoveFunc(const base::FilePath& from, const base::FilePath& to) { | 313 void MoveFunc(const base::FilePath& from, const base::FilePath& to) { |
| 313 EXPECT_TRUE(base::Move(from, to)); | 314 EXPECT_TRUE(base::Move(from, to)); |
| 314 } | 315 } |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 ScopedAttributesRestorer restorer(bundle_path(), 0777); | 420 ScopedAttributesRestorer restorer(bundle_path(), 0777); |
| 420 GetIOMessageLoopProxy()->PostTask( | 421 GetIOMessageLoopProxy()->PostTask( |
| 421 FROM_HERE, | 422 FROM_HERE, |
| 422 base::Bind(&ChangeAttr, bundle_path(), 0222)); | 423 base::Bind(&ChangeAttr, bundle_path(), 0222)); |
| 423 Run(); | 424 Run(); |
| 424 ASSERT_TRUE(mock_launchd()->remove_called()); | 425 ASSERT_TRUE(mock_launchd()->remove_called()); |
| 425 ASSERT_TRUE(mock_launchd()->delete_called()); | 426 ASSERT_TRUE(mock_launchd()->delete_called()); |
| 426 } | 427 } |
| 427 | 428 |
| 428 #endif // !OS_MACOSX | 429 #endif // !OS_MACOSX |
| OLD | NEW |