Index: chrome/browser/importer/ie_importer_test_registry_overrider_win.h |
diff --git a/chrome/browser/importer/ie_importer_test_registry_overrider_win.h b/chrome/browser/importer/ie_importer_test_registry_overrider_win.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ee843f5a492d652841efe78f62288c6ba8dd27cc |
--- /dev/null |
+++ b/chrome/browser/importer/ie_importer_test_registry_overrider_win.h |
@@ -0,0 +1,61 @@ |
+// Copyright (c) 2013 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_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ |
+#define CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/lazy_instance.h" |
+#include "base/synchronization/lock.h" |
+ |
+// A helper class to override HKEY_CURRENT_USER to point to a test key from this |
+// process' point of view. Also provides functionality (via an environment |
+// variable) to let child processes check whether they should also override. |
+// Always unsets any existing override upon being deleted. |
+class IEImporterTestRegistryOverrider { |
+ public: |
+ IEImporterTestRegistryOverrider(); |
+ |
+ // Unsets any existing registry override and deletes the temporary registry |
+ // key if |override_set_by_current_process_|. |
+ ~IEImporterTestRegistryOverrider(); |
+ |
+ // Calls StartRegistryOverride() and sets an environment variable so that |
+ // future calls to StartRegistryOverrideIfNeeded() from child processes also |
+ // 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.
|
+ // across all processes. |
+ // Returns false on unexpected failure. |
+ bool SetRegistryOverride(); |
+ |
+ // Calls StartRegistryOverride() if the environment was set by a parent |
+ // process via SetRegistryOverride(). |
+ // Returns false on unexpected failure. |
+ bool StartRegistryOverrideIfNeeded(); |
+ |
+ private: |
+ // Overrides HKCU to point to a test key from this process' point of view. |
+ // Ignored if this process is already overriding the registry. |
+ // Returns false on unexpected failure. |
+ bool StartRegistryOverride(); |
+ |
+ // Returns true if the environment indicates that an override is taking place. |
+ bool IsEnvironmentSet(); |
+ |
+ // Whether this object started an override for the current process (and thus |
+ // should undo it when done). |
+ 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.
|
+ |
+ // Whether this object is the one that set the override (and thus will be |
+ // the one in charge of deleting the temporary key when done). |
+ bool override_set_by_this_; |
robertshield
2013/04/30 03:15:42
maybe override_initiated_?
gab
2013/04/30 21:44:52
Done.
|
+ |
+ // Whether a registry override was initiated in the current process. Accesses |
+ // to this variable should only be made while holding |lock_|. |
+ static bool override_active_in_process_; |
+ static base::LazyInstance<base::Lock>::Leaky lock_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(IEImporterTestRegistryOverrider); |
+}; |
+ |
+#endif // CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ |