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 <windows.h> | |
9 | |
10 #include <memory> | |
11 | |
12 #include "base/macros.h" | |
13 #include "base/strings/string16.h" | |
14 #include "base/synchronization/waitable_event.h" | |
15 #include "base/win/scoped_handle.h" | |
16 | |
17 namespace base { | |
18 class CommandLine; | |
19 class TimeDelta; | |
20 } | |
21 | |
22 namespace installer { | |
23 | |
24 class InstallationState; | |
25 class InstallerState; | |
26 class MasterPreferences; | |
27 | |
28 // Any modification to a Chrome installation should be done within the scope of | |
29 // a SetupSingleton. There can be only one active SetupSingleton per Chrome | |
30 // installation at a time. | |
31 class SetupSingleton { | |
32 public: | |
33 // 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.
| |
34 // current process the exclusive right to modify the Chrome installation | |
35 // described by |installer_state| (installation directory and associated | |
36 // registry keys). May block. |installer_state| and |original_state| are | |
37 // 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.
| |
38 // Chrome installation was | |
39 // modified by another process before the exclusive right to modify it was | |
40 // acquired. Returns nullptr on failure. | |
41 static std::unique_ptr<SetupSingleton> Acquire( | |
42 const base::CommandLine& command_line, | |
43 const MasterPreferences& master_preferences, | |
44 InstallerState* installer_state, | |
45 InstallationState* original_state); | |
46 | |
47 // Releases the exclusive right to modifiy the Chrome installation. | |
48 ~SetupSingleton(); | |
49 | |
50 // 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.
| |
51 // 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.
| |
52 // the latter case, the method returns true and this SetupSingleton should be | |
53 // released as soon as possible to unblock the acquisition of the other | |
54 // SetupSingleton. | |
55 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.
| |
56 | |
57 private: | |
58 class ScopedHoldMutex { | |
59 public: | |
60 ScopedHoldMutex(); | |
61 ~ScopedHoldMutex(); | |
62 | |
63 // Waits up to a certain amount of time to acquire |mutex|. Returns true on | |
64 // success. |mutex| will be released in the destructor. | |
65 bool Acquire(HANDLE mutex); | |
66 | |
67 private: | |
68 HANDLE mutex_ = INVALID_HANDLE_VALUE; | |
69 | |
70 DISALLOW_COPY_AND_ASSIGN(ScopedHoldMutex); | |
71 }; | |
72 | |
73 // |sync_primitive_name_suffix| is a suffix for the name of |setup_mutex_| and | |
74 // |exit_event_|. | |
75 explicit SetupSingleton(const base::string16& sync_primitive_name_suffix); | |
76 | |
77 // A mutex that must be held to modify the Chrome installation directory. | |
78 base::win::ScopedHandle setup_mutex_; | |
79 | |
80 // Holds |setup_mutex_| throughout the lifetime of this SetupSingleton. | |
81 ScopedHoldMutex scoped_hold_setup_mutex_; | |
82 | |
83 // An event signaled to ask the owner of |setup_mutex_| to release it as soon | |
84 // as possible. | |
85 base::WaitableEvent exit_event_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(SetupSingleton); | |
88 }; | |
89 | |
90 } // namespace installer | |
91 | |
92 #endif // CHROME_INSTALLER_SETUP_SETUP_SINGLETON_H_ | |
OLD | NEW |