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

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 temp_scoped_dir_cleaner to a build file 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"
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 std::move(temp_dir_cleaner)));
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 =
102 base::MakeRefCounted<TempScopedDirRegistryCleaner>();
103 }
104 #endif
105
85 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter( 106 std::unique_ptr<PrefHashFilter> unprotected_pref_hash_filter(
86 new PrefHashFilter(CreatePrefHashStore(*config, false), 107 new PrefHashFilter(CreatePrefHashStore(*config, false),
87 GetExternalVerificationPrefHashStorePair(*config), 108 GetExternalVerificationPrefHashStorePair(
109 *config, temp_scoped_dir_cleaner),
88 unprotected_configuration, nullptr, 110 unprotected_configuration, nullptr,
89 config->validation_delegate.get(), 111 config->validation_delegate.get(),
90 config->reporting_ids_count, false)); 112 config->reporting_ids_count, false));
91 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter( 113 std::unique_ptr<PrefHashFilter> protected_pref_hash_filter(new PrefHashFilter(
92 CreatePrefHashStore(*config, true), 114 CreatePrefHashStore(*config, true),
93 GetExternalVerificationPrefHashStorePair(*config), 115 GetExternalVerificationPrefHashStorePair(*config,
116 temp_scoped_dir_cleaner),
94 protected_configuration, std::move(config->reset_on_load_observer), 117 protected_configuration, std::move(config->reset_on_load_observer),
95 config->validation_delegate.get(), config->reporting_ids_count, true)); 118 config->validation_delegate.get(), config->reporting_ids_count, true));
96 119
97 PrefHashFilter* raw_unprotected_pref_hash_filter = 120 PrefHashFilter* raw_unprotected_pref_hash_filter =
98 unprotected_pref_hash_filter.get(); 121 unprotected_pref_hash_filter.get();
99 PrefHashFilter* raw_protected_pref_hash_filter = 122 PrefHashFilter* raw_protected_pref_hash_filter =
100 protected_pref_hash_filter.get(); 123 protected_pref_hash_filter.get();
101 124
102 scoped_refptr<JsonPrefStore> unprotected_pref_store( 125 scoped_refptr<JsonPrefStore> unprotected_pref_store(
103 new JsonPrefStore(config->unprotected_pref_filename, io_task_runner.get(), 126 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); 141 raw_unprotected_pref_hash_filter, raw_protected_pref_hash_filter);
119 142
120 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store, 143 return new SegregatedPrefStore(unprotected_pref_store, protected_pref_store,
121 protected_pref_names, 144 protected_pref_names,
122 std::move(config->validation_delegate)); 145 std::move(config->validation_delegate));
123 } 146 }
124 147
125 void InitializeMasterPrefsTracking( 148 void InitializeMasterPrefsTracking(
126 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration, 149 prefs::mojom::TrackedPersistentPrefStoreConfigurationPtr configuration,
127 base::DictionaryValue* master_prefs) { 150 base::DictionaryValue* master_prefs) {
128 PrefHashFilter(CreatePrefHashStore(*configuration, false), 151 PrefHashFilter(
129 GetExternalVerificationPrefHashStorePair(*configuration), 152 CreatePrefHashStore(*configuration, false),
130 configuration->tracking_configuration, nullptr, nullptr, 153 GetExternalVerificationPrefHashStorePair(*configuration, nullptr),
131 configuration->reporting_ids_count, false) 154 configuration->tracking_configuration, nullptr, nullptr,
155 configuration->reporting_ids_count, false)
132 .Initialize(master_prefs); 156 .Initialize(master_prefs);
133 } 157 }
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