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

Side by Side Diff: chrome/browser/importer/ie_importer_test_registry_overrider_win.h

Issue 14143010: Introduce IEImporterTestRegistryOverrider to be able to override the registry for a test and flag t… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Works :) -- fix interface comments and remove logs Created 7 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/string16.h"
11 #include "base/synchronization/lock.h"
12
13 // A helper class to override HKEY_CURRENT_USER to point to a test key from this
14 // process' point of view. Uses a random guid as a subkey for the override in
15 // order for multiple tests to be able to use this functionality in parallel.
16 // Also provides functionality (via an environment variable) to let child
17 // processes check whether they should also override. This class is thread-safe.
18 // Always unsets any existing override upon being deleted.
19 class IEImporterTestRegistryOverrider {
20 public:
21 IEImporterTestRegistryOverrider();
22
23 // Unsets any existing registry override and deletes the temporary registry
24 // key if |override_initiated_|.
25 ~IEImporterTestRegistryOverrider();
26
27 // Calls StartRegistryOverride() and sets an environment variable so that
28 // future calls to StartRegistryOverrideIfNeeded() from child processes also
29 // result in an overriden HKEY_CURRENT_USER hive. This method should only be
30 // called once across all processes.
31 // Returns false on unexpected failure.
32 bool SetRegistryOverride();
33
34 // Calls StartRegistryOverride() if the environment was set by a parent
35 // process via SetRegistryOverride().
36 // Returns false on unexpected failure.
37 bool StartRegistryOverrideIfNeeded();
38
39 private:
40 // Overrides HKCU to point to a test key (ending with |subkey|) from this
41 // process' point of view. Re-applies the override without taking ownership if
42 // |override_active_in_process_|.
43 // Returns false on unexpected failure.
44 bool StartRegistryOverride(const base::string16& subkey);
45
46 // Whether this object started an override for the current process (and thus
47 // will be responsible for unsetting it when done).
48 bool override_performed_;
49
50 // Whether this object is the one that initiated the override via
51 // SetRegistryOverride() (and thus will be the one responsible for deleting
52 // the temporary key when done).
53 bool override_initiated_;
54
55 // Whether a registry override was initiated in the current process.
56 static bool override_active_in_process_;
57
58 // This lock should be held before accessing this class' static data and any
59 // of its objects' members.
60 static base::LazyInstance<base::Lock>::Leaky lock_;
61
62 DISALLOW_COPY_AND_ASSIGN(IEImporterTestRegistryOverrider);
63 };
64
65 #endif // CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698