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

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

Issue 2926453002: Fix a race condition in ~RegistryHashStoreContentsWin (Closed)
Patch Set: Add file I forgot to git add 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
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"
19 #include "services/preferences/tracked/tracked_preferences_migration.h" 20 #include "services/preferences/tracked/tracked_preferences_migration.h"
20 21
21 #if defined(OS_WIN) 22 #if defined(OS_WIN)
23 #include "base/files/scoped_temp_dir.h"
24 #include "base/strings/string_util.h"
22 #include "services/preferences/tracked/registry_hash_store_contents_win.h" 25 #include "services/preferences/tracked/registry_hash_store_contents_win.h"
23 #endif 26 #endif
24 27
25 namespace { 28 namespace {
26 29
27 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store, 30 void RemoveValueSilently(const base::WeakPtr<JsonPrefStore> pref_store,
28 const std::string& key) { 31 const std::string& key) {
29 if (pref_store) { 32 if (pref_store) {
30 pref_store->RemoveValueSilently( 33 pref_store->RemoveValueSilently(
31 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 34 key, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
32 } 35 }
33 } 36 }
34 37
35 std::unique_ptr<PrefHashStore> CreatePrefHashStore( 38 std::unique_ptr<PrefHashStore> CreatePrefHashStore(
36 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config, 39 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config,
37 bool use_super_mac) { 40 bool use_super_mac) {
38 return base::MakeUnique<PrefHashStoreImpl>( 41 return base::MakeUnique<PrefHashStoreImpl>(
39 config.seed, config.legacy_device_id, use_super_mac); 42 config.seed, config.legacy_device_id, use_super_mac);
40 } 43 }
41 44
42 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>> 45 std::pair<std::unique_ptr<PrefHashStore>, std::unique_ptr<HashStoreContents>>
43 GetExternalVerificationPrefHashStorePair( 46 GetExternalVerificationPrefHashStorePair(
44 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config) { 47 const prefs::mojom::TrackedPersistentPrefStoreConfiguration& config,
48 scoped_refptr<TempScopedDirCleaner> temp_dir_cleaner) {
45 #if defined(OS_WIN) 49 #if defined(OS_WIN)
46 return std::make_pair( 50 return std::make_pair(base::MakeUnique<PrefHashStoreImpl>(
47 base::MakeUnique<PrefHashStoreImpl>(config.registry_seed, 51 config.registry_seed, config.legacy_device_id,
48 config.legacy_device_id, 52 false /* use_super_mac */),
49 false /* use_super_mac */), 53 base::MakeUnique<RegistryHashStoreContentsWin>(
50 base::MakeUnique<RegistryHashStoreContentsWin>( 54 config.registry_path,
51 config.registry_path, config.unprotected_pref_filename.DirName() 55 config.unprotected_pref_filename.DirName()
52 .BaseName() 56 .BaseName()
53 .LossyDisplayName())); 57 .LossyDisplayName(),
58 temp_dir_cleaner));
gab 2017/06/12 15:52:17 std::move
proberge 2017/06/12 18:46:02 Done.
54 #else 59 #else
55 return std::make_pair(nullptr, nullptr); 60 return std::make_pair(nullptr, nullptr);
56 #endif 61 #endif
57 } 62 }
58 63
59 } // namespace 64 } // namespace
60 65
61 PersistentPrefStore* CreateTrackedPersistentPrefStore( 66 PersistentPrefStore* CreateTrackedPersistentPrefStore(
62 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr config, 67 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr config,
63 base::SequencedWorkerPool* worker_pool) { 68 base::SequencedWorkerPool* worker_pool) {
(...skipping 11 matching lines...) Expand all
75 EnforcementLevel::NO_ENFORCEMENT) { 80 EnforcementLevel::NO_ENFORCEMENT) {
76 protected_pref_names.insert(metadata->name); 81 protected_pref_names.insert(metadata->name);
77 protected_configuration.push_back(std::move(metadata)); 82 protected_configuration.push_back(std::move(metadata));
78 } else { 83 } else {
79 unprotected_pref_names.insert(metadata->name); 84 unprotected_pref_names.insert(metadata->name);
80 unprotected_configuration.push_back(std::move(metadata)); 85 unprotected_configuration.push_back(std::move(metadata));
81 } 86 }
82 } 87 }
83 config->tracking_configuration.clear(); 88 config->tracking_configuration.clear();
84 89
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 = new TempScopedDirRegistryCleaner();
gab 2017/06/12 15:52:16 MakeRefCounted
proberge 2017/06/12 18:46:02 Done.
102 }
103 #endif
104
85 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( 105 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
86 new PrefHashFilter(CreatePrefHashStore(*config, false), 106 new PrefHashFilter(CreatePrefHashStore(*config, false),
87 GetExternalVerificationPrefHashStorePair(*config), 107 GetExternalVerificationPrefHashStorePair(
108 *config, temp_scoped_dir_cleaner),
88 unprotected_configuration, nullptr, 109 unprotected_configuration, nullptr,
89 config->validation_delegate.get(), 110 config->validation_delegate.get(),
90 config->reporting_ids_count, false)); 111 config->reporting_ids_count, false));
91 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( 112 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
92 CreatePrefHashStore(*config, true), 113 CreatePrefHashStore(*config, true),
93 GetExternalVerificationPrefHashStorePair(*config), 114 GetExternalVerificationPrefHashStorePair(*config,
115 temp_scoped_dir_cleaner),
94 protected_configuration, std::move(config->reset_on_load_observer), 116 protected_configuration, std::move(config->reset_on_load_observer),
95 config->validation_delegate.get(), config->reporting_ids_count, true)); 117 config->validation_delegate.get(), config->reporting_ids_count, true));
96 118
97 PrefHashFilter* raw_unprotected_pref_hash_filter = 119 PrefHashFilter* raw_unprotected_pref_hash_filter =
98 unprotected_pref_hash_filter.get(); 120 unprotected_pref_hash_filter.get();
99 PrefHashFilter* raw_protected_pref_hash_filter = 121 PrefHashFilter* raw_protected_pref_hash_filter =
100 protected_pref_hash_filter.get(); 122 protected_pref_hash_filter.get();
101 123
102 scoped_refptr<JsonPrefStore> unprotected_pref_store( 124 scoped_refptr<JsonPrefStore> unprotected_pref_store(
103 new JsonPrefStore(config->unprotected_pref_filename, io_task_runner.get(), 125 new JsonPrefStore(config->unprotected_pref_filename, io_task_runner.get(),
(...skipping 14 matching lines...) Expand all
118 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter); 140 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter);
119 141
120 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, 142 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
121 protected_pref_names, 143 protected_pref_names,
122 std::move(config->validation_delegate)); 144 std::move(config->validation_delegate));
123 } 145 }
124 146
125 void InitializeMasterPrefsTracking( 147 void InitializeMasterPrefsTracking(
126 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration, 148 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration,
127 base::DictionaryValue* master_prefs) { 149 base::DictionaryValue* master_prefs) {
128 PrefHashFilter(CreatePrefHashStore(*configuration, false), 150 PrefHashFilter(
129 GetExternalVerificationPrefHashStorePair(*configuration), 151 CreatePrefHashStore(*configuration, false),
130 configuration->tracking_configuration, nullptr, nullptr, 152 GetExternalVerificationPrefHashStorePair(*configuration, nullptr),
131 configuration->reporting_ids_count, false) 153 configuration->tracking_configuration, nullptr, nullptr,
154 configuration->reporting_ids_count, false)
132 .Initialize(master_prefs); 155 .Initialize(master_prefs);
133 } 156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698