OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
| 6 #define CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/win/scoped_handle.h" |
| 13 |
| 14 namespace base { |
| 15 class FilePath; |
| 16 class TimeDelta; |
| 17 } |
| 18 |
| 19 namespace installer { |
| 20 |
| 21 class InstallerState; |
| 22 |
| 23 // Any modification to a Chrome installation should be done within the scope of |
| 24 // a SetupSingleton. There can be only one active SetupSingleton per Chrome |
| 25 // installation at a time. |
| 26 class SetupSingleton { |
| 27 public: |
| 28 // Acquires the exclusive right to modify the Chrome installation described by |
| 29 // |installer_state| (installation directory and associated registry keys). |
| 30 // May block. |
| 31 explicit SetupSingleton(const InstallerState& installer_state); |
| 32 |
| 33 // Acquires the exclusive right to modify the Chrome installation located in |
| 34 // |install_dir| (installation directory and associated registry keys). |
| 35 // |system_install| indicates whether this is a system-level installation. May |
| 36 // block. |
| 37 SetupSingleton(const base::FilePath& install_dir, bool system_install); |
| 38 |
| 39 // Releases the exclusive right to modifiy the Chrome installation. |
| 40 ~SetupSingleton(); |
| 41 |
| 42 // Waits until |max_time| has passed or another SetupSingleton is instantiated |
| 43 // with the same Chrome installation as this SetupSingleton (possibly in |
| 44 // another process). |
| 45 |
| 46 // Returns true if another SetupSingleton is instantiated with the same Chrome |
| 47 // installation as this SetupSingleton. In such a case, this SetupSingleton |
| 48 // should be deleted as soon as possible to unblock the other SetupSingleton. |
| 49 // Returns false otherwise. |
| 50 bool Wait(const base::TimeDelta& max_time); |
| 51 |
| 52 private: |
| 53 // A mutex that must be held to modify the Chrome installation directory. |
| 54 base::win::ScopedHandle setup_mutex_; |
| 55 |
| 56 // An event signaled to ask the owner of |setup_mutex_| to release it as soon |
| 57 // as possible. |
| 58 std::unique_ptr<base::WaitableEvent> exit_event_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(SetupSingleton); |
| 61 }; |
| 62 |
| 63 } // namespace installer |
| 64 |
| 65 #endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
OLD | NEW |