| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/linux_util.h" | 5 #include "base/linux_util.h" |
| 6 | 6 |
| 7 #include <dirent.h> | 7 #include <dirent.h> |
| 8 #include <errno.h> | 8 #include <errno.h> |
| 9 #include <glib.h> | 9 #include <glib.h> |
| 10 #include <stdlib.h> | 10 #include <stdlib.h> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 STATE_DID_NOT_CHECK = 0, | 29 STATE_DID_NOT_CHECK = 0, |
| 30 STATE_CHECK_STARTED = 1, | 30 STATE_CHECK_STARTED = 1, |
| 31 STATE_CHECK_FINISHED = 2, | 31 STATE_CHECK_FINISHED = 2, |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 // Helper class for GetLinuxDistro(). | 34 // Helper class for GetLinuxDistro(). |
| 35 class LinuxDistroHelper { | 35 class LinuxDistroHelper { |
| 36 public: | 36 public: |
| 37 // Retrieves the Singleton. | 37 // Retrieves the Singleton. |
| 38 static LinuxDistroHelper* Get() { | 38 static LinuxDistroHelper* Get() { |
| 39 return Singleton<LinuxDistroHelper>::get(); | 39 return LeakySingleton<LinuxDistroHelper>::get(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 // The simple state machine goes from: | |
| 43 // STATE_DID_NOT_CHECK -> STATE_CHECK_STARTED -> STATE_CHECK_FINISHED. | |
| 44 LinuxDistroHelper() : state_(STATE_DID_NOT_CHECK) {} | |
| 45 ~LinuxDistroHelper() {} | |
| 46 | |
| 47 // Retrieve the current state, if we're in STATE_DID_NOT_CHECK, | 42 // Retrieve the current state, if we're in STATE_DID_NOT_CHECK, |
| 48 // we automatically move to STATE_CHECK_STARTED so nobody else will | 43 // we automatically move to STATE_CHECK_STARTED so nobody else will |
| 49 // do the check. | 44 // do the check. |
| 50 LinuxDistroState State() { | 45 LinuxDistroState State() { |
| 51 AutoLock scoped_lock(lock_); | 46 AutoLock scoped_lock(lock_); |
| 52 if (STATE_DID_NOT_CHECK == state_) { | 47 if (STATE_DID_NOT_CHECK == state_) { |
| 53 state_ = STATE_CHECK_STARTED; | 48 state_ = STATE_CHECK_STARTED; |
| 54 return STATE_DID_NOT_CHECK; | 49 return STATE_DID_NOT_CHECK; |
| 55 } | 50 } |
| 56 return state_; | 51 return state_; |
| 57 } | 52 } |
| 58 | 53 |
| 59 // Indicate the check finished, move to STATE_CHECK_FINISHED. | 54 // Indicate the check finished, move to STATE_CHECK_FINISHED. |
| 60 void CheckFinished() { | 55 void CheckFinished() { |
| 61 AutoLock scoped_lock(lock_); | 56 AutoLock scoped_lock(lock_); |
| 62 DCHECK(state_ == STATE_CHECK_STARTED); | 57 DCHECK(state_ == STATE_CHECK_STARTED); |
| 63 state_ = STATE_CHECK_FINISHED; | 58 state_ = STATE_CHECK_FINISHED; |
| 64 } | 59 } |
| 65 | 60 |
| 66 private: | 61 private: |
| 62 friend struct DefaultSingletonTraits<LinuxDistroHelper>; |
| 63 |
| 64 // The simple state machine goes from: |
| 65 // STATE_DID_NOT_CHECK -> STATE_CHECK_STARTED -> STATE_CHECK_FINISHED. |
| 66 LinuxDistroHelper() : state_(STATE_DID_NOT_CHECK) {} |
| 67 ~LinuxDistroHelper() {} |
| 68 |
| 67 Lock lock_; | 69 Lock lock_; |
| 68 LinuxDistroState state_; | 70 LinuxDistroState state_; |
| 69 }; | 71 }; |
| 70 #endif // if defined(OS_LINUX) | 72 #endif // if defined(OS_LINUX) |
| 71 | 73 |
| 72 // expected prefix of the target of the /proc/self/fd/%d link for a socket | 74 // expected prefix of the target of the /proc/self/fd/%d link for a socket |
| 73 static const char kSocketLinkPrefix[] = "socket:["; | 75 static const char kSocketLinkPrefix[] = "socket:["; |
| 74 | 76 |
| 75 // Parse a symlink in /proc/pid/fd/$x and return the inode number of the | 77 // Parse a symlink in /proc/pid/fd/$x and return the inode number of the |
| 76 // socket. | 78 // socket. |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 } | 257 } |
| 256 } | 258 } |
| 257 | 259 |
| 258 closedir(fd); | 260 closedir(fd); |
| 259 } | 261 } |
| 260 | 262 |
| 261 return already_found; | 263 return already_found; |
| 262 } | 264 } |
| 263 | 265 |
| 264 } // namespace base | 266 } // namespace base |
| OLD | NEW |