Index: chrome/installer/setup/setup_singleton.h |
diff --git a/chrome/installer/setup/setup_singleton.h b/chrome/installer/setup/setup_singleton.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..03874fd9fe38939c8ffbbb6f232478e7a106a0c1 |
--- /dev/null |
+++ b/chrome/installer/setup/setup_singleton.h |
@@ -0,0 +1,65 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
+#define CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |
+ |
+#include <memory> |
+ |
+#include "base/macros.h" |
+#include "base/synchronization/waitable_event.h" |
+#include "base/win/scoped_handle.h" |
+ |
+namespace base { |
+class FilePath; |
+class TimeDelta; |
+} |
+ |
+namespace installer { |
+ |
+class InstallerState; |
+ |
+// Any modification to a Chrome installation should be done within the scope of |
+// a SetupSingleton. There can be only one active SetupSingleton per Chrome |
+// installation at a time. |
+class SetupSingleton { |
+ public: |
+ // Acquires the exclusive right to modify the Chrome installation described by |
+ // |installer_state| (installation directory and associated registry keys). |
+ // May block. |
+ explicit SetupSingleton(const InstallerState& installer_state); |
+ |
+ // Acquires the exclusive right to modify the Chrome installation located in |
+ // |install_dir| (installation directory and associated registry keys). |
+ // |system_install| indicates whether this is a system-level installation. May |
+ // block. |
+ SetupSingleton(const base::FilePath& install_dir, bool system_install); |
+ |
+ // Releases the exclusive right to modifiy the Chrome installation. |
+ ~SetupSingleton(); |
+ |
+ // Waits until |max_time| has passed or another SetupSingleton is instantiated |
+ // with the same Chrome installation as this SetupSingleton (possibly in |
+ // another process). |
+ |
+ // Returns true if another SetupSingleton is instantiated with the same Chrome |
+ // installation as this SetupSingleton. In such a case, this SetupSingleton |
+ // should be deleted as soon as possible to unblock the other SetupSingleton. |
+ // Returns false otherwise. |
+ bool Wait(const base::TimeDelta& max_time); |
+ |
+ private: |
+ // A mutex that must be held to modify the Chrome installation directory. |
+ base::win::ScopedHandle setup_mutex_; |
+ |
+ // An event signaled to ask the owner of |setup_mutex_| to release it as soon |
+ // as possible. |
+ std::unique_ptr<base::WaitableEvent> exit_event_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SetupSingleton); |
+}; |
+ |
+} // namespace installer |
+ |
+#endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ |