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 // |sync_primitive_name_suffix| is a suffix for the name of |setup_mutex_| and | 70 // |sync_primitive_name_suffix| is a suffix for the name of |setup_mutex_| and |
71 // |exit_event_|. | 71 // |exit_event_|. |
72 explicit SetupSingleton(const base::string16& sync_primitive_name_suffix); | 72 explicit SetupSingleton(const base::string16& sync_primitive_name_suffix); |
73 | 73 |
74 // A mutex that must be held to modify the Chrome installation directory. | 74 // A mutex that must be held to modify the Chrome installation directory. |
75 base::win::ScopedHandle setup_mutex_; | 75 base::win::ScopedHandle setup_mutex_; |
76 | 76 |
77 // Holds |setup_mutex_| throughout the lifetime of this SetupSingleton. | 77 // Holds |setup_mutex_| throughout the lifetime of this SetupSingleton. |
78 ScopedHoldMutex scoped_hold_setup_mutex_; | 78 ScopedHoldMutex scoped_hold_setup_mutex_; |
79 | 79 |
80 // An event signaled to ask the owner of |setup_mutex_| to release it as soon | 80 // An event signaled to ask the owner of |setup_mutex_| to release it as soon |
81 // as possible. | 81 // as possible. |
82 base::WaitableEvent exit_event_; | 82 mutable base::WaitableEvent exit_event_; |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(SetupSingleton); | 84 DISALLOW_COPY_AND_ASSIGN(SetupSingleton); |
85 }; | 85 }; |
86 | 86 |
87 } // namespace installer | 87 } // namespace installer |
88 | 88 |
89 #endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ | 89 #endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
OLD | NEW |