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

Side by Side Diff: chrome/browser/extensions/api/preference/preference_api.cc

Issue 217053003: Remove PreferenceAPI dependency from ExtensionPrefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: woops Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/api/preference/preference_api.h ('k') | extensions/browser/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/browser/extensions/api/preference/preference_api.h" 5 #include "chrome/browser/extensions/api/preference/preference_api.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 // static 440 // static
441 PreferenceAPI* PreferenceAPI::Get(content::BrowserContext* context) { 441 PreferenceAPI* PreferenceAPI::Get(content::BrowserContext* context) {
442 return BrowserContextKeyedAPIFactory<PreferenceAPI>::Get(context); 442 return BrowserContextKeyedAPIFactory<PreferenceAPI>::Get(context);
443 } 443 }
444 444
445 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) { 445 void PreferenceAPI::OnListenerAdded(const EventListenerInfo& details) {
446 preference_event_router_.reset(new PreferenceEventRouter(profile_)); 446 preference_event_router_.reset(new PreferenceEventRouter(profile_));
447 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this); 447 ExtensionSystem::Get(profile_)->event_router()->UnregisterObserver(this);
448 } 448 }
449 449
450 // static
451 void PreferenceAPI::LoadExtensionControlledPrefs(
452 ExtensionPrefs* prefs,
453 ExtensionPrefValueMap* value_map,
454 const std::string& extension_id,
455 ExtensionPrefsScope scope) {
456 std::string scope_string;
457 if (!pref_names::ScopeToPrefName(scope, &scope_string))
458 return;
459 std::string key = extension_id + "." + scope_string;
460
461 const base::DictionaryValue* source_dict = prefs->pref_service()->
462 GetDictionary(pref_names::kExtensions);
463 const base::DictionaryValue* preferences = NULL;
464 if (!source_dict->GetDictionary(key, &preferences))
465 return;
466
467 for (base::DictionaryValue::Iterator iter(*preferences);
468 !iter.IsAtEnd(); iter.Advance()) {
469 value_map->SetExtensionPref(
470 extension_id, iter.key(), scope, iter.value().DeepCopy());
471 }
472 }
473
474 // static
475 void PreferenceAPI::InitExtensionControlledPrefs(
476 ExtensionPrefs* prefs,
477 ExtensionPrefValueMap* value_map) {
478 ExtensionIdList extension_ids;
479 prefs->GetExtensions(&extension_ids);
480
481 for (ExtensionIdList::iterator extension_id = extension_ids.begin();
482 extension_id != extension_ids.end(); ++extension_id) {
483 base::Time install_time = prefs->GetInstallTime(*extension_id);
484 bool is_enabled = !prefs->IsExtensionDisabled(*extension_id);
485 bool is_incognito_enabled = prefs->IsIncognitoEnabled(*extension_id);
486 value_map->RegisterExtension(
487 *extension_id, install_time, is_enabled, is_incognito_enabled);
488 prefs->content_settings_store()->RegisterExtension(
489 *extension_id, install_time, is_enabled);
490
491 // Set regular extension controlled prefs.
492 LoadExtensionControlledPrefs(prefs,
493 value_map,
494 *extension_id,
495 kExtensionPrefsScopeRegular);
496 // Set incognito extension controlled prefs.
497 LoadExtensionControlledPrefs(prefs,
498 value_map,
499 *extension_id,
500 kExtensionPrefsScopeIncognitoPersistent);
501 // Set regular-only extension controlled prefs.
502 LoadExtensionControlledPrefs(prefs,
503 value_map,
504 *extension_id,
505 kExtensionPrefsScopeRegularOnly);
506
507 // Set content settings.
508 const base::ListValue* content_settings = NULL;
509 if (prefs->ReadPrefAsList(*extension_id,
510 pref_names::kPrefContentSettings,
511 &content_settings)) {
512 prefs->content_settings_store()->SetExtensionContentSettingFromList(
513 *extension_id, content_settings, kExtensionPrefsScopeRegular);
514 }
515 if (prefs->ReadPrefAsList(*extension_id,
516 pref_names::kPrefIncognitoContentSettings,
517 &content_settings)) {
518 prefs->content_settings_store()->SetExtensionContentSettingFromList(
519 *extension_id,
520 content_settings,
521 kExtensionPrefsScopeIncognitoPersistent);
522 }
523 }
524 }
525
526 void PreferenceAPI::OnContentSettingChanged(const std::string& extension_id, 450 void PreferenceAPI::OnContentSettingChanged(const std::string& extension_id,
527 bool incognito) { 451 bool incognito) {
528 if (incognito) { 452 if (incognito) {
529 extension_prefs()->UpdateExtensionPref( 453 extension_prefs()->UpdateExtensionPref(
530 extension_id, 454 extension_id,
531 pref_names::kPrefIncognitoContentSettings, 455 pref_names::kPrefIncognitoContentSettings,
532 extension_prefs()->content_settings_store()->GetSettingsForExtension( 456 extension_prefs()->content_settings_store()->GetSettingsForExtension(
533 extension_id, kExtensionPrefsScopeIncognitoPersistent)); 457 extension_id, kExtensionPrefsScopeIncognitoPersistent));
534 } else { 458 } else {
535 extension_prefs()->UpdateExtensionPref( 459 extension_prefs()->UpdateExtensionPref(
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) { 703 pref_key, PreferenceFunction::PERMISSION_TYPE_WRITE, &browser_pref)) {
780 return false; 704 return false;
781 } 705 }
782 706
783 PreferenceAPI::Get(GetProfile()) 707 PreferenceAPI::Get(GetProfile())
784 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope); 708 ->RemoveExtensionControlledPref(extension_id(), browser_pref, scope);
785 return true; 709 return true;
786 } 710 }
787 711
788 } // namespace extensions 712 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/preference/preference_api.h ('k') | extensions/browser/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698