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

Side by Side Diff: services/preferences/tracked/tracked_persistent_pref_store_factory.cc

Issue 2937633003: Revert of Fix a race condition in ~RegistryHashStoreContentsWin (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « services/preferences/tracked/temp_scoped_dir_cleaner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #include "services/preferences/tracked/tracked_persistent_pref_store_factory.h" 5 #include "services/preferences/tracked/tracked_persistent_pref_store_factory.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "components/prefs/json_pref_store.h" 13 #include "components/prefs/json_pref_store.h"
14 #include "components/prefs/pref_filter.h" 14 #include "components/prefs/pref_filter.h"
15 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h" 15 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h"
16 #include "services/preferences/tracked/pref_hash_filter.h" 16 #include "services/preferences/tracked/pref_hash_filter.h"
17 #include "services/preferences/tracked/pref_hash_store_impl.h" 17 #include "services/preferences/tracked/pref_hash_store_impl.h"
18 #include "services/preferences/tracked/segregated_pref_store.h" 18 #include "services/preferences/tracked/segregated_pref_store.h"
19 #include "services/preferences/tracked/temp_scoped_dir_cleaner.h"
20 #include "services/preferences/tracked/tracked_preferences_migration.h" 19 #include "services/preferences/tracked/tracked_preferences_migration.h"
21 20
22 #if defined(OS_WIN) 21 #if defined(OS_WIN)
23 #include "base/files/scoped_temp_dir.h"
24 #include "base/strings/string_util.h"
25 #include "services/preferences/tracked/registry_hash_store_contents_win.h" 22 #include "services/preferences/tracked/registry_hash_store_contents_win.h"
26 #endif 23 #endif
27 24
28 namespace { 25 namespace {
29 26
30 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, 27 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
31 const std::string& key) { 28 const std::string& key) {
32 if (pref_store) { 29 if (pref_store) {
33 pref_store->RemoveValueSilently( 30 pref_store->RemoveValueSilently(
34 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 31 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
35 } 32 }
36 } 33 }
37 34
38 std::unique_ptr<PrefHashStore> CreatePrefHashStore( 35 std::unique_ptr<PrefHashStore> CreatePrefHashStore(
39 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config, 36 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config,
40 bool use_super_mac) { 37 bool use_super_mac) {
41 return base::MakeUnique<PrefHashStoreImpl>( 38 return base::MakeUnique<PrefHashStoreImpl>(
42 config.seed, config.legacy_device_id, use_super_mac); 39 config.seed, config.legacy_device_id, use_super_mac);
43 } 40 }
44 41
45 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>> 42 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
46 GetExternalVerificationPrefHashStorePair( 43 GetExternalVerificationPrefHashStorePair(
47 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config, 44 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config) {
48 scoped_refptr<TempScopedDirCleaner> temp_dir_cleaner) {
49 #if defined(OS_WIN) 45 #if defined(OS_WIN)
50 return std::make_pair(base::MakeUnique<PrefHashStoreImpl>( 46 return std::make_pair(
51 config.registry_seed, config.legacy_device_id, 47 base::MakeUnique<PrefHashStoreImpl>(config.registry_seed,
52 false /* use_super_mac */), 48 config.legacy_device_id,
53 base::MakeUnique<RegistryHashStoreContentsWin>( 49 false /* use_super_mac */),
54 config.registry_path, 50 base::MakeUnique<RegistryHashStoreContentsWin>(
55 config.unprotected_pref_filename.DirName() 51 config.registry_path, config.unprotected_pref_filename.DirName()
56 .BaseName() 52 .BaseName()
57 .LossyDisplayName(), 53 .LossyDisplayName()));
58 std::move(temp_dir_cleaner)));
59 #else 54 #else
60 return std::make_pair(nullptr, nullptr); 55 return std::make_pair(nullptr, nullptr);
61 #endif 56 #endif
62 } 57 }
63 58
64 } // namespace 59 } // namespace
65 60
66 PersistentPrefStore* CreateTrackedPersistentPrefStore( 61 PersistentPrefStore* CreateTrackedPersistentPrefStore(
67 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr config, 62 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr config,
68 base::SequencedWorkerPool* worker_pool) { 63 base::SequencedWorkerPool* worker_pool) {
(...skipping 11 matching lines...) Expand all
80 EnforcementLevel::NO_ENFORCEMENT) { 75 EnforcementLevel::NO_ENFORCEMENT) {
81 protected_pref_names.insert(metadata->name); 76 protected_pref_names.insert(metadata->name);
82 protected_configuration.push_back(std::move(metadata)); 77 protected_configuration.push_back(std::move(metadata));
83 } else { 78 } else {
84 unprotected_pref_names.insert(metadata->name); 79 unprotected_pref_names.insert(metadata->name);
85 unprotected_configuration.push_back(std::move(metadata)); 80 unprotected_configuration.push_back(std::move(metadata));
86 } 81 }
87 } 82 }
88 config->tracking_configuration.clear(); 83 config->tracking_configuration.clear();
89 84
90 scoped_refptr<TempScopedDirCleaner> temp_scoped_dir_cleaner;
91 #if defined(OS_WIN)
92 // For tests that create a profile in a ScopedTempDir, share a ref_counted
93 // object between the unprotected and protected hash filter's
94 // RegistryHashStoreContentsWin which will clear the registry keys when
95 // destroyed. (https://crbug.com/721245)
96 if (base::StartsWith(config->unprotected_pref_filename.DirName()
97 .BaseName()
98 .LossyDisplayName(),
99 base::ScopedTempDir::GetTempDirPrefix(),
100 base::CompareCase::INSENSITIVE_ASCII)) {
101 temp_scoped_dir_cleaner =
102 base::MakeRefCounted<TempScopedDirRegistryCleaner>();
103 }
104 #endif
105
106 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( 85 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
107 new PrefHashFilter(CreatePrefHashStore(*config, false), 86 new PrefHashFilter(CreatePrefHashStore(*config, false),
108 GetExternalVerificationPrefHashStorePair( 87 GetExternalVerificationPrefHashStorePair(*config),
109 *config, temp_scoped_dir_cleaner),
110 unprotected_configuration, nullptr, 88 unprotected_configuration, nullptr,
111 config->validation_delegate.get(), 89 config->validation_delegate.get(),
112 config->reporting_ids_count, false)); 90 config->reporting_ids_count, false));
113 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( 91 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
114 CreatePrefHashStore(*config, true), 92 CreatePrefHashStore(*config, true),
115 GetExternalVerificationPrefHashStorePair(*config, 93 GetExternalVerificationPrefHashStorePair(*config),
116 temp_scoped_dir_cleaner),
117 protected_configuration, std::move(config->reset_on_load_observer), 94 protected_configuration, std::move(config->reset_on_load_observer),
118 config->validation_delegate.get(), config->reporting_ids_count, true)); 95 config->validation_delegate.get(), config->reporting_ids_count, true));
119 96
120 PrefHashFilter* raw_unprotected_pref_hash_filter = 97 PrefHashFilter* raw_unprotected_pref_hash_filter =
121 unprotected_pref_hash_filter.get(); 98 unprotected_pref_hash_filter.get();
122 PrefHashFilter* raw_protected_pref_hash_filter = 99 PrefHashFilter* raw_protected_pref_hash_filter =
123 protected_pref_hash_filter.get(); 100 protected_pref_hash_filter.get();
124 101
125 scoped_refptr<JsonPrefStore> unprotected_pref_store( 102 scoped_refptr<JsonPrefStore> unprotected_pref_store(
126 new JsonPrefStore(config->unprotected_pref_filename, io_task_runner.get(), 103 new JsonPrefStore(config->unprotected_pref_filename, io_task_runner.get(),
(...skipping 14 matching lines...) Expand all
141 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter); 118 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter);
142 119
143 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, 120 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
144 protected_pref_names, 121 protected_pref_names,
145 std::move(config->validation_delegate)); 122 std::move(config->validation_delegate));
146 } 123 }
147 124
148 void InitializeMasterPrefsTracking( 125 void InitializeMasterPrefsTracking(
149 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration, 126 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration,
150 base::DictionaryValue* master_prefs) { 127 base::DictionaryValue* master_prefs) {
151 PrefHashFilter( 128 PrefHashFilter(CreatePrefHashStore(*configuration, false),
152 CreatePrefHashStore(*configuration, false), 129 GetExternalVerificationPrefHashStorePair(*configuration),
153 GetExternalVerificationPrefHashStorePair(*configuration, nullptr), 130 configuration->tracking_configuration, nullptr, nullptr,
154 configuration->tracking_configuration, nullptr, nullptr, 131 configuration->reporting_ids_count, false)
155 configuration->reporting_ids_count, false)
156 .Initialize(master_prefs); 132 .Initialize(master_prefs);
157 } 133 }
OLDNEW
« no previous file with comments | « services/preferences/tracked/temp_scoped_dir_cleaner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698