| 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 // On Linux, when the user tries to launch a second copy of chrome, we check | 5 // On Linux, when the user tries to launch a second copy of chrome, we check |
| 6 // for a socket in the user's profile directory. If the socket file is open we | 6 // for a socket in the user's profile directory. If the socket file is open we |
| 7 // send a message to the first chrome browser process with the current | 7 // send a message to the first chrome browser process with the current |
| 8 // directory and second process command line flags. The second process then | 8 // directory and second process command line flags. The second process then |
| 9 // exits. | 9 // exits. |
| 10 // | 10 // |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 ml->AddDestructionObserver(this); | 560 ml->AddDestructionObserver(this); |
| 561 ml->WatchFileDescriptor(socket, true, MessageLoopForIO::WATCH_READ, | 561 ml->WatchFileDescriptor(socket, true, MessageLoopForIO::WATCH_READ, |
| 562 &fd_watcher_, this); | 562 &fd_watcher_, this); |
| 563 } | 563 } |
| 564 | 564 |
| 565 void ProcessSingleton::LinuxWatcher::HandleMessage( | 565 void ProcessSingleton::LinuxWatcher::HandleMessage( |
| 566 const std::string& current_dir, const std::vector<std::string>& argv, | 566 const std::string& current_dir, const std::vector<std::string>& argv, |
| 567 SocketReader* reader) { | 567 SocketReader* reader) { |
| 568 DCHECK(ui_message_loop_ == MessageLoop::current()); | 568 DCHECK(ui_message_loop_ == MessageLoop::current()); |
| 569 DCHECK(reader); | 569 DCHECK(reader); |
| 570 // If locked, it means we are not ready to process this message because | |
| 571 // we are probably in a first run critical phase. | |
| 572 if (parent_->locked()) { | |
| 573 DLOG(WARNING) << "Browser is locked"; | |
| 574 parent_->saved_startup_messages_.push_back( | |
| 575 std::make_pair(argv, base::FilePath(current_dir))); | |
| 576 // Send back "ACK" message to prevent the client process from starting up. | |
| 577 reader->FinishWithACK(kACKToken, arraysize(kACKToken) - 1); | |
| 578 return; | |
| 579 } | |
| 580 | 570 |
| 581 if (parent_->notification_callback_.Run(CommandLine(argv), | 571 if (parent_->notification_callback_.Run(CommandLine(argv), |
| 582 base::FilePath(current_dir))) { | 572 base::FilePath(current_dir))) { |
| 583 // Send back "ACK" message to prevent the client process from starting up. | 573 // Send back "ACK" message to prevent the client process from starting up. |
| 584 reader->FinishWithACK(kACKToken, arraysize(kACKToken) - 1); | 574 reader->FinishWithACK(kACKToken, arraysize(kACKToken) - 1); |
| 585 } else { | 575 } else { |
| 586 LOG(WARNING) << "Not handling interprocess notification as browser" | 576 LOG(WARNING) << "Not handling interprocess notification as browser" |
| 587 " is shutting down"; | 577 " is shutting down"; |
| 588 // Send back "SHUTDOWN" message, so that the client process can start up | 578 // Send back "SHUTDOWN" message, so that the client process can start up |
| 589 // without killing this process. | 579 // without killing this process. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 this)); | 678 this)); |
| 689 // We will be deleted once the posted RemoveSocketReader task runs. | 679 // We will be deleted once the posted RemoveSocketReader task runs. |
| 690 } | 680 } |
| 691 | 681 |
| 692 /////////////////////////////////////////////////////////////////////////////// | 682 /////////////////////////////////////////////////////////////////////////////// |
| 693 // ProcessSingleton | 683 // ProcessSingleton |
| 694 // | 684 // |
| 695 ProcessSingleton::ProcessSingleton( | 685 ProcessSingleton::ProcessSingleton( |
| 696 const base::FilePath& user_data_dir, | 686 const base::FilePath& user_data_dir, |
| 697 const NotificationCallback& notification_callback) | 687 const NotificationCallback& notification_callback) |
| 698 : locked_(false), | 688 : foreground_window_(NULL), |
| 699 foreground_window_(NULL), | |
| 700 notification_callback_(notification_callback), | 689 notification_callback_(notification_callback), |
| 701 current_pid_(base::GetCurrentProcId()), | 690 current_pid_(base::GetCurrentProcId()), |
| 702 ALLOW_THIS_IN_INITIALIZER_LIST(watcher_(new LinuxWatcher(this))) { | 691 ALLOW_THIS_IN_INITIALIZER_LIST(watcher_(new LinuxWatcher(this))) { |
| 703 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename); | 692 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename); |
| 704 lock_path_ = user_data_dir.Append(chrome::kSingletonLockFilename); | 693 lock_path_ = user_data_dir.Append(chrome::kSingletonLockFilename); |
| 705 cookie_path_ = user_data_dir.Append(chrome::kSingletonCookieFilename); | 694 cookie_path_ = user_data_dir.Append(chrome::kSingletonCookieFilename); |
| 706 | 695 |
| 707 kill_callback_ = base::Bind(&ProcessSingleton::KillProcess, | 696 kill_callback_ = base::Bind(&ProcessSingleton::KillProcess, |
| 708 base::Unretained(this)); | 697 base::Unretained(this)); |
| 709 } | 698 } |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 } | 978 } |
| 990 | 979 |
| 991 void ProcessSingleton::KillProcess(int pid) { | 980 void ProcessSingleton::KillProcess(int pid) { |
| 992 // TODO(james.su@gmail.com): Is SIGKILL ok? | 981 // TODO(james.su@gmail.com): Is SIGKILL ok? |
| 993 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); | 982 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); |
| 994 // ESRCH = No Such Process (can happen if the other process is already in | 983 // ESRCH = No Such Process (can happen if the other process is already in |
| 995 // progress of shutting down and finishes before we try to kill it). | 984 // progress of shutting down and finishes before we try to kill it). |
| 996 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " | 985 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " |
| 997 << safe_strerror(errno); | 986 << safe_strerror(errno); |
| 998 } | 987 } |
| OLD | NEW |