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

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

Issue 648653003: Standardize usage of virtual/override/final in chrome/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
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 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 bytes_read_(0) { 479 bytes_read_(0) {
480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 480 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
481 // Wait for reads. 481 // Wait for reads.
482 base::MessageLoopForIO::current()->WatchFileDescriptor( 482 base::MessageLoopForIO::current()->WatchFileDescriptor(
483 fd, true, base::MessageLoopForIO::WATCH_READ, &fd_reader_, this); 483 fd, true, base::MessageLoopForIO::WATCH_READ, &fd_reader_, this);
484 // If we haven't completed in a reasonable amount of time, give up. 484 // If we haven't completed in a reasonable amount of time, give up.
485 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeoutInSeconds), 485 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeoutInSeconds),
486 this, &SocketReader::CleanupAndDeleteSelf); 486 this, &SocketReader::CleanupAndDeleteSelf);
487 } 487 }
488 488
489 virtual ~SocketReader() { 489 ~SocketReader() override { CloseSocket(fd_); }
490 CloseSocket(fd_);
491 }
492 490
493 // MessageLoopForIO::Watcher impl. 491 // MessageLoopForIO::Watcher impl.
494 virtual void OnFileCanReadWithoutBlocking(int fd) override; 492 void OnFileCanReadWithoutBlocking(int fd) override;
495 virtual void OnFileCanWriteWithoutBlocking(int fd) override { 493 void OnFileCanWriteWithoutBlocking(int fd) override {
496 // SocketReader only watches for accept (read) events. 494 // SocketReader only watches for accept (read) events.
497 NOTREACHED(); 495 NOTREACHED();
498 } 496 }
499 497
500 // Finish handling the incoming message by optionally sending back an ACK 498 // Finish handling the incoming message by optionally sending back an ACK
501 // message and removing this SocketReader. 499 // message and removing this SocketReader.
502 void FinishWithACK(const char *message, size_t length); 500 void FinishWithACK(const char *message, size_t length);
503 501
504 private: 502 private:
505 void CleanupAndDeleteSelf() { 503 void CleanupAndDeleteSelf() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 void StartListening(int socket); 541 void StartListening(int socket);
544 542
545 // This method determines if we should use the same process and if we should, 543 // This method determines if we should use the same process and if we should,
546 // opens a new browser tab. This runs on the UI thread. 544 // opens a new browser tab. This runs on the UI thread.
547 // |reader| is for sending back ACK message. 545 // |reader| is for sending back ACK message.
548 void HandleMessage(const std::string& current_dir, 546 void HandleMessage(const std::string& current_dir,
549 const std::vector<std::string>& argv, 547 const std::vector<std::string>& argv,
550 SocketReader* reader); 548 SocketReader* reader);
551 549
552 // MessageLoopForIO::Watcher impl. These run on the IO thread. 550 // MessageLoopForIO::Watcher impl. These run on the IO thread.
553 virtual void OnFileCanReadWithoutBlocking(int fd) override; 551 void OnFileCanReadWithoutBlocking(int fd) override;
554 virtual void OnFileCanWriteWithoutBlocking(int fd) override { 552 void OnFileCanWriteWithoutBlocking(int fd) override {
555 // ProcessSingleton only watches for accept (read) events. 553 // ProcessSingleton only watches for accept (read) events.
556 NOTREACHED(); 554 NOTREACHED();
557 } 555 }
558 556
559 // MessageLoop::DestructionObserver 557 // MessageLoop::DestructionObserver
560 virtual void WillDestroyCurrentMessageLoop() override { 558 void WillDestroyCurrentMessageLoop() override {
561 fd_watcher_.StopWatchingFileDescriptor(); 559 fd_watcher_.StopWatchingFileDescriptor();
562 } 560 }
563 561
564 private: 562 private:
565 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>; 563 friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
566 friend class base::DeleteHelper<ProcessSingleton::LinuxWatcher>; 564 friend class base::DeleteHelper<ProcessSingleton::LinuxWatcher>;
567 565
568 virtual ~LinuxWatcher() { 566 ~LinuxWatcher() override {
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
570 STLDeleteElements(&readers_); 568 STLDeleteElements(&readers_);
571 569
572 base::MessageLoopForIO* ml = base::MessageLoopForIO::current(); 570 base::MessageLoopForIO* ml = base::MessageLoopForIO::current();
573 ml->RemoveDestructionObserver(this); 571 ml->RemoveDestructionObserver(this);
574 } 572 }
575 573
576 // Removes and deletes the SocketReader. 574 // Removes and deletes the SocketReader.
577 void RemoveSocketReader(SocketReader* reader); 575 void RemoveSocketReader(SocketReader* reader);
578 576
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 } 1067 }
1070 1068
1071 void ProcessSingleton::KillProcess(int pid) { 1069 void ProcessSingleton::KillProcess(int pid) {
1072 // TODO(james.su@gmail.com): Is SIGKILL ok? 1070 // TODO(james.su@gmail.com): Is SIGKILL ok?
1073 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL); 1071 int rv = kill(static_cast<base::ProcessHandle>(pid), SIGKILL);
1074 // ESRCH = No Such Process (can happen if the other process is already in 1072 // ESRCH = No Such Process (can happen if the other process is already in
1075 // progress of shutting down and finishes before we try to kill it). 1073 // progress of shutting down and finishes before we try to kill it).
1076 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: " 1074 DCHECK(rv == 0 || errno == ESRCH) << "Error killing process: "
1077 << safe_strerror(errno); 1075 << safe_strerror(errno);
1078 } 1076 }
OLDNEW
« no previous file with comments | « chrome/browser/prefetch/prefetch_browsertest.cc ('k') | chrome/browser/profile_resetter/automatic_profile_resetter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698