Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3901)

Unified Diff: chrome/installer/setup/setup_singleton.h

Issue 2292293002: Add installer::SetupSingleton. (Closed)
Patch Set: CR grt #9 Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/installer/setup/setup_main.cc ('k') | chrome/installer/setup/setup_singleton.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f8abc15ddb75022e8c0c79e3739fc8bc2accb929
--- /dev/null
+++ b/chrome/installer/setup/setup_singleton.h
@@ -0,0 +1,89 @@
+// 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 <windows.h>
+
+#include <memory>
+
+#include "base/macros.h"
+#include "base/strings/string16.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/win/scoped_handle.h"
+
+namespace base {
+class CommandLine;
+class TimeDelta;
+}
+
+namespace installer {
+
+class InstallationState;
+class InstallerState;
+class MasterPreferences;
+
+// 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:
+ // Returns a SetupSingleton which, throughout its lifetime, gives the current
+ // process the exclusive right to modify the Chrome installation described by
+ // |installer_state| (installation directory and associated registry keys).
+ // May block. |original_state| and |installer_state| are updated using
+ // |command_line| and |master_preferences| to reflect the new state of the
+ // installation after acquisition. Returns nullptr on failure.
+ static std::unique_ptr<SetupSingleton> Acquire(
+ const base::CommandLine& command_line,
+ const MasterPreferences& master_preferences,
+ InstallationState* original_state,
+ InstallerState* installer_state);
+
+ // Releases the exclusive right to modify the Chrome installation.
+ ~SetupSingleton();
+
+ // Waits until |max_time| has passed or another process tries to acquire a
+ // SetupSingleton for the same Chrome installation. In the latter case, the
+ // method returns true and this SetupSingleton should be released as soon as
+ // possible to unblock the other process.
+ bool WaitForInterrupt(const base::TimeDelta& max_time);
+
+ private:
+ class ScopedHoldMutex {
+ public:
+ ScopedHoldMutex();
+ ~ScopedHoldMutex();
+
+ // Waits up to a certain amount of time to acquire |mutex|. Returns true on
+ // success. |mutex| will be released in the destructor.
+ bool Acquire(HANDLE mutex);
+
+ private:
+ HANDLE mutex_ = INVALID_HANDLE_VALUE;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedHoldMutex);
+ };
+
+ // |sync_primitive_name_suffix| is a suffix for the name of |setup_mutex_| and
+ // |exit_event_|.
+ explicit SetupSingleton(const base::string16& sync_primitive_name_suffix);
+
+ // A mutex that must be held to modify the Chrome installation directory.
+ base::win::ScopedHandle setup_mutex_;
+
+ // Holds |setup_mutex_| throughout the lifetime of this SetupSingleton.
+ ScopedHoldMutex scoped_hold_setup_mutex_;
+
+ // An event signaled to ask the owner of |setup_mutex_| to release it as soon
+ // as possible.
+ base::WaitableEvent exit_event_;
+
+ DISALLOW_COPY_AND_ASSIGN(SetupSingleton);
+};
+
+} // namespace installer
+
+#endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_
« no previous file with comments | « chrome/installer/setup/setup_main.cc ('k') | chrome/installer/setup/setup_singleton.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698