Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 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_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ | |
| 6 #define CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/lazy_instance.h" | |
| 10 #include "base/synchronization/lock.h" | |
| 11 | |
| 12 // A helper class to override HKEY_CURRENT_USER to point to a test key from this | |
| 13 // process' point of view. Also provides functionality (via an environment | |
| 14 // variable) to let child processes check whether they should also override. | |
| 15 // Always unsets any existing override upon being deleted. | |
| 16 class IEImporterTestRegistryOverrider { | |
| 17 public: | |
| 18 IEImporterTestRegistryOverrider(); | |
| 19 | |
| 20 // Unsets any existing registry override and deletes the temporary registry | |
| 21 // key if |override_set_by_current_process_|. | |
| 22 ~IEImporterTestRegistryOverrider(); | |
| 23 | |
| 24 // Calls StartRegistryOverride() and sets an environment variable so that | |
| 25 // future calls to StartRegistryOverrideIfNeeded() from child processes also | |
| 26 // result in an overriden registry. This method should only be called once | |
|
robertshield
2013/04/30 03:15:42
nit: registry -> HKEY_CURRENT_USER hive.
gab
2013/04/30 21:44:52
Done.
| |
| 27 // across all processes. | |
| 28 // Returns false on unexpected failure. | |
| 29 bool SetRegistryOverride(); | |
| 30 | |
| 31 // Calls StartRegistryOverride() if the environment was set by a parent | |
| 32 // process via SetRegistryOverride(). | |
| 33 // Returns false on unexpected failure. | |
| 34 bool StartRegistryOverrideIfNeeded(); | |
| 35 | |
| 36 private: | |
| 37 // Overrides HKCU to point to a test key from this process' point of view. | |
| 38 // Ignored if this process is already overriding the registry. | |
| 39 // Returns false on unexpected failure. | |
| 40 bool StartRegistryOverride(); | |
| 41 | |
| 42 // Returns true if the environment indicates that an override is taking place. | |
| 43 bool IsEnvironmentSet(); | |
| 44 | |
| 45 // Whether this object started an override for the current process (and thus | |
| 46 // should undo it when done). | |
| 47 bool in_process_override_started_by_this_; | |
|
robertshield
2013/04/30 03:15:42
nit: rename to override_performed_.
gab
2013/04/30 21:44:52
Done.
| |
| 48 | |
| 49 // Whether this object is the one that set the override (and thus will be | |
| 50 // the one in charge of deleting the temporary key when done). | |
| 51 bool override_set_by_this_; | |
|
robertshield
2013/04/30 03:15:42
maybe override_initiated_?
gab
2013/04/30 21:44:52
Done.
| |
| 52 | |
| 53 // Whether a registry override was initiated in the current process. Accesses | |
| 54 // to this variable should only be made while holding |lock_|. | |
| 55 static bool override_active_in_process_; | |
| 56 static base::LazyInstance<base::Lock>::Leaky lock_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(IEImporterTestRegistryOverrider); | |
| 59 }; | |
| 60 | |
| 61 #endif // CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ | |
| OLD | NEW |