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

Side by Side Diff: components/content_settings/core/browser/host_content_settings_map.cc

Issue 2158743002: Register a pref to control migration status (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@change_scoping_type
Patch Set: minor change Created 4 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/host_content_settings_map.h" 5 #include "components/content_settings/core/browser/host_content_settings_map.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { 52 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = {
53 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION}, 53 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION},
54 {"policy", content_settings::SETTING_SOURCE_POLICY}, 54 {"policy", content_settings::SETTING_SOURCE_POLICY},
55 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED}, 55 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED},
56 {"extension", content_settings::SETTING_SOURCE_EXTENSION}, 56 {"extension", content_settings::SETTING_SOURCE_EXTENSION},
57 {"preference", content_settings::SETTING_SOURCE_USER}, 57 {"preference", content_settings::SETTING_SOURCE_USER},
58 {"default", content_settings::SETTING_SOURCE_USER}, 58 {"default", content_settings::SETTING_SOURCE_USER},
59 }; 59 };
60 60
61 // Enum describing the status of domain to origin migration of content settings.
62 // Migration will be done twice: once upon construction of the
63 // HostContentSettingsMap (before syncing any content settings) and once after
64 // sync has finished. We always migrate before sync to ensure that settings will
65 // get migrated even if a user doesn't have sync enabled. We migrate after sync
66 // to ensure that any sync'd settings will be migrated. Once these events have
67 // occurred, we won't perform migration again.
68 enum DomainToOriginMigrationStatus {
69 // Haven't been migrated at all.
70 NOT_MIGRATED,
71 // Have done migration in the constructor of HostContentSettingsMap.
72 MIGRATED_BEFORE_SYNC,
73 // Have done migration both in HostContentSettingsMap construction and and
74 // after sync is finished. No migration will happen after this point.
75 MIGRATED_AFTER_SYNC,
76 };
77
61 static_assert( 78 static_assert(
62 arraysize(kProviderNamesSourceMap) == 79 arraysize(kProviderNamesSourceMap) ==
63 HostContentSettingsMap::NUM_PROVIDER_TYPES, 80 HostContentSettingsMap::NUM_PROVIDER_TYPES,
64 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements"); 81 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements");
65 82
66 // Returns true if the |content_type| supports a resource identifier. 83 // Returns true if the |content_type| supports a resource identifier.
67 // Resource identifiers are supported (but not required) for plugins. 84 // Resource identifiers are supported (but not required) for plugins.
68 bool SupportsResourceIdentifier(ContentSettingsType content_type) { 85 bool SupportsResourceIdentifier(ContentSettingsType content_type) {
69 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; 86 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
70 } 87 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 RecordNumberOfExceptions(); 193 RecordNumberOfExceptions();
177 } 194 }
178 195
179 // static 196 // static
180 void HostContentSettingsMap::RegisterProfilePrefs( 197 void HostContentSettingsMap::RegisterProfilePrefs(
181 user_prefs::PrefRegistrySyncable* registry) { 198 user_prefs::PrefRegistrySyncable* registry) {
182 // Ensure the content settings are all registered. 199 // Ensure the content settings are all registered.
183 content_settings::ContentSettingsRegistry::GetInstance(); 200 content_settings::ContentSettingsRegistry::GetInstance();
184 201
185 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); 202 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0);
203 registry->RegisterIntegerPref(prefs::kDomainToOriginMigrationStatus,
204 NOT_MIGRATED);
186 205
187 // Register the prefs for the content settings providers. 206 // Register the prefs for the content settings providers.
188 content_settings::DefaultProvider::RegisterProfilePrefs(registry); 207 content_settings::DefaultProvider::RegisterProfilePrefs(registry);
189 content_settings::PrefProvider::RegisterProfilePrefs(registry); 208 content_settings::PrefProvider::RegisterProfilePrefs(registry);
190 content_settings::PolicyProvider::RegisterProfilePrefs(registry); 209 content_settings::PolicyProvider::RegisterProfilePrefs(registry);
191 } 210 }
192 211
193 void HostContentSettingsMap::RegisterProvider( 212 void HostContentSettingsMap::RegisterProvider(
194 ProviderType type, 213 ProviderType type,
195 std::unique_ptr<content_settings::ObservableProvider> provider) { 214 std::unique_ptr<content_settings::ObservableProvider> provider) {
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 CONTENT_SETTINGS_TYPE_KEYGEN, 509 CONTENT_SETTINGS_TYPE_KEYGEN,
491 std::string(), CONTENT_SETTING_DEFAULT); 510 std::string(), CONTENT_SETTING_DEFAULT);
492 // Set the new pattern. 511 // Set the new pattern.
493 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, 512 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN,
494 std::string(), content_setting); 513 std::string(), content_setting);
495 } 514 }
496 } 515 }
497 } 516 }
498 } 517 }
499 518
500 void HostContentSettingsMap::MigrateDomainScopedSettings() { 519 void HostContentSettingsMap::MigrateDomainScopedSettings(bool after_sync) {
520 int status = prefs_->GetInteger(prefs::kDomainToOriginMigrationStatus);
msramek 2016/07/26 19:21:02 nit: DomainToOriginMigrationStatus status = static
lshang 2016/07/27 00:23:47 Done.
521 if (status == MIGRATED_AFTER_SYNC)
522 return;
523 if (status == MIGRATED_BEFORE_SYNC && !after_sync)
524 return;
525 DCHECK(status != NOT_MIGRATED || !after_sync);
526
501 const ContentSettingsType kDomainScopedTypes[] = { 527 const ContentSettingsType kDomainScopedTypes[] = {
502 CONTENT_SETTINGS_TYPE_COOKIES, 528 CONTENT_SETTINGS_TYPE_COOKIES,
503 CONTENT_SETTINGS_TYPE_IMAGES, 529 CONTENT_SETTINGS_TYPE_IMAGES,
504 CONTENT_SETTINGS_TYPE_PLUGINS, 530 CONTENT_SETTINGS_TYPE_PLUGINS,
505 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 531 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
506 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, 532 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
507 CONTENT_SETTINGS_TYPE_POPUPS}; 533 CONTENT_SETTINGS_TYPE_POPUPS};
508 for (const ContentSettingsType& type : kDomainScopedTypes) { 534 for (const ContentSettingsType& type : kDomainScopedTypes) {
509 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type)) 535 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type))
510 continue; 536 continue;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 581
556 // If the current resolved content setting is allowed it's safe to set the 582 // If the current resolved content setting is allowed it's safe to set the
557 // origin-scoped pattern. 583 // origin-scoped pattern.
558 if (origin_setting == CONTENT_SETTING_ALLOW) 584 if (origin_setting == CONTENT_SETTING_ALLOW)
559 SetContentSettingCustomScope( 585 SetContentSettingCustomScope(
560 ContentSettingsPattern::FromURLNoWildcard(origin), 586 ContentSettingsPattern::FromURLNoWildcard(origin),
561 ContentSettingsPattern::Wildcard(), type, std::string(), 587 ContentSettingsPattern::Wildcard(), type, std::string(),
562 CONTENT_SETTING_ALLOW); 588 CONTENT_SETTING_ALLOW);
563 } 589 }
564 } 590 }
591
592 if (status == NOT_MIGRATED) {
593 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus,
594 MIGRATED_BEFORE_SYNC);
595 } else if (status == MIGRATED_BEFORE_SYNC) {
596 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus,
597 MIGRATED_AFTER_SYNC);
598 }
565 } 599 }
566 600
567 void HostContentSettingsMap::RecordNumberOfExceptions() { 601 void HostContentSettingsMap::RecordNumberOfExceptions() {
568 for (const content_settings::WebsiteSettingsInfo* info : 602 for (const content_settings::WebsiteSettingsInfo* info :
569 *content_settings::WebsiteSettingsRegistry::GetInstance()) { 603 *content_settings::WebsiteSettingsRegistry::GetInstance()) {
570 ContentSettingsType content_type = info->type(); 604 ContentSettingsType content_type = info->type();
571 const std::string type_name = info->name(); 605 const std::string type_name = info->name();
572 606
573 ContentSettingsForOneType settings; 607 ContentSettingsForOneType settings;
574 GetSettingsForOneType(content_type, std::string(), &settings); 608 GetSettingsForOneType(content_type, std::string(), &settings);
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 rule.secondary_pattern.Matches(secondary_url)) { 947 rule.secondary_pattern.Matches(secondary_url)) {
914 if (primary_pattern) 948 if (primary_pattern)
915 *primary_pattern = rule.primary_pattern; 949 *primary_pattern = rule.primary_pattern;
916 if (secondary_pattern) 950 if (secondary_pattern)
917 *secondary_pattern = rule.secondary_pattern; 951 *secondary_pattern = rule.secondary_pattern;
918 return base::WrapUnique(rule.value.get()->DeepCopy()); 952 return base::WrapUnique(rule.value.get()->DeepCopy());
919 } 953 }
920 } 954 }
921 return std::unique_ptr<base::Value>(); 955 return std::unique_ptr<base::Value>();
922 } 956 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698