OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/login/chrome_restart_request.h" | 5 #include "chrome/browser/chromeos/login/chrome_restart_request.h" |
6 | 6 |
| 7 #include <sys/socket.h> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
10 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 explicit ChromeRestartRequest(const std::vector<std::string>& argv); | 264 explicit ChromeRestartRequest(const std::vector<std::string>& argv); |
264 ~ChromeRestartRequest(); | 265 ~ChromeRestartRequest(); |
265 | 266 |
266 // Starts the request. | 267 // Starts the request. |
267 void Start(); | 268 void Start(); |
268 | 269 |
269 private: | 270 private: |
270 // Fires job restart request to session manager. | 271 // Fires job restart request to session manager. |
271 void RestartJob(); | 272 void RestartJob(); |
272 | 273 |
| 274 // Called when RestartJob D-Bus method call is complete. |
| 275 void OnRestartJob(base::ScopedFD local_auth_fd, DBusMethodCallStatus status); |
| 276 |
273 const std::vector<std::string> argv_; | 277 const std::vector<std::string> argv_; |
274 base::OneShotTimer timer_; | 278 base::OneShotTimer timer_; |
275 | 279 |
276 DISALLOW_COPY_AND_ASSIGN(ChromeRestartRequest); | 280 DISALLOW_COPY_AND_ASSIGN(ChromeRestartRequest); |
277 }; | 281 }; |
278 | 282 |
279 ChromeRestartRequest::ChromeRestartRequest(const std::vector<std::string>& argv) | 283 ChromeRestartRequest::ChromeRestartRequest(const std::vector<std::string>& argv) |
280 : argv_(argv) {} | 284 : argv_(argv) {} |
281 | 285 |
282 ChromeRestartRequest::~ChromeRestartRequest() {} | 286 ChromeRestartRequest::~ChromeRestartRequest() {} |
(...skipping 29 matching lines...) Expand all Loading... |
312 local_state_task_runner->PostTaskAndReply( | 316 local_state_task_runner->PostTaskAndReply( |
313 FROM_HERE, | 317 FROM_HERE, |
314 base::Bind(&EnsureLocalStateIsWritten), | 318 base::Bind(&EnsureLocalStateIsWritten), |
315 base::Bind(&ChromeRestartRequest::RestartJob, AsWeakPtr())); | 319 base::Bind(&ChromeRestartRequest::RestartJob, AsWeakPtr())); |
316 } | 320 } |
317 | 321 |
318 void ChromeRestartRequest::RestartJob() { | 322 void ChromeRestartRequest::RestartJob() { |
319 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 323 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
320 VLOG(1) << "ChromeRestartRequest::RestartJob"; | 324 VLOG(1) << "ChromeRestartRequest::RestartJob"; |
321 | 325 |
322 DBusThreadManager::Get()->GetSessionManagerClient()->RestartJob(argv_); | 326 // The session manager requires a RestartJob caller to open a socket pair and |
| 327 // pass one end over D-Bus while holding the local end open for the duration |
| 328 // of the call. |
| 329 int sockets[2] = {-1, -1}; |
| 330 // socketpair() doesn't cause disk IO so it's OK to call it on the UI thread. |
| 331 // Also, the current chrome process is going to die soon so it doesn't matter |
| 332 // anyways. |
| 333 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) < 0) { |
| 334 PLOG(ERROR) << "Failed to create a unix domain socketpair"; |
| 335 delete this; |
| 336 return; |
| 337 } |
| 338 base::ScopedFD local_auth_fd(sockets[0]); |
| 339 base::ScopedFD remote_auth_fd(sockets[1]); |
| 340 // Ownership of local_auth_fd is passed to the callback that is to be |
| 341 // called on completion of this method call. This keeps the browser end |
| 342 // of the socket-pair alive for the duration of the RPC. |
| 343 DBusThreadManager::Get()->GetSessionManagerClient()->RestartJob( |
| 344 remote_auth_fd.get(), argv_, |
| 345 base::Bind(&ChromeRestartRequest::OnRestartJob, AsWeakPtr(), |
| 346 base::Passed(&local_auth_fd))); |
| 347 } |
323 | 348 |
| 349 void ChromeRestartRequest::OnRestartJob(base::ScopedFD local_auth_fd, |
| 350 DBusMethodCallStatus status) { |
| 351 // Now that the call is complete, local_auth_fd can be closed and discarded, |
| 352 // which will happen automatically when it goes out of scope. |
| 353 VLOG(1) << "OnRestartJob"; |
324 delete this; | 354 delete this; |
325 } | 355 } |
326 | 356 |
327 } // namespace | 357 } // namespace |
328 | 358 |
329 void GetOffTheRecordCommandLine(const GURL& start_url, | 359 void GetOffTheRecordCommandLine(const GURL& start_url, |
330 bool is_oobe_completed, | 360 bool is_oobe_completed, |
331 const base::CommandLine& base_command_line, | 361 const base::CommandLine& base_command_line, |
332 base::CommandLine* command_line) { | 362 base::CommandLine* command_line) { |
333 base::DictionaryValue otr_switches; | 363 base::DictionaryValue otr_switches; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // Relaunch chrome without session manager on dev box. | 395 // Relaunch chrome without session manager on dev box. |
366 ReLaunch(command_line); | 396 ReLaunch(command_line); |
367 return; | 397 return; |
368 } | 398 } |
369 | 399 |
370 // ChromeRestartRequest deletes itself after request sent to session manager. | 400 // ChromeRestartRequest deletes itself after request sent to session manager. |
371 (new ChromeRestartRequest(command_line.argv()))->Start(); | 401 (new ChromeRestartRequest(command_line.argv()))->Start(); |
372 } | 402 } |
373 | 403 |
374 } // namespace chromeos | 404 } // namespace chromeos |
OLD | NEW |