Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(997)

Side by Side Diff: chrome/browser/process_singleton_linux.cc

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename test suite. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 : notification_callback_(notification_callback),
699 foreground_window_(NULL),
700 notification_callback_(notification_callback),
701 current_pid_(base::GetCurrentProcId()), 689 current_pid_(base::GetCurrentProcId()),
702 ALLOW_THIS_IN_INITIALIZER_LIST(watcher_(new LinuxWatcher(this))) { 690 ALLOW_THIS_IN_INITIALIZER_LIST(watcher_(new LinuxWatcher(this))) {
703 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename); 691 socket_path_ = user_data_dir.Append(chrome::kSingletonSocketFilename);
704 lock_path_ = user_data_dir.Append(chrome::kSingletonLockFilename); 692 lock_path_ = user_data_dir.Append(chrome::kSingletonLockFilename);
705 cookie_path_ = user_data_dir.Append(chrome::kSingletonCookieFilename); 693 cookie_path_ = user_data_dir.Append(chrome::kSingletonCookieFilename);
706 694
707 kill_callback_ = base::Bind(&ProcessSingleton::KillProcess, 695 kill_callback_ = base::Bind(&ProcessSingleton::KillProcess,
708 base::Unretained(this)); 696 base::Unretained(this));
709 } 697 }
710 698
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 } 977 }
990 978
991 void ProcessSingleton::KillProcess(int pid) { 979 void ProcessSingleton::KillProcess(int pid) {
992 // TODO(james.su@gmail.com): Is SIGKILL ok? 980 // TODO(james.su@gmail.com): Is SIGKILL ok?
993 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); 981 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL);
994 // ESRCH = No Such Process (can happen if the other process is already in 982 // 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). 983 // progress of shutting down and finishes before we try to kill it).
996 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " 984 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: "
997 << safe_strerror(errno); 985 << safe_strerror(errno);
998 } 986 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698