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 // 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 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 timer_.Stop(); | 687 timer_.Stop(); |
688 | 688 |
689 std::string current_dir = tokens[1]; | 689 std::string current_dir = tokens[1]; |
690 // Remove the first two tokens. The remaining tokens should be the command | 690 // Remove the first two tokens. The remaining tokens should be the command |
691 // line argv array. | 691 // line argv array. |
692 tokens.erase(tokens.begin()); | 692 tokens.erase(tokens.begin()); |
693 tokens.erase(tokens.begin()); | 693 tokens.erase(tokens.begin()); |
694 | 694 |
695 // Return to the UI thread to handle opening a new browser tab. | 695 // Return to the UI thread to handle opening a new browser tab. |
696 ui_task_runner_->PostTask( | 696 ui_task_runner_->PostTask( |
697 FROM_HERE, base::Bind(&ProcessSingleton::LinuxWatcher::HandleMessage, | 697 FROM_HERE, base::BindOnce(&ProcessSingleton::LinuxWatcher::HandleMessage, |
698 parent_, current_dir, tokens, this)); | 698 parent_, current_dir, tokens, this)); |
699 fd_watch_controller_.reset(); | 699 fd_watch_controller_.reset(); |
700 | 700 |
701 // LinuxWatcher::HandleMessage() is in charge of destroying this SocketReader | 701 // LinuxWatcher::HandleMessage() is in charge of destroying this SocketReader |
702 // object by invoking SocketReader::FinishWithACK(). | 702 // object by invoking SocketReader::FinishWithACK(). |
703 } | 703 } |
704 | 704 |
705 void ProcessSingleton::LinuxWatcher::SocketReader::FinishWithACK( | 705 void ProcessSingleton::LinuxWatcher::SocketReader::FinishWithACK( |
706 const char *message, size_t length) { | 706 const char *message, size_t length) { |
707 if (message && length) { | 707 if (message && length) { |
708 // Not necessary to care about the return value. | 708 // Not necessary to care about the return value. |
709 WriteToSocket(fd_, message, length); | 709 WriteToSocket(fd_, message, length); |
710 } | 710 } |
711 | 711 |
712 if (shutdown(fd_, SHUT_WR) < 0) | 712 if (shutdown(fd_, SHUT_WR) < 0) |
713 PLOG(ERROR) << "shutdown() failed"; | 713 PLOG(ERROR) << "shutdown() failed"; |
714 | 714 |
715 BrowserThread::PostTask( | 715 BrowserThread::PostTask( |
716 BrowserThread::IO, | 716 BrowserThread::IO, FROM_HERE, |
717 FROM_HERE, | 717 base::BindOnce(&ProcessSingleton::LinuxWatcher::RemoveSocketReader, |
718 base::Bind(&ProcessSingleton::LinuxWatcher::RemoveSocketReader, | 718 parent_, this)); |
719 parent_, | |
720 this)); | |
721 // We will be deleted once the posted RemoveSocketReader task runs. | 719 // We will be deleted once the posted RemoveSocketReader task runs. |
722 } | 720 } |
723 | 721 |
724 /////////////////////////////////////////////////////////////////////////////// | 722 /////////////////////////////////////////////////////////////////////////////// |
725 // ProcessSingleton | 723 // ProcessSingleton |
726 // | 724 // |
727 ProcessSingleton::ProcessSingleton( | 725 ProcessSingleton::ProcessSingleton( |
728 const base::FilePath& user_data_dir, | 726 const base::FilePath& user_data_dir, |
729 const NotificationCallback& notification_callback) | 727 const NotificationCallback& notification_callback) |
730 : notification_callback_(notification_callback), | 728 : notification_callback_(notification_callback), |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 PLOG(ERROR) << "Failed to bind() " << socket_target_path.value(); | 1019 PLOG(ERROR) << "Failed to bind() " << socket_target_path.value(); |
1022 CloseSocket(sock); | 1020 CloseSocket(sock); |
1023 return false; | 1021 return false; |
1024 } | 1022 } |
1025 | 1023 |
1026 if (listen(sock, 5) < 0) | 1024 if (listen(sock, 5) < 0) |
1027 NOTREACHED() << "listen failed: " << base::safe_strerror(errno); | 1025 NOTREACHED() << "listen failed: " << base::safe_strerror(errno); |
1028 | 1026 |
1029 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); | 1027 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); |
1030 BrowserThread::PostTask( | 1028 BrowserThread::PostTask( |
1031 BrowserThread::IO, | 1029 BrowserThread::IO, FROM_HERE, |
1032 FROM_HERE, | 1030 base::BindOnce(&ProcessSingleton::LinuxWatcher::StartListening, watcher_, |
1033 base::Bind(&ProcessSingleton::LinuxWatcher::StartListening, | 1031 sock)); |
1034 watcher_, | |
1035 sock)); | |
1036 | 1032 |
1037 return true; | 1033 return true; |
1038 } | 1034 } |
1039 | 1035 |
1040 void ProcessSingleton::Cleanup() { | 1036 void ProcessSingleton::Cleanup() { |
1041 UnlinkPath(socket_path_); | 1037 UnlinkPath(socket_path_); |
1042 UnlinkPath(cookie_path_); | 1038 UnlinkPath(cookie_path_); |
1043 UnlinkPath(lock_path_); | 1039 UnlinkPath(lock_path_); |
1044 } | 1040 } |
1045 | 1041 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 } | 1074 } |
1079 | 1075 |
1080 void ProcessSingleton::KillProcess(int pid) { | 1076 void ProcessSingleton::KillProcess(int pid) { |
1081 // TODO(james.su@gmail.com): Is SIGKILL ok? | 1077 // TODO(james.su@gmail.com): Is SIGKILL ok? |
1082 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); | 1078 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); |
1083 // ESRCH = No Such Process (can happen if the other process is already in | 1079 // ESRCH = No Such Process (can happen if the other process is already in |
1084 // progress of shutting down and finishes before we try to kill it). | 1080 // progress of shutting down and finishes before we try to kill it). |
1085 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " | 1081 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " |
1086 << base::safe_strerror(errno); | 1082 << base::safe_strerror(errno); |
1087 } | 1083 } |
OLD | NEW |