OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 | 988 |
989 if (bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) { | 989 if (bind(sock, reinterpret_cast<sockaddr*>(&addr), sizeof(addr)) < 0) { |
990 PLOG(ERROR) << "Failed to bind() " << socket_target_path.value(); | 990 PLOG(ERROR) << "Failed to bind() " << socket_target_path.value(); |
991 CloseSocket(sock); | 991 CloseSocket(sock); |
992 return false; | 992 return false; |
993 } | 993 } |
994 | 994 |
995 if (listen(sock, 5) < 0) | 995 if (listen(sock, 5) < 0) |
996 NOTREACHED() << "listen failed: " << safe_strerror(errno); | 996 NOTREACHED() << "listen failed: " << safe_strerror(errno); |
997 | 997 |
998 // Normally we would use BrowserThread, but the IO thread hasn't started yet. | 998 DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); |
999 // Using g_browser_process, we start the thread so we can listen on the | 999 BrowserThread::PostTask( |
1000 // socket. | 1000 BrowserThread::IO, |
1001 MessageLoop* ml = g_browser_process->io_thread()->message_loop(); | 1001 FROM_HERE, |
1002 DCHECK(ml); | 1002 base::Bind(&ProcessSingleton::LinuxWatcher::StartListening, |
1003 ml->PostTask(FROM_HERE, base::Bind( | 1003 watcher_.get(), |
1004 &ProcessSingleton::LinuxWatcher::StartListening, | 1004 sock)); |
1005 watcher_.get(), | |
1006 sock)); | |
1007 | 1005 |
1008 return true; | 1006 return true; |
1009 } | 1007 } |
1010 | 1008 |
1011 void ProcessSingleton::Cleanup() { | 1009 void ProcessSingleton::Cleanup() { |
1012 UnlinkPath(socket_path_); | 1010 UnlinkPath(socket_path_); |
1013 UnlinkPath(cookie_path_); | 1011 UnlinkPath(cookie_path_); |
1014 UnlinkPath(lock_path_); | 1012 UnlinkPath(lock_path_); |
1015 } | 1013 } |
OLD | NEW |