OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/content_settings/core/browser/content_settings_pref.h" | 5 #include "components/content_settings/core/browser/content_settings_pref.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
13 #include "components/content_settings/core/browser/content_settings_info.h" | 14 #include "components/content_settings/core/browser/content_settings_info.h" |
14 #include "components/content_settings/core/browser/content_settings_registry.h" | 15 #include "components/content_settings/core/browser/content_settings_registry.h" |
15 #include "components/content_settings/core/browser/content_settings_rule.h" | 16 #include "components/content_settings/core/browser/content_settings_rule.h" |
16 #include "components/content_settings/core/browser/content_settings_utils.h" | 17 #include "components/content_settings/core/browser/content_settings_utils.h" |
17 #include "components/content_settings/core/browser/host_content_settings_map.h" | 18 #include "components/content_settings/core/browser/host_content_settings_map.h" |
18 #include "components/content_settings/core/common/content_settings.h" | 19 #include "components/content_settings/core/common/content_settings.h" |
19 #include "components/content_settings/core/common/content_settings_pattern.h" | 20 #include "components/content_settings/core/common/content_settings_pattern.h" |
20 #include "components/content_settings/core/common/pref_names.h" | 21 #include "components/content_settings/core/common/pref_names.h" |
21 #include "components/prefs/scoped_user_pref_update.h" | 22 #include "components/prefs/scoped_user_pref_update.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 const char kSettingPath[] = "setting"; | 27 const char kSettingPath[] = "setting"; |
| 28 const char kLastModifiedPath[] = "last_modified"; |
27 const char kPerResourceIdentifierPrefName[] = "per_resource"; | 29 const char kPerResourceIdentifierPrefName[] = "per_resource"; |
28 | 30 |
29 // If the given content type supports resource identifiers in user preferences, | 31 // If the given content type supports resource identifiers in user preferences, |
30 // returns true and sets |pref_key| to the key in the content settings | 32 // returns true and sets |pref_key| to the key in the content settings |
31 // dictionary under which per-resource content settings are stored. | 33 // dictionary under which per-resource content settings are stored. |
32 // Otherwise, returns false. | 34 // Otherwise, returns false. |
33 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { | 35 bool SupportsResourceIdentifiers(ContentSettingsType content_type) { |
34 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 36 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
35 } | 37 } |
36 | 38 |
37 bool IsValueAllowedForType(const base::Value* value, ContentSettingsType type) { | 39 bool IsValueAllowedForType(const base::Value* value, ContentSettingsType type) { |
38 const content_settings::ContentSettingsInfo* info = | 40 const content_settings::ContentSettingsInfo* info = |
39 content_settings::ContentSettingsRegistry::GetInstance()->Get(type); | 41 content_settings::ContentSettingsRegistry::GetInstance()->Get(type); |
40 if (info) { | 42 if (info) { |
41 int setting; | 43 int setting; |
42 if (!value->GetAsInteger(&setting)) | 44 if (!value->GetAsInteger(&setting)) |
43 return false; | 45 return false; |
44 if (setting == CONTENT_SETTING_DEFAULT) | 46 if (setting == CONTENT_SETTING_DEFAULT) |
45 return false; | 47 return false; |
46 return info->IsSettingValid(IntToContentSetting(setting)); | 48 return info->IsSettingValid(IntToContentSetting(setting)); |
47 } | 49 } |
48 | 50 |
49 // TODO(raymes): We should permit different types of base::Value for | 51 // TODO(raymes): We should permit different types of base::Value for |
50 // website settings. | 52 // website settings. |
51 return value->GetType() == base::Value::Type::DICTIONARY; | 53 return value->GetType() == base::Value::Type::DICTIONARY; |
52 } | 54 } |
53 | 55 |
| 56 // Extract a timestamp from |dictionary[kLastModifiedPath]|. |
| 57 // Will return base::Time() if no timestamp exists. |
| 58 base::Time GetTimeStamp(const base::DictionaryValue* dictionary) { |
| 59 std::string timestamp_str; |
| 60 dictionary->GetStringWithoutPathExpansion(kLastModifiedPath, ×tamp_str); |
| 61 int64_t timestamp = 0; |
| 62 base::StringToInt64(timestamp_str, ×tamp); |
| 63 base::Time last_modified = base::Time::FromInternalValue(timestamp); |
| 64 return last_modified; |
| 65 } |
| 66 |
54 } // namespace | 67 } // namespace |
55 | 68 |
56 namespace content_settings { | 69 namespace content_settings { |
57 | 70 |
58 ContentSettingsPref::ContentSettingsPref( | 71 ContentSettingsPref::ContentSettingsPref( |
59 ContentSettingsType content_type, | 72 ContentSettingsType content_type, |
60 PrefService* prefs, | 73 PrefService* prefs, |
61 PrefChangeRegistrar* registrar, | 74 PrefChangeRegistrar* registrar, |
62 const std::string& pref_name, | 75 const std::string& pref_name, |
63 bool incognito, | 76 bool incognito, |
| 77 bool store_last_modified, |
64 NotifyObserversCallback notify_callback) | 78 NotifyObserversCallback notify_callback) |
65 : content_type_(content_type), | 79 : content_type_(content_type), |
66 prefs_(prefs), | 80 prefs_(prefs), |
67 registrar_(registrar), | 81 registrar_(registrar), |
68 pref_name_(pref_name), | 82 pref_name_(pref_name), |
69 is_incognito_(incognito), | 83 is_incognito_(incognito), |
| 84 store_last_modified_(store_last_modified), |
70 updating_preferences_(false), | 85 updating_preferences_(false), |
71 notify_callback_(notify_callback) { | 86 notify_callback_(notify_callback) { |
72 DCHECK(prefs_); | 87 DCHECK(prefs_); |
73 | 88 |
74 ReadContentSettingsFromPref(); | 89 ReadContentSettingsFromPref(); |
75 | 90 |
76 registrar_->Add( | 91 registrar_->Add( |
77 pref_name_, | 92 pref_name_, |
78 base::Bind(&ContentSettingsPref::OnPrefChanged, base::Unretained(this))); | 93 base::Bind(&ContentSettingsPref::OnPrefChanged, base::Unretained(this))); |
79 } | 94 } |
(...skipping 24 matching lines...) Expand all Loading... |
104 !resource_identifier.empty()); | 119 !resource_identifier.empty()); |
105 | 120 |
106 // At this point take the ownership of the |in_value|. | 121 // At this point take the ownership of the |in_value|. |
107 std::unique_ptr<base::Value> value(in_value); | 122 std::unique_ptr<base::Value> value(in_value); |
108 | 123 |
109 // Update in memory value map. | 124 // Update in memory value map. |
110 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; | 125 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
111 if (!is_incognito_) | 126 if (!is_incognito_) |
112 map_to_modify = &value_map_; | 127 map_to_modify = &value_map_; |
113 | 128 |
| 129 base::Time modified_time = |
| 130 store_last_modified_ ? base::Time::Now() : base::Time(); |
| 131 |
114 { | 132 { |
115 base::AutoLock auto_lock(lock_); | 133 base::AutoLock auto_lock(lock_); |
116 if (value.get()) { | 134 if (value.get()) { |
117 map_to_modify->SetValue( | 135 map_to_modify->SetValue(primary_pattern, secondary_pattern, content_type_, |
118 primary_pattern, | 136 resource_identifier, modified_time, |
119 secondary_pattern, | 137 value->DeepCopy()); |
120 content_type_, | |
121 resource_identifier, | |
122 value->DeepCopy()); | |
123 } else { | 138 } else { |
124 map_to_modify->DeleteValue( | 139 map_to_modify->DeleteValue( |
125 primary_pattern, | 140 primary_pattern, |
126 secondary_pattern, | 141 secondary_pattern, |
127 content_type_, | 142 content_type_, |
128 resource_identifier); | 143 resource_identifier); |
129 } | 144 } |
130 } | 145 } |
131 // Update the content settings preference. | 146 // Update the content settings preference. |
132 if (!is_incognito_) { | 147 if (!is_incognito_) { |
133 UpdatePref(primary_pattern, | 148 UpdatePref(primary_pattern, secondary_pattern, resource_identifier, |
134 secondary_pattern, | 149 modified_time, value.get()); |
135 resource_identifier, | |
136 value.get()); | |
137 } | 150 } |
138 | 151 |
139 notify_callback_.Run( | 152 notify_callback_.Run( |
140 primary_pattern, secondary_pattern, content_type_, resource_identifier); | 153 primary_pattern, secondary_pattern, content_type_, resource_identifier); |
141 | 154 |
142 return true; | 155 return true; |
143 } | 156 } |
144 | 157 |
| 158 base::Time ContentSettingsPref::GetWebsiteSettingLastModified( |
| 159 const ContentSettingsPattern& primary_pattern, |
| 160 const ContentSettingsPattern& secondary_pattern, |
| 161 const ResourceIdentifier& resource_identifier) { |
| 162 OriginIdentifierValueMap* map_to_modify = &incognito_value_map_; |
| 163 if (!is_incognito_) |
| 164 map_to_modify = &value_map_; |
| 165 |
| 166 base::Time last_modified = map_to_modify->GetLastModified( |
| 167 primary_pattern, secondary_pattern, content_type_, resource_identifier); |
| 168 return last_modified; |
| 169 } |
| 170 |
145 void ContentSettingsPref::ClearPref() { | 171 void ContentSettingsPref::ClearPref() { |
146 DCHECK(thread_checker_.CalledOnValidThread()); | 172 DCHECK(thread_checker_.CalledOnValidThread()); |
147 DCHECK(prefs_); | 173 DCHECK(prefs_); |
148 | 174 |
149 { | 175 { |
150 base::AutoLock auto_lock(lock_); | 176 base::AutoLock auto_lock(lock_); |
151 value_map_.clear(); | 177 value_map_.clear(); |
152 } | 178 } |
153 | 179 |
154 { | 180 { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 // notification. | 221 // notification. |
196 base::AutoReset<bool> auto_reset(&updating_preferences_, true); | 222 base::AutoReset<bool> auto_reset(&updating_preferences_, true); |
197 DictionaryPrefUpdate update(prefs_, pref_name_); | 223 DictionaryPrefUpdate update(prefs_, pref_name_); |
198 base::AutoLock auto_lock(lock_); | 224 base::AutoLock auto_lock(lock_); |
199 | 225 |
200 const base::DictionaryValue* all_settings_dictionary = | 226 const base::DictionaryValue* all_settings_dictionary = |
201 prefs_->GetDictionary(pref_name_); | 227 prefs_->GetDictionary(pref_name_); |
202 | 228 |
203 value_map_.clear(); | 229 value_map_.clear(); |
204 | 230 |
205 // Careful: The returned value could be NULL if the pref has never been set. | 231 // Careful: The returned value could be nullptr if the pref has never been |
| 232 // set. |
206 if (!all_settings_dictionary) | 233 if (!all_settings_dictionary) |
207 return; | 234 return; |
208 | 235 |
209 base::DictionaryValue* mutable_settings; | 236 base::DictionaryValue* mutable_settings; |
210 std::unique_ptr<base::DictionaryValue> mutable_settings_scope; | 237 std::unique_ptr<base::DictionaryValue> mutable_settings_scope; |
211 | 238 |
212 if (!is_incognito_) { | 239 if (!is_incognito_) { |
213 mutable_settings = update.Get(); | 240 mutable_settings = update.Get(); |
214 } else { | 241 } else { |
215 // Create copy as we do not want to persist anything in incognito prefs. | 242 // Create copy as we do not want to persist anything in incognito prefs. |
(...skipping 13 matching lines...) Expand all Loading... |
229 ParsePatternString(pattern_str); | 256 ParsePatternString(pattern_str); |
230 if (!pattern_pair.first.IsValid() || | 257 if (!pattern_pair.first.IsValid() || |
231 !pattern_pair.second.IsValid()) { | 258 !pattern_pair.second.IsValid()) { |
232 // TODO: Change this to DFATAL when crbug.com/132659 is fixed. | 259 // TODO: Change this to DFATAL when crbug.com/132659 is fixed. |
233 LOG(ERROR) << "Invalid pattern strings: " << pattern_str; | 260 LOG(ERROR) << "Invalid pattern strings: " << pattern_str; |
234 continue; | 261 continue; |
235 } | 262 } |
236 | 263 |
237 // Get settings dictionary for the current pattern string, and read | 264 // Get settings dictionary for the current pattern string, and read |
238 // settings from the dictionary. | 265 // settings from the dictionary. |
239 const base::DictionaryValue* settings_dictionary = NULL; | 266 const base::DictionaryValue* settings_dictionary = nullptr; |
240 bool is_dictionary = i.value().GetAsDictionary(&settings_dictionary); | 267 bool is_dictionary = i.value().GetAsDictionary(&settings_dictionary); |
241 DCHECK(is_dictionary); | 268 DCHECK(is_dictionary); |
242 | 269 |
243 if (SupportsResourceIdentifiers(content_type_)) { | 270 if (SupportsResourceIdentifiers(content_type_)) { |
244 const base::DictionaryValue* resource_dictionary = NULL; | 271 const base::DictionaryValue* resource_dictionary = nullptr; |
245 if (settings_dictionary->GetDictionary( | 272 if (settings_dictionary->GetDictionary( |
246 kPerResourceIdentifierPrefName, &resource_dictionary)) { | 273 kPerResourceIdentifierPrefName, &resource_dictionary)) { |
| 274 base::Time last_modified = GetTimeStamp(settings_dictionary); |
247 for (base::DictionaryValue::Iterator j(*resource_dictionary); | 275 for (base::DictionaryValue::Iterator j(*resource_dictionary); |
248 !j.IsAtEnd(); | 276 !j.IsAtEnd(); |
249 j.Advance()) { | 277 j.Advance()) { |
250 const std::string& resource_identifier(j.key()); | 278 const std::string& resource_identifier(j.key()); |
251 int setting = CONTENT_SETTING_DEFAULT; | 279 int setting = CONTENT_SETTING_DEFAULT; |
252 bool is_integer = j.value().GetAsInteger(&setting); | 280 bool is_integer = j.value().GetAsInteger(&setting); |
253 DCHECK(is_integer); | 281 DCHECK(is_integer); |
254 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); | 282 DCHECK_NE(CONTENT_SETTING_DEFAULT, setting); |
255 std::unique_ptr<base::Value> setting_ptr(new base::Value(setting)); | 283 std::unique_ptr<base::Value> setting_ptr(new base::Value(setting)); |
256 value_map_.SetValue(pattern_pair.first, | 284 // Per resource settings store a single timestamps for all resources. |
257 pattern_pair.second, | 285 value_map_.SetValue(pattern_pair.first, pattern_pair.second, |
258 content_type_, | 286 content_type_, resource_identifier, last_modified, |
259 resource_identifier, | |
260 setting_ptr->DeepCopy()); | 287 setting_ptr->DeepCopy()); |
261 } | 288 } |
262 } | 289 } |
263 } | 290 } |
264 | 291 |
265 const base::Value* value = nullptr; | 292 const base::Value* value = nullptr; |
266 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value); | 293 settings_dictionary->GetWithoutPathExpansion(kSettingPath, &value); |
267 | |
268 if (value) { | 294 if (value) { |
| 295 base::Time last_modified = GetTimeStamp(settings_dictionary); |
269 DCHECK(IsValueAllowedForType(value, content_type_)); | 296 DCHECK(IsValueAllowedForType(value, content_type_)); |
270 value_map_.SetValue(pattern_pair.first, | 297 value_map_.SetValue(pattern_pair.first, pattern_pair.second, |
271 pattern_pair.second, | 298 content_type_, ResourceIdentifier(), last_modified, |
272 content_type_, | |
273 ResourceIdentifier(), | |
274 value->DeepCopy()); | 299 value->DeepCopy()); |
275 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { | 300 if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) { |
276 ContentSetting s = ValueToContentSetting(value); | 301 ContentSetting s = ValueToContentSetting(value); |
277 switch (s) { | 302 switch (s) { |
278 case CONTENT_SETTING_ALLOW : | 303 case CONTENT_SETTING_ALLOW : |
279 ++cookies_allow_exception_count; | 304 ++cookies_allow_exception_count; |
280 break; | 305 break; |
281 case CONTENT_SETTING_BLOCK : | 306 case CONTENT_SETTING_BLOCK : |
282 ++cookies_block_exception_count; | 307 ++cookies_block_exception_count; |
283 break; | 308 break; |
(...skipping 30 matching lines...) Expand all Loading... |
314 notify_callback_.Run(ContentSettingsPattern(), | 339 notify_callback_.Run(ContentSettingsPattern(), |
315 ContentSettingsPattern(), | 340 ContentSettingsPattern(), |
316 content_type_, | 341 content_type_, |
317 ResourceIdentifier()); | 342 ResourceIdentifier()); |
318 } | 343 } |
319 | 344 |
320 void ContentSettingsPref::UpdatePref( | 345 void ContentSettingsPref::UpdatePref( |
321 const ContentSettingsPattern& primary_pattern, | 346 const ContentSettingsPattern& primary_pattern, |
322 const ContentSettingsPattern& secondary_pattern, | 347 const ContentSettingsPattern& secondary_pattern, |
323 const ResourceIdentifier& resource_identifier, | 348 const ResourceIdentifier& resource_identifier, |
| 349 const base::Time last_modified, |
324 const base::Value* value) { | 350 const base::Value* value) { |
325 // Ensure that |lock_| is not held by this thread, since this function will | 351 // Ensure that |lock_| is not held by this thread, since this function will |
326 // send out notifications (by |~DictionaryPrefUpdate|). | 352 // send out notifications (by |~DictionaryPrefUpdate|). |
327 AssertLockNotHeld(); | 353 AssertLockNotHeld(); |
328 | 354 |
329 base::AutoReset<bool> auto_reset(&updating_preferences_, true); | 355 base::AutoReset<bool> auto_reset(&updating_preferences_, true); |
330 { | 356 { |
331 DictionaryPrefUpdate update(prefs_, pref_name_); | 357 DictionaryPrefUpdate update(prefs_, pref_name_); |
332 base::DictionaryValue* pattern_pairs_settings = update.Get(); | 358 base::DictionaryValue* pattern_pairs_settings = update.Get(); |
333 | 359 |
334 // Get settings dictionary for the given patterns. | 360 // Get settings dictionary for the given patterns. |
335 std::string pattern_str(CreatePatternString(primary_pattern, | 361 std::string pattern_str(CreatePatternString(primary_pattern, |
336 secondary_pattern)); | 362 secondary_pattern)); |
337 base::DictionaryValue* settings_dictionary = NULL; | 363 base::DictionaryValue* settings_dictionary = nullptr; |
338 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( | 364 bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion( |
339 pattern_str, &settings_dictionary); | 365 pattern_str, &settings_dictionary); |
340 | 366 |
341 if (!found && value) { | 367 if (!found && value) { |
342 settings_dictionary = new base::DictionaryValue; | 368 settings_dictionary = new base::DictionaryValue; |
343 pattern_pairs_settings->SetWithoutPathExpansion( | 369 pattern_pairs_settings->SetWithoutPathExpansion( |
344 pattern_str, settings_dictionary); | 370 pattern_str, settings_dictionary); |
345 } | 371 } |
346 | 372 |
347 if (settings_dictionary) { | 373 if (settings_dictionary) { |
348 if (SupportsResourceIdentifiers(content_type_) && | 374 if (SupportsResourceIdentifiers(content_type_) && |
349 !resource_identifier.empty()) { | 375 !resource_identifier.empty()) { |
350 base::DictionaryValue* resource_dictionary = NULL; | 376 base::DictionaryValue* resource_dictionary = nullptr; |
351 found = settings_dictionary->GetDictionary( | 377 found = settings_dictionary->GetDictionary( |
352 kPerResourceIdentifierPrefName, &resource_dictionary); | 378 kPerResourceIdentifierPrefName, &resource_dictionary); |
353 if (!found) { | 379 if (!found) { |
354 if (value == NULL) | 380 if (value == nullptr) |
355 return; // Nothing to remove. Exit early. | 381 return; // Nothing to remove. Exit early. |
356 resource_dictionary = new base::DictionaryValue; | 382 resource_dictionary = new base::DictionaryValue; |
357 settings_dictionary->Set( | 383 settings_dictionary->Set( |
358 kPerResourceIdentifierPrefName, resource_dictionary); | 384 kPerResourceIdentifierPrefName, resource_dictionary); |
359 } | 385 } |
360 // Update resource dictionary. | 386 // Update resource dictionary. |
361 if (value == NULL) { | 387 if (value == nullptr) { |
362 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier, | 388 resource_dictionary->RemoveWithoutPathExpansion(resource_identifier, |
363 NULL); | 389 nullptr); |
364 if (resource_dictionary->empty()) { | 390 if (resource_dictionary->empty()) { |
365 settings_dictionary->RemoveWithoutPathExpansion( | 391 settings_dictionary->RemoveWithoutPathExpansion( |
366 kPerResourceIdentifierPrefName, NULL); | 392 kPerResourceIdentifierPrefName, nullptr); |
| 393 settings_dictionary->RemoveWithoutPathExpansion(kLastModifiedPath, |
| 394 nullptr); |
367 } | 395 } |
368 } else { | 396 } else { |
369 resource_dictionary->SetWithoutPathExpansion( | 397 resource_dictionary->SetWithoutPathExpansion( |
370 resource_identifier, value->DeepCopy()); | 398 resource_identifier, value->DeepCopy()); |
| 399 // Update timestamp for whole resource dictionary. |
| 400 settings_dictionary->SetStringWithoutPathExpansion( |
| 401 kLastModifiedPath, |
| 402 base::Int64ToString(last_modified.ToInternalValue())); |
371 } | 403 } |
372 } else { | 404 } else { |
373 // Update settings dictionary. | 405 // Update settings dictionary. |
374 if (value == NULL) { | 406 if (value == nullptr) { |
375 settings_dictionary->RemoveWithoutPathExpansion(kSettingPath, NULL); | 407 settings_dictionary->RemoveWithoutPathExpansion(kSettingPath, |
| 408 nullptr); |
| 409 settings_dictionary->RemoveWithoutPathExpansion(kLastModifiedPath, |
| 410 nullptr); |
376 } else { | 411 } else { |
377 settings_dictionary->SetWithoutPathExpansion( | 412 settings_dictionary->SetWithoutPathExpansion( |
378 kSettingPath, value->DeepCopy()); | 413 kSettingPath, value->DeepCopy()); |
| 414 settings_dictionary->SetStringWithoutPathExpansion( |
| 415 kLastModifiedPath, |
| 416 base::Int64ToString(last_modified.ToInternalValue())); |
379 } | 417 } |
380 } | 418 } |
381 // Remove the settings dictionary if it is empty. | 419 // Remove the settings dictionary if it is empty. |
382 if (settings_dictionary->empty()) { | 420 if (settings_dictionary->empty()) { |
383 pattern_pairs_settings->RemoveWithoutPathExpansion( | 421 pattern_pairs_settings->RemoveWithoutPathExpansion(pattern_str, |
384 pattern_str, NULL); | 422 nullptr); |
385 } | 423 } |
386 } | 424 } |
387 } | 425 } |
388 } | 426 } |
389 | 427 |
390 // static | 428 // static |
391 void ContentSettingsPref::CanonicalizeContentSettingsExceptions( | 429 void ContentSettingsPref::CanonicalizeContentSettingsExceptions( |
392 base::DictionaryValue* all_settings_dictionary) { | 430 base::DictionaryValue* all_settings_dictionary) { |
393 DCHECK(all_settings_dictionary); | 431 DCHECK(all_settings_dictionary); |
394 | 432 |
(...skipping 13 matching lines...) Expand all Loading... |
408 | 446 |
409 const std::string canonicalized_pattern_str = CreatePatternString( | 447 const std::string canonicalized_pattern_str = CreatePatternString( |
410 pattern_pair.first, pattern_pair.second); | 448 pattern_pair.first, pattern_pair.second); |
411 | 449 |
412 if (canonicalized_pattern_str.empty() || | 450 if (canonicalized_pattern_str.empty() || |
413 canonicalized_pattern_str == pattern_str) { | 451 canonicalized_pattern_str == pattern_str) { |
414 continue; | 452 continue; |
415 } | 453 } |
416 | 454 |
417 // Clear old pattern if prefs already have canonicalized pattern. | 455 // Clear old pattern if prefs already have canonicalized pattern. |
418 const base::DictionaryValue* new_pattern_settings_dictionary = NULL; | 456 const base::DictionaryValue* new_pattern_settings_dictionary = nullptr; |
419 if (all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 457 if (all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
420 canonicalized_pattern_str, &new_pattern_settings_dictionary)) { | 458 canonicalized_pattern_str, &new_pattern_settings_dictionary)) { |
421 remove_items.push_back(pattern_str); | 459 remove_items.push_back(pattern_str); |
422 continue; | 460 continue; |
423 } | 461 } |
424 | 462 |
425 // Move old pattern to canonicalized pattern. | 463 // Move old pattern to canonicalized pattern. |
426 const base::DictionaryValue* old_pattern_settings_dictionary = NULL; | 464 const base::DictionaryValue* old_pattern_settings_dictionary = nullptr; |
427 if (i.value().GetAsDictionary(&old_pattern_settings_dictionary)) { | 465 if (i.value().GetAsDictionary(&old_pattern_settings_dictionary)) { |
428 move_items.push_back( | 466 move_items.push_back( |
429 std::make_pair(pattern_str, canonicalized_pattern_str)); | 467 std::make_pair(pattern_str, canonicalized_pattern_str)); |
430 } | 468 } |
431 } | 469 } |
432 | 470 |
433 for (size_t i = 0; i < remove_items.size(); ++i) { | 471 for (size_t i = 0; i < remove_items.size(); ++i) { |
434 all_settings_dictionary->RemoveWithoutPathExpansion(remove_items[i], NULL); | 472 all_settings_dictionary->RemoveWithoutPathExpansion(remove_items[i], |
| 473 nullptr); |
435 } | 474 } |
436 | 475 |
437 for (size_t i = 0; i < move_items.size(); ++i) { | 476 for (size_t i = 0; i < move_items.size(); ++i) { |
438 std::unique_ptr<base::Value> pattern_settings_dictionary; | 477 std::unique_ptr<base::Value> pattern_settings_dictionary; |
439 all_settings_dictionary->RemoveWithoutPathExpansion( | 478 all_settings_dictionary->RemoveWithoutPathExpansion( |
440 move_items[i].first, &pattern_settings_dictionary); | 479 move_items[i].first, &pattern_settings_dictionary); |
441 all_settings_dictionary->SetWithoutPathExpansion( | 480 all_settings_dictionary->SetWithoutPathExpansion( |
442 move_items[i].second, pattern_settings_dictionary.release()); | 481 move_items[i].second, pattern_settings_dictionary.release()); |
443 } | 482 } |
444 } | 483 } |
445 | 484 |
446 void ContentSettingsPref::AssertLockNotHeld() const { | 485 void ContentSettingsPref::AssertLockNotHeld() const { |
447 #if !defined(NDEBUG) | 486 #if !defined(NDEBUG) |
448 // |Lock::Acquire()| will assert if the lock is held by this thread. | 487 // |Lock::Acquire()| will assert if the lock is held by this thread. |
449 lock_.Acquire(); | 488 lock_.Acquire(); |
450 lock_.Release(); | 489 lock_.Release(); |
451 #endif | 490 #endif |
452 } | 491 } |
453 | 492 |
454 } // namespace content_settings | 493 } // namespace content_settings |
OLD | NEW |