OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ | 5 #ifndef CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
6 #define CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ | 6 #define CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 InstallationState* original_state, | 42 InstallationState* original_state, |
43 InstallerState* installer_state); | 43 InstallerState* installer_state); |
44 | 44 |
45 // Releases the exclusive right to modify the Chrome installation. | 45 // Releases the exclusive right to modify the Chrome installation. |
46 ~SetupSingleton(); | 46 ~SetupSingleton(); |
47 | 47 |
48 // Waits until |max_time| has passed or another process tries to acquire a | 48 // Waits until |max_time| has passed or another process tries to acquire a |
49 // SetupSingleton for the same Chrome installation. In the latter case, the | 49 // SetupSingleton for the same Chrome installation. In the latter case, the |
50 // method returns true and this SetupSingleton should be released as soon as | 50 // method returns true and this SetupSingleton should be released as soon as |
51 // possible to unblock the other process. | 51 // possible to unblock the other process. |
52 bool WaitForInterrupt(const base::TimeDelta& max_time); | 52 bool WaitForInterrupt(const base::TimeDelta& max_time) const; |
53 | 53 |
54 private: | 54 private: |
55 class ScopedHoldMutex { | 55 class ScopedHoldMutex { |
56 public: | 56 public: |
57 ScopedHoldMutex(); | 57 ScopedHoldMutex(); |
58 ~ScopedHoldMutex(); | 58 ~ScopedHoldMutex(); |
59 | 59 |
60 // Waits up to a certain amount of time to acquire |mutex|. Returns true on | 60 // Waits up to a certain amount of time to acquire |mutex|. Returns true on |
61 // success. |mutex| will be released in the destructor. | 61 // success. |mutex| will be released in the destructor. |
62 bool Acquire(HANDLE mutex); | 62 bool Acquire(HANDLE mutex); |
63 | 63 |
64 private: | 64 private: |
65 HANDLE mutex_ = INVALID_HANDLE_VALUE; | 65 HANDLE mutex_ = INVALID_HANDLE_VALUE; |
66 | 66 |
67 DISALLOW_COPY_AND_ASSIGN(ScopedHoldMutex); | 67 DISALLOW_COPY_AND_ASSIGN(ScopedHoldMutex); |
68 }; | 68 }; |
69 | 69 |
70 SetupSingleton(base::win::ScopedHandle setup_mutex, | 70 SetupSingleton(base::win::ScopedHandle setup_mutex, |
71 base::win::ScopedHandle exit_event); | 71 base::win::ScopedHandle exit_event); |
72 | 72 |
73 // A mutex that must be held to modify the Chrome installation directory. | 73 // A mutex that must be held to modify the Chrome installation directory. |
74 base::win::ScopedHandle setup_mutex_; | 74 base::win::ScopedHandle setup_mutex_; |
75 | 75 |
76 // Holds |setup_mutex_| throughout the lifetime of this SetupSingleton. | 76 // Holds |setup_mutex_| throughout the lifetime of this SetupSingleton. |
77 ScopedHoldMutex scoped_hold_setup_mutex_; | 77 ScopedHoldMutex scoped_hold_setup_mutex_; |
78 | 78 |
79 // An event signaled to ask the owner of |setup_mutex_| to release it as soon | 79 // An event signaled to ask the owner of |setup_mutex_| to release it as soon |
80 // as possible. | 80 // as possible. |
81 base::WaitableEvent exit_event_; | 81 mutable base::WaitableEvent exit_event_; |
82 | 82 |
83 DISALLOW_COPY_AND_ASSIGN(SetupSingleton); | 83 DISALLOW_COPY_AND_ASSIGN(SetupSingleton); |
84 }; | 84 }; |
85 | 85 |
86 } // namespace installer | 86 } // namespace installer |
87 | 87 |
88 #endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ | 88 #endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
OLD | NEW |