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/browser/service_process/service_process_control.h" | 5 #include "chrome/browser/service_process/service_process_control.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 this), | 48 this), |
49 base::Bind( | 49 base::Bind( |
50 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, | 50 &ServiceProcessControlBrowserTest::ProcessControlLaunchFailed, |
51 this)); | 51 this)); |
52 | 52 |
53 // Then run the message loop to keep things running. | 53 // Then run the message loop to keep things running. |
54 content::RunMessageLoop(); | 54 content::RunMessageLoop(); |
55 } | 55 } |
56 | 56 |
57 static void QuitMessageLoop() { | 57 static void QuitMessageLoop() { |
58 base::MessageLoop::current()->Quit(); | 58 base::MessageLoop::current()->QuitWhenIdle(); |
59 } | 59 } |
60 | 60 |
61 static void CloudPrintInfoCallback( | 61 static void CloudPrintInfoCallback( |
62 const cloud_print::CloudPrintProxyInfo& proxy_info) { | 62 const cloud_print::CloudPrintProxyInfo& proxy_info) { |
63 QuitMessageLoop(); | 63 QuitMessageLoop(); |
64 } | 64 } |
65 | 65 |
66 void Disconnect() { | 66 void Disconnect() { |
67 // This will close the IPC connection. | 67 // This will close the IPC connection. |
68 ServiceProcessControl::GetInstance()->Disconnect(); | 68 ServiceProcessControl::GetInstance()->Disconnect(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 base::Process::OpenWithAccess(service_pid, | 104 base::Process::OpenWithAccess(service_pid, |
105 SYNCHRONIZE | PROCESS_QUERY_INFORMATION); | 105 SYNCHRONIZE | PROCESS_QUERY_INFORMATION); |
106 #else | 106 #else |
107 service_process_ = base::Process::Open(service_pid); | 107 service_process_ = base::Process::Open(service_pid); |
108 #endif | 108 #endif |
109 EXPECT_TRUE(service_process_.IsValid()); | 109 EXPECT_TRUE(service_process_.IsValid()); |
110 // Quit the current message. Post a QuitTask instead of just calling Quit() | 110 // Quit the current message. Post a QuitTask instead of just calling Quit() |
111 // because this can get invoked in the context of a Launch() call and we | 111 // because this can get invoked in the context of a Launch() call and we |
112 // may not be in Run() yet. | 112 // may not be in Run() yet. |
113 base::ThreadTaskRunnerHandle::Get()->PostTask( | 113 base::ThreadTaskRunnerHandle::Get()->PostTask( |
114 FROM_HERE, base::MessageLoop::QuitClosure()); | 114 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
115 } | 115 } |
116 | 116 |
117 void ProcessControlLaunchFailed() { | 117 void ProcessControlLaunchFailed() { |
118 ADD_FAILURE(); | 118 ADD_FAILURE(); |
119 // Quit the current message. | 119 // Quit the current message. |
120 base::ThreadTaskRunnerHandle::Get()->PostTask( | 120 base::ThreadTaskRunnerHandle::Get()->PostTask( |
121 FROM_HERE, base::MessageLoop::QuitClosure()); | 121 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 base::Process service_process_; | 125 base::Process service_process_; |
126 }; | 126 }; |
127 | 127 |
128 class RealServiceProcessControlBrowserTest | 128 class RealServiceProcessControlBrowserTest |
129 : public ServiceProcessControlBrowserTest { | 129 : public ServiceProcessControlBrowserTest { |
130 public: | 130 public: |
131 void SetUpCommandLine(base::CommandLine* command_line) override { | 131 void SetUpCommandLine(base::CommandLine* command_line) override { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); | 193 ASSERT_TRUE(ServiceProcessControl::GetInstance()->IsConnected()); |
194 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( | 194 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetCloudPrintProxyInfo( |
195 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); | 195 base::Bind(&ServiceProcessControlBrowserTest::CloudPrintInfoCallback))); |
196 content::RunMessageLoop(); | 196 content::RunMessageLoop(); |
197 } | 197 } |
198 | 198 |
199 static void DecrementUntilZero(int* count) { | 199 static void DecrementUntilZero(int* count) { |
200 (*count)--; | 200 (*count)--; |
201 if (!(*count)) | 201 if (!(*count)) |
202 base::ThreadTaskRunnerHandle::Get()->PostTask( | 202 base::ThreadTaskRunnerHandle::Get()->PostTask( |
203 FROM_HERE, base::MessageLoop::QuitClosure()); | 203 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
204 } | 204 } |
205 | 205 |
206 // Flaky on Mac. http://crbug.com/517420 | 206 // Flaky on Mac. http://crbug.com/517420 |
207 #if defined(OS_MACOSX) | 207 #if defined(OS_MACOSX) |
208 #define MAYBE_MultipleLaunchTasks DISABLED_MultipleLaunchTasks | 208 #define MAYBE_MultipleLaunchTasks DISABLED_MultipleLaunchTasks |
209 #else | 209 #else |
210 #define MAYBE_MultipleLaunchTasks MultipleLaunchTasks | 210 #define MAYBE_MultipleLaunchTasks MultipleLaunchTasks |
211 #endif | 211 #endif |
212 // Invoke multiple Launch calls in succession and ensure that all the tasks | 212 // Invoke multiple Launch calls in succession and ensure that all the tasks |
213 // get invoked. | 213 // get invoked. |
214 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, | 214 IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, |
215 MAYBE_MultipleLaunchTasks) { | 215 MAYBE_MultipleLaunchTasks) { |
216 ServiceProcessControl* process = ServiceProcessControl::GetInstance(); | 216 ServiceProcessControl* process = ServiceProcessControl::GetInstance(); |
217 int launch_count = 5; | 217 int launch_count = 5; |
218 for (int i = 0; i < launch_count; i++) { | 218 for (int i = 0; i < launch_count; i++) { |
219 // Launch the process asynchronously. | 219 // Launch the process asynchronously. |
220 process->Launch(base::Bind(&DecrementUntilZero, &launch_count), | 220 process->Launch(base::Bind(&DecrementUntilZero, &launch_count), |
221 base::MessageLoop::QuitClosure()); | 221 base::MessageLoop::QuitWhenIdleClosure()); |
222 } | 222 } |
223 // Then run the message loop to keep things running. | 223 // Then run the message loop to keep things running. |
224 content::RunMessageLoop(); | 224 content::RunMessageLoop(); |
225 EXPECT_EQ(0, launch_count); | 225 EXPECT_EQ(0, launch_count); |
226 } | 226 } |
227 | 227 |
228 // Flaky on Mac. http://crbug.com/517420 | 228 // Flaky on Mac. http://crbug.com/517420 |
229 #if defined(OS_MACOSX) | 229 #if defined(OS_MACOSX) |
230 #define MAYBE_SameLaunchTask DISABLED_SameLaunchTask | 230 #define MAYBE_SameLaunchTask DISABLED_SameLaunchTask |
231 #else | 231 #else |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // Callback should not be called during GetHistograms call. | 334 // Callback should not be called during GetHistograms call. |
335 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); | 335 EXPECT_CALL(*this, MockHistogramsCallback()).Times(0); |
336 // Wait for real callback by providing large timeout value. | 336 // Wait for real callback by providing large timeout value. |
337 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( | 337 EXPECT_TRUE(ServiceProcessControl::GetInstance()->GetHistograms( |
338 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, | 338 base::Bind(&ServiceProcessControlBrowserTest::HistogramsCallback, |
339 base::Unretained(this)), | 339 base::Unretained(this)), |
340 base::TimeDelta::FromHours(1))); | 340 base::TimeDelta::FromHours(1))); |
341 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); | 341 EXPECT_CALL(*this, MockHistogramsCallback()).Times(1); |
342 content::RunMessageLoop(); | 342 content::RunMessageLoop(); |
343 } | 343 } |
OLD | NEW |