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

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

Issue 2292293002: Add installer::SetupSingleton. (Closed)
Patch Set: cleanup diff Created 4 years, 4 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
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..cdfd0fceefab056cd404e3f37478ded35a12951e
--- /dev/null
+++ b/chrome/installer/setup/setup_singleton.h
@@ -0,0 +1,92 @@
+// 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 to the
grt (UTC plus 2) 2016/09/01 12:05:39 language nit "to the" -> "the"
fdoray 2016/09/01 15:45:23 Done.
+ // current process the exclusive right to modify the Chrome installation
+ // described by |installer_state| (installation directory and associated
+ // registry keys). May block. |installer_state| and |original_state| are
+ // updated using |command_line| and just before this returns in case the
grt (UTC plus 2) 2016/09/01 12:05:39 "and |master_preferences|"?
grt (UTC plus 2) 2016/09/01 12:05:39 maybe change to something like "...updated using .
fdoray 2016/09/01 15:45:23 Done.
fdoray 2016/09/01 15:45:23 Done.
+ // Chrome installation was
+ // modified by another process before the exclusive right to modify it was
+ // acquired. Returns nullptr on failure.
+ static std::unique_ptr<SetupSingleton> Acquire(
+ const base::CommandLine& command_line,
+ const MasterPreferences& master_preferences,
+ InstallerState* installer_state,
+ InstallationState* original_state);
+
+ // Releases the exclusive right to modifiy the Chrome installation.
+ ~SetupSingleton();
+
+ // Waits until |max_time| has passed or someone tries to acquire a
grt (UTC plus 2) 2016/09/01 12:05:39 "someone" -> "another process"
fdoray 2016/09/01 15:45:23 Done.
+ // SetupSingleton for the same Chrome installation as this SetupSingleton. In
grt (UTC plus 2) 2016/09/01 12:05:39 nit: omit " as this SetupSingleton". i think it's
fdoray 2016/09/01 15:45:23 Done.
+ // the latter case, the method returns true and this SetupSingleton should be
+ // released as soon as possible to unblock the acquisition of the other
+ // SetupSingleton.
+ bool Wait(const base::TimeDelta& max_time);
grt (UTC plus 2) 2016/09/01 12:05:39 how about WaitForInterrupt?
fdoray 2016/09/01 15:45:23 Done.
+
+ 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_

Powered by Google App Engine
This is Rietveld 408576698