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

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

Issue 15736014: Registry overriding doesn't seem to work across multiple processes prior to Win8, instead simply ha… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ 5 #ifndef CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_
6 #define CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ 6 #define CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/lazy_instance.h"
10 #include "base/string16.h" 9 #include "base/string16.h"
11 #include "base/synchronization/lock.h"
12 10
13 // A helper class to override HKEY_CURRENT_USER to point to a test key from this 11 // A helper class to let tests generate a random registry key to be used in
14 // process' point of view. Uses a random guid as a subkey for the override in 12 // HKEY_CURRENT_USER in tests. After the key has been generated by constructing
15 // order for multiple tests to be able to use this functionality in parallel. 13 // an IEImporterTestRegistryOverrider, consumers in this process (or in any
16 // Also provides functionality (via an environment variable) to let child 14 // child processes created after the key has been generated) can obtain the key
17 // processes check whether they should also override. This class is thread-safe. 15 // via GetTestRegistryOverride(). IEImporterTestRegistryOverrider will delete
18 // Always unsets any existing override upon being deleted. 16 // the temporary key upon being deleted itself. Only one
17 // IEImporterTestRegistryOverrider should live at once in a given process
18 // hiearchy.
19 class IEImporterTestRegistryOverrider { 19 class IEImporterTestRegistryOverrider {
20 public: 20 public:
21 IEImporterTestRegistryOverrider(); 21 IEImporterTestRegistryOverrider();
22
23 // Unsets any existing registry override and deletes the temporary registry
24 // key if |override_initiated_|.
25 ~IEImporterTestRegistryOverrider(); 22 ~IEImporterTestRegistryOverrider();
26 23
27 // Calls StartRegistryOverride() and sets an environment variable so that 24 // Returns a test key if one was chosen and set by a call to
28 // future calls to StartRegistryOverrideIfNeeded() from child processes also 25 // SetTestRegistryOverride(); returns the empty string if none.
29 // result in an overriden HKEY_CURRENT_USER hive. This method should only be 26 static base::string16 GetTestRegistryOverride();
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 27
39 private: 28 private:
40 // Overrides HKCU to point to a test key (ending with |subkey|) from this 29 base::string16 temporary_key_;
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 // Reads the environment variable set by SetRegistryOverride into |subkey| if
47 // it exists. Returns true if the variable was successfully read.
48 bool GetSubKeyFromEnvironment(base::string16* subkey);
49
50 // Whether this object started an override for the current process (and thus
51 // will be responsible for unsetting it when done).
52 bool override_performed_;
53
54 // Whether this object is the one that initiated the override via
55 // SetRegistryOverride() (and thus will be the one responsible for deleting
56 // the temporary key when done).
57 bool override_initiated_;
58
59 // Whether a registry override was initiated in the current process.
60 static bool override_active_in_process_;
61
62 // This lock should be held before accessing this class' static data and any
63 // of its objects' members.
64 static base::LazyInstance<base::Lock>::Leaky lock_;
65 30
66 DISALLOW_COPY_AND_ASSIGN(IEImporterTestRegistryOverrider); 31 DISALLOW_COPY_AND_ASSIGN(IEImporterTestRegistryOverrider);
67 }; 32 };
68 33
69 #endif // CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_ 34 #endif // CHROME_BROWSER_IMPORTER_IE_IMPORTER_TEST_REGISTRY_OVERRIDER_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698