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 #include <errno.h> | 5 #include <errno.h> |
6 #include <fcntl.h> | 6 #include <fcntl.h> |
7 #include <sys/file.h> | 7 #include <sys/file.h> |
8 | 8 |
9 #include "chrome/browser/process_singleton.h" | 9 #include "chrome/browser/process_singleton.h" |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Make sure the lock is released. Process death will also release | 49 // Make sure the lock is released. Process death will also release |
50 // it, even if this is not called. | 50 // it, even if this is not called. |
51 Cleanup(); | 51 Cleanup(); |
52 } | 52 } |
53 | 53 |
54 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { | 54 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { |
55 // This space intentionally left blank. | 55 // This space intentionally left blank. |
56 return PROCESS_NONE; | 56 return PROCESS_NONE; |
57 } | 57 } |
58 | 58 |
59 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessOrCreate() { | 59 ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessOrCreate( |
| 60 const NotificationCallback& notification_callback) { |
60 // Windows tries NotifyOtherProcess() first. | 61 // Windows tries NotifyOtherProcess() first. |
61 return Create() ? PROCESS_NONE : PROFILE_IN_USE; | 62 return Create(notification_callback) ? PROCESS_NONE : PROFILE_IN_USE; |
62 } | 63 } |
63 | 64 |
64 // Attempt to acquire an exclusive lock on an empty file in the | 65 // Attempt to acquire an exclusive lock on an empty file in the |
65 // profile directory. Returns |true| if it gets the lock. Returns | 66 // profile directory. Returns |true| if it gets the lock. Returns |
66 // |false| if the lock is held, or if there is an error. | 67 // |false| if the lock is held, or if there is an error. |
| 68 // |notification_callback| is not actually used. See the comments at the top of |
| 69 // this file for details. |
67 // TODO(shess): Rather than logging failures, popup an alert. Punting | 70 // TODO(shess): Rather than logging failures, popup an alert. Punting |
68 // that for now because it would require confidence that this code is | 71 // that for now because it would require confidence that this code is |
69 // never called in a situation where an alert wouldn't work. | 72 // never called in a situation where an alert wouldn't work. |
70 // http://crbug.com/59061 | 73 // http://crbug.com/59061 |
71 bool ProcessSingleton::Create() { | 74 bool ProcessSingleton::Create( |
| 75 const NotificationCallback& notification_callback) { |
72 DCHECK_EQ(-1, lock_fd_) << "lock_path_ is already open."; | 76 DCHECK_EQ(-1, lock_fd_) << "lock_path_ is already open."; |
73 | 77 |
74 lock_fd_ = HANDLE_EINTR(open(lock_path_.value().c_str(), | 78 lock_fd_ = HANDLE_EINTR(open(lock_path_.value().c_str(), |
75 O_RDONLY | O_CREAT, 0644)); | 79 O_RDONLY | O_CREAT, 0644)); |
76 if (lock_fd_ == -1) { | 80 if (lock_fd_ == -1) { |
77 const int capture_errno = errno; | 81 const int capture_errno = errno; |
78 DPCHECK(lock_fd_ != -1) << "Unexpected failure opening profile lockfile"; | 82 DPCHECK(lock_fd_ != -1) << "Unexpected failure opening profile lockfile"; |
79 UMA_HISTOGRAM_ENUMERATION("ProcessSingleton.OpenError", | 83 UMA_HISTOGRAM_ENUMERATION("ProcessSingleton.OpenError", |
80 capture_errno, kMaxErrno); | 84 capture_errno, kMaxErrno); |
81 return false; | 85 return false; |
(...skipping 25 matching lines...) Expand all Loading... |
107 } | 111 } |
108 | 112 |
109 void ProcessSingleton::Cleanup() { | 113 void ProcessSingleton::Cleanup() { |
110 // Closing the file also releases the lock. | 114 // Closing the file also releases the lock. |
111 if (lock_fd_ != -1) { | 115 if (lock_fd_ != -1) { |
112 int rc = HANDLE_EINTR(close(lock_fd_)); | 116 int rc = HANDLE_EINTR(close(lock_fd_)); |
113 DPCHECK(!rc) << "Closing lock_fd_:"; | 117 DPCHECK(!rc) << "Closing lock_fd_:"; |
114 } | 118 } |
115 lock_fd_ = -1; | 119 lock_fd_ = -1; |
116 } | 120 } |
117 | |
118 void ProcessSingleton::ProcessCommandLine(const CommandLine& command_line, | |
119 const FilePath& current_directory) { | |
120 } | |
OLD | NEW |