OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/in_memory_pref_store.h" | |
11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
12 | 13 |
13 using base::Time; | 14 using base::Time; |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // Additional preferences keys | 18 // Additional preferences keys |
18 | 19 |
19 // Where an extension was installed from. (see Extension::Location) | 20 // Where an extension was installed from. (see Extension::Location) |
20 const char kPrefLocation[] = "location"; | 21 const char kPrefLocation[] = "location"; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 // A preference set by the the NTP to persist the desired launch container type | 72 // A preference set by the the NTP to persist the desired launch container type |
72 // used for apps. | 73 // used for apps. |
73 const char kPrefLaunchType[] = "launchType"; | 74 const char kPrefLaunchType[] = "launchType"; |
74 | 75 |
75 // A preference determining the order of which the apps appear on the NTP. | 76 // A preference determining the order of which the apps appear on the NTP. |
76 const char kPrefAppLaunchIndex[] = "app_launcher_index"; | 77 const char kPrefAppLaunchIndex[] = "app_launcher_index"; |
77 | 78 |
78 // "A preference for storing extra data sent in update checks for an extension. | 79 // "A preference for storing extra data sent in update checks for an extension. |
79 const char kUpdateUrlData[] = "update_url_data"; | 80 const char kUpdateUrlData[] = "update_url_data"; |
80 | 81 |
82 // A preference that indicates when an extension was installed. | |
83 const char kPrefInstallTime[] = "install_time"; | |
84 | |
85 // A preference that indicates the last effective preference values of an | |
86 // extension. The value is a dictionary mapping (non-expanded) preference keys | |
87 // to the values configured by the extension. | |
88 const char kPrefPreferences[] = "preferences"; | |
89 | |
81 } // namespace | 90 } // namespace |
82 | 91 |
83 //////////////////////////////////////////////////////////////////////////////// | 92 //////////////////////////////////////////////////////////////////////////////// |
84 | 93 |
85 namespace { | 94 namespace { |
86 | 95 |
87 // TODO(asargent) - This is cleanup code for a key that was introduced into | 96 // TODO(asargent) - This is cleanup code for a key that was introduced into |
88 // the extensions.settings sub-dictionary which wasn't a valid extension | 97 // the extensions.settings sub-dictionary which wasn't a valid extension |
89 // id. We can remove this in a couple of months. (See http://crbug.com/40017 | 98 // id. We can remove this in a couple of months. (See http://crbug.com/40017 |
90 // and http://crbug.com/39745 for more details). | 99 // and http://crbug.com/39745 for more details). |
(...skipping 21 matching lines...) Expand all Loading... | |
112 } // namespace | 121 } // namespace |
113 | 122 |
114 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) | 123 ExtensionPrefs::ExtensionPrefs(PrefService* prefs, const FilePath& root_dir) |
115 : prefs_(prefs), | 124 : prefs_(prefs), |
116 install_directory_(root_dir) { | 125 install_directory_(root_dir) { |
117 // TODO(asargent) - Remove this in a couple of months. (See comment above | 126 // TODO(asargent) - Remove this in a couple of months. (See comment above |
118 // CleanupBadExtensionKeys). | 127 // CleanupBadExtensionKeys). |
119 CleanupBadExtensionKeys(prefs); | 128 CleanupBadExtensionKeys(prefs); |
120 | 129 |
121 MakePathsRelative(); | 130 MakePathsRelative(); |
131 | |
132 InstallPersistedExtensionControlledPrefs(); | |
122 } | 133 } |
123 | 134 |
124 ExtensionPrefs::~ExtensionPrefs() {} | 135 ExtensionPrefs::~ExtensionPrefs() {} |
125 | 136 |
126 // static | 137 // static |
127 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings"; | 138 const char ExtensionPrefs::kExtensionsPref[] = "extensions.settings"; |
128 | 139 |
129 static FilePath::StringType MakePathRelative(const FilePath& parent, | 140 static FilePath::StringType MakePathRelative(const FilePath& parent, |
130 const FilePath& child, | 141 const FilePath& child, |
131 bool *dirty) { | 142 bool *dirty) { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 iter != extension_ids.end(); ++iter) { | 528 iter != extension_ids.end(); ++iter) { |
518 toolbar_order->Append(new StringValue(*iter)); | 529 toolbar_order->Append(new StringValue(*iter)); |
519 } | 530 } |
520 SavePrefsAndNotify(); | 531 SavePrefsAndNotify(); |
521 } | 532 } |
522 | 533 |
523 void ExtensionPrefs::OnExtensionInstalled( | 534 void ExtensionPrefs::OnExtensionInstalled( |
524 const Extension* extension, Extension::State initial_state, | 535 const Extension* extension, Extension::State initial_state, |
525 bool initial_incognito_enabled) { | 536 bool initial_incognito_enabled) { |
526 const std::string& id = extension->id(); | 537 const std::string& id = extension->id(); |
538 const base::Time installTime = GetCurrentTime(); | |
527 UpdateExtensionPref(id, kPrefState, | 539 UpdateExtensionPref(id, kPrefState, |
528 Value::CreateIntegerValue(initial_state)); | 540 Value::CreateIntegerValue(initial_state)); |
529 UpdateExtensionPref(id, kPrefIncognitoEnabled, | 541 UpdateExtensionPref(id, kPrefIncognitoEnabled, |
530 Value::CreateBooleanValue(initial_incognito_enabled)); | 542 Value::CreateBooleanValue(initial_incognito_enabled)); |
531 UpdateExtensionPref(id, kPrefLocation, | 543 UpdateExtensionPref(id, kPrefLocation, |
532 Value::CreateIntegerValue(extension->location())); | 544 Value::CreateIntegerValue(extension->location())); |
545 UpdateExtensionPref(id, kPrefInstallTime, | |
546 Value::CreateStringValue( | |
547 base::Int64ToString(installTime.ToInternalValue()))); | |
548 UpdateExtensionPref(id, kPrefPreferences, new DictionaryValue()); | |
549 | |
533 FilePath::StringType path = MakePathRelative(install_directory_, | 550 FilePath::StringType path = MakePathRelative(install_directory_, |
534 extension->path(), NULL); | 551 extension->path(), NULL); |
535 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); | 552 UpdateExtensionPref(id, kPrefPath, Value::CreateStringValue(path)); |
536 // We store prefs about LOAD extensions, but don't cache their manifest | 553 // We store prefs about LOAD extensions, but don't cache their manifest |
537 // since it may change on disk. | 554 // since it may change on disk. |
538 if (extension->location() != Extension::LOAD) { | 555 if (extension->location() != Extension::LOAD) { |
539 UpdateExtensionPref(id, kPrefManifest, | 556 UpdateExtensionPref(id, kPrefManifest, |
540 extension->manifest_value()->DeepCopy()); | 557 extension->manifest_value()->DeepCopy()); |
541 } | 558 } |
542 UpdateExtensionPref(id, kPrefAppLaunchIndex, | 559 UpdateExtensionPref(id, kPrefAppLaunchIndex, |
543 Value::CreateIntegerValue(GetNextAppLaunchIndex())); | 560 Value::CreateIntegerValue(GetNextAppLaunchIndex())); |
544 SavePrefsAndNotify(); | 561 SavePrefsAndNotify(); |
545 } | 562 } |
546 | 563 |
547 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, | 564 void ExtensionPrefs::OnExtensionUninstalled(const std::string& extension_id, |
548 const Extension::Location& location, | 565 const Extension::Location& location, |
549 bool external_uninstall) { | 566 bool external_uninstall) { |
550 // For external extensions, we save a preference reminding ourself not to try | 567 // For external extensions, we save a preference reminding ourself not to try |
551 // and install the extension anymore (except when |external_uninstall| is | 568 // and install the extension anymore (except when |external_uninstall| is |
552 // true, which signifies that the registry key was deleted or the pref file | 569 // true, which signifies that the registry key was deleted or the pref file |
553 // no longer lists the extension). | 570 // no longer lists the extension). |
571 | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Remove blank line and move the two code lines befo
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
572 std::vector<std::string> prefKeys; | |
573 GetExtensionControlledPrefKeys(extension_id, &prefKeys); | |
574 | |
554 if (!external_uninstall && Extension::IsExternalLocation(location)) { | 575 if (!external_uninstall && Extension::IsExternalLocation(location)) { |
555 UpdateExtensionPref(extension_id, kPrefState, | 576 UpdateExtensionPref(extension_id, kPrefState, |
556 Value::CreateIntegerValue(Extension::KILLBIT)); | 577 Value::CreateIntegerValue(Extension::KILLBIT)); |
557 SavePrefsAndNotify(); | 578 SavePrefsAndNotify(); |
558 } else { | 579 } else { |
559 DeleteExtensionPrefs(extension_id); | 580 DeleteExtensionPrefs(extension_id); |
560 } | 581 } |
582 | |
583 for (std::vector<std::string>::iterator i = prefKeys.begin(); | |
584 i != prefKeys.end(); ++i) { | |
585 UpdateWinningPref(*i); | |
586 } | |
561 } | 587 } |
562 | 588 |
563 Extension::State ExtensionPrefs::GetExtensionState( | 589 Extension::State ExtensionPrefs::GetExtensionState( |
564 const std::string& extension_id) { | 590 const std::string& extension_id) const { |
565 DictionaryValue* extension = GetExtensionPref(extension_id); | 591 DictionaryValue* extension = GetExtensionPref(extension_id); |
566 | 592 |
567 // If the extension doesn't have a pref, it's a --load-extension. | 593 // If the extension doesn't have a pref, it's a --load-extension. |
568 if (!extension) | 594 if (!extension) |
569 return Extension::ENABLED; | 595 return Extension::ENABLED; |
570 | 596 |
571 int state = -1; | 597 int state = -1; |
572 if (!extension->GetInteger(kPrefState, &state) || | 598 if (!extension->GetInteger(kPrefState, &state) || |
573 state < 0 || state >= Extension::NUM_STATES) { | 599 state < 0 || state >= Extension::NUM_STATES) { |
574 LOG(ERROR) << "Bad or missing pref 'state' for extension '" | 600 LOG(ERROR) << "Bad or missing pref 'state' for extension '" |
575 << extension_id << "'"; | 601 << extension_id << "'"; |
576 return Extension::ENABLED; | 602 return Extension::ENABLED; |
577 } | 603 } |
578 return static_cast<Extension::State>(state); | 604 return static_cast<Extension::State>(state); |
579 } | 605 } |
580 | 606 |
581 void ExtensionPrefs::SetExtensionState(const Extension* extension, | 607 void ExtensionPrefs::SetExtensionState(const Extension* extension, |
582 Extension::State state) { | 608 Extension::State state) { |
583 UpdateExtensionPref(extension->id(), kPrefState, | 609 UpdateExtensionPref(extension->id(), kPrefState, |
584 Value::CreateIntegerValue(state)); | 610 Value::CreateIntegerValue(state)); |
611 | |
612 std::vector<std::string> prefKeys; | |
613 GetExtensionControlledPrefKeys(extension->id(), &prefKeys); | |
614 for (std::vector<std::string>::iterator i = prefKeys.begin(); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
It might be useful to have a typedef std::vector<s
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
615 i != prefKeys.end(); ++i) { | |
616 UpdateWinningPref(*i); | |
617 } | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
You have this exact loop earlier in the code, mayb
battre (please use the other)
2010/11/19 16:03:18
It is not that simple: In OnExtensionUninstalled,
| |
618 | |
585 SavePrefsAndNotify(); | 619 SavePrefsAndNotify(); |
586 } | 620 } |
587 | 621 |
588 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { | 622 std::string ExtensionPrefs::GetVersionString(const std::string& extension_id) { |
589 DictionaryValue* extension = GetExtensionPref(extension_id); | 623 DictionaryValue* extension = GetExtensionPref(extension_id); |
590 if (!extension) | 624 if (!extension) |
591 return std::string(); | 625 return std::string(); |
592 | 626 |
593 std::string version; | 627 std::string version; |
594 if (!extension->GetString(kPrefVersion, &version)) { | 628 if (!extension->GetString(kPrefVersion, &version)) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
654 DictionaryValue* ExtensionPrefs::GetExtensionPref( | 688 DictionaryValue* ExtensionPrefs::GetExtensionPref( |
655 const std::string& extension_id) const { | 689 const std::string& extension_id) const { |
656 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); | 690 const DictionaryValue* dict = prefs_->GetDictionary(kExtensionsPref); |
657 if (!dict) | 691 if (!dict) |
658 return NULL; | 692 return NULL; |
659 DictionaryValue* extension = NULL; | 693 DictionaryValue* extension = NULL; |
660 dict->GetDictionary(extension_id, &extension); | 694 dict->GetDictionary(extension_id, &extension); |
661 return extension; | 695 return extension; |
662 } | 696 } |
663 | 697 |
698 DictionaryValue* ExtensionPrefs::GetExtensionControlledPrefs( | |
699 const std::string& extension_id) const { | |
700 DictionaryValue* extension = GetExtensionPref(extension_id); | |
701 if (!extension) | |
702 return NULL; | |
703 DictionaryValue* preferences = NULL; | |
704 extension->GetDictionary(kPrefPreferences, &preferences); | |
705 return preferences; | |
706 } | |
707 | |
664 // Helper function for GetInstalledExtensionsInfo. | 708 // Helper function for GetInstalledExtensionsInfo. |
665 static ExtensionInfo* GetInstalledExtensionInfoImpl( | 709 static ExtensionInfo* GetInstalledExtensionInfoImpl( |
666 DictionaryValue* extension_data, | 710 DictionaryValue* extension_data, |
667 DictionaryValue::key_iterator extension_id) { | 711 DictionaryValue::key_iterator extension_id) { |
668 DictionaryValue* ext; | 712 DictionaryValue* ext; |
669 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { | 713 if (!extension_data->GetDictionaryWithoutPathExpansion(*extension_id, &ext)) { |
670 LOG(WARNING) << "Invalid pref for extension " << *extension_id; | 714 LOG(WARNING) << "Invalid pref for extension " << *extension_id; |
671 NOTREACHED(); | 715 NOTREACHED(); |
672 return NULL; | 716 return NULL; |
673 } | 717 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 std::string ExtensionPrefs::GetUpdateUrlData(const std::string& extension_id) { | 957 std::string ExtensionPrefs::GetUpdateUrlData(const std::string& extension_id) { |
914 DictionaryValue* dictionary = GetExtensionPref(extension_id); | 958 DictionaryValue* dictionary = GetExtensionPref(extension_id); |
915 if (!dictionary) | 959 if (!dictionary) |
916 return std::string(); | 960 return std::string(); |
917 | 961 |
918 std::string data; | 962 std::string data; |
919 dictionary->GetString(kUpdateUrlData, &data); | 963 dictionary->GetString(kUpdateUrlData, &data); |
920 return data; | 964 return data; |
921 } | 965 } |
922 | 966 |
967 base::Time ExtensionPrefs::GetCurrentTime() const { | |
968 return base::Time::Now(); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
How does that implementation allow to inject a clo
battre (please use the other)
2010/11/19 16:03:18
that was a bug. Done.
| |
969 } | |
970 | |
971 base::Time ExtensionPrefs::GetInstallTime(const DictionaryValue* extension) | |
972 const { | |
973 DCHECK(extension); | |
974 std::string install_time_str("0"); | |
975 extension->GetString(kPrefInstallTime, &install_time_str); | |
976 int64 install_time_i64 = 0; | |
977 base::StringToInt64(install_time_str, &install_time_i64); | |
978 LOG_IF(ERROR, install_time_i64 == 0) | |
979 << "Error parsing installation time of an extension"; | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
period/exclamation mark?
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
980 return base::Time::FromInternalValue(install_time_i64); | |
981 } | |
982 | |
983 void ExtensionPrefs::InstallPersistedExtensionControlledPrefs() { | |
984 // When this is called, the PrefService is initialized and provides access | |
985 // to the user preferences stored in a JSON file. We take the persisted | |
986 // preferences of all extensions, calculate the effective preferences | |
987 // (considering that one extension overrides preferences of other extensions) | |
988 // and store the effective preferences in the PrefService. | |
989 | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
No blank line. The rationale is that you're commen
battre (please use the other)
2010/11/19 16:03:18
I considered this a comment about the entire funct
| |
990 const DictionaryValue* extensions = | |
991 pref_service()->GetDictionary(kExtensionsPref); | |
992 | |
993 // Collect extensions, sorted by time (latest installed appears last). | |
994 std::vector<DictionaryValue*> sorted_extensions; | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
How about just using a set with the right comparat
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
995 for (DictionaryValue::key_iterator ext_id = extensions->begin_keys(); | |
996 ext_id != extensions->end_keys(); ++ext_id) { | |
997 if (GetExtensionState(*ext_id) != Extension::ENABLED) | |
998 continue; | |
999 | |
1000 DictionaryValue* extension = GetExtensionPref(*ext_id); | |
1001 CHECK(extension != NULL); | |
1002 | |
1003 if (GetInstallTime(extension) == base::Time::FromInternalValue(0)) { | |
1004 // Fix old entry that did not get an installation time entry when | |
1005 // it was installed. | |
1006 const base::Time installTime = GetCurrentTime(); | |
1007 extension->Set(kPrefInstallTime, | |
1008 Value::CreateStringValue( | |
1009 base::Int64ToString(installTime.ToInternalValue()))); | |
1010 SavePrefsAndNotify(); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Can we call this after we're done, i.e. outside th
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
1011 } | |
1012 DictionaryValue* dummy_prefs; | |
1013 if (!extension->GetDictionary(kPrefPreferences, &dummy_prefs)) { | |
1014 extension->Set(kPrefPreferences, new DictionaryValue()); | |
1015 } | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Wouldn't it be more obvious to do the defaulting l
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
1016 | |
1017 // Currently we sort only by time, no tie-breaker. | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
Implement sorting inline? Please don't :) And plea
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
1018 std::vector<DictionaryValue*>::iterator insert_pos = | |
1019 sorted_extensions.begin(); | |
1020 while (insert_pos != sorted_extensions.end() && | |
1021 GetInstallTime(extension) > GetInstallTime(*insert_pos)) { | |
1022 ++insert_pos; | |
1023 } | |
1024 sorted_extensions.insert(insert_pos, extension); | |
1025 } | |
1026 | |
1027 // Collect all effective preferences (later ones override newer ones). | |
1028 scoped_ptr<DictionaryValue> merged_non_expanded(new DictionaryValue); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
why is this a scoped_ptr instead of a plain Dictio
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
1029 for (std::vector<DictionaryValue*>::iterator i = sorted_extensions.begin(); | |
1030 i != sorted_extensions.end(); ++i) { | |
1031 DictionaryValue* preferences; | |
1032 if ((*i)->GetDictionary(kPrefPreferences, &preferences)) | |
1033 merged_non_expanded->MergeDictionary(preferences); | |
1034 } | |
1035 | |
1036 // Expand all keys. | |
1037 scoped_ptr<InMemoryPrefStore> extension_prefs(new InMemoryPrefStore); | |
1038 for (DictionaryValue::key_iterator prefkey = | |
1039 merged_non_expanded->begin_keys(); | |
1040 prefkey != merged_non_expanded->end_keys(); | |
1041 ++prefkey) { | |
1042 Value* value; | |
1043 CHECK(merged_non_expanded->GetWithoutPathExpansion(*prefkey, &value)); | |
1044 extension_prefs->prefs()->Set(*prefkey, value->DeepCopy()); | |
1045 } | |
1046 | |
1047 // Store result in pref service. | |
1048 pref_service()->pref_value_store()->ReplaceExtensionPrefStore( | |
1049 extension_prefs.release()); | |
1050 } | |
1051 | |
1052 namespace subtle { | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
you can just use an anonymous namespace here, I th
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
1053 static bool equalValues(const Value* a, const Value* b) { | |
1054 if ((a == NULL) && (b == NULL)) return true; | |
1055 if ((a == NULL) ^ (b == NULL)) return false; | |
1056 return a->Equals(b); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
this can be rewritten as a == NULL ? b == NULL : a
battre (please use the other)
2010/11/19 16:03:18
nice. :-)
Done.
| |
1057 } | |
1058 } | |
1059 | |
1060 const Value* ExtensionPrefs::WinningExtensionControlledPrefValue( | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
It bothers me a bit that you have the logic that m
battre (please use the other)
2010/11/19 16:03:18
I have simplified it a bit at least.
| |
1061 const std::string& key) const { | |
1062 Value *winner = NULL; | |
1063 int64 winners_install_time = 0; | |
1064 | |
1065 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref); | |
1066 for (DictionaryValue::key_iterator ext_iter = extensions->begin_keys(); | |
1067 ext_iter != extensions->end_keys(); ++ext_iter) { | |
1068 if (GetExtensionState(*ext_iter) != Extension::ENABLED) | |
1069 continue; | |
1070 | |
1071 DictionaryValue* extension = GetExtensionPref(*ext_iter); | |
1072 CHECK(extension); | |
1073 | |
1074 std::string extension_install_time_s = "0"; | |
1075 extension->GetString(kPrefInstallTime, &extension_install_time_s); | |
1076 int64 extension_install_time = 0; | |
1077 base::StringToInt64(extension_install_time_s, &extension_install_time); | |
1078 | |
1079 // We do not need to consider extensions that were installed before the | |
1080 // most recent extension found that provides the requested preference. | |
1081 if (extension_install_time < winners_install_time) { | |
1082 continue; | |
1083 } | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
No need for curlies.
battre (please use the other)
2010/11/19 16:03:18
Done.
| |
1084 | |
1085 DictionaryValue* preferences = GetExtensionControlledPrefs(*ext_iter); | |
1086 CHECK(preferences); | |
1087 | |
1088 Value *value = NULL; | |
1089 if (preferences->GetWithoutPathExpansion(key, &value)) { | |
1090 // This extension is more recent than the last one providing this pref. | |
1091 winner = value; | |
1092 winners_install_time = extension_install_time; | |
1093 } | |
1094 } | |
1095 return winner; | |
1096 } | |
1097 | |
1098 void ExtensionPrefs::UpdateWinningPref(const std::string& pref_key) { | |
1099 PrefStore* extensionPrefStore = | |
1100 pref_service()->pref_value_store()->GetExtensionPrefStore(); | |
1101 const Value* winningPrefValue = WinningExtensionControlledPrefValue(pref_key); | |
1102 Value* oldValue = NULL; | |
1103 extensionPrefStore->prefs()->Get(pref_key, &oldValue); | |
1104 bool changed = !subtle::equalValues(winningPrefValue, oldValue); | |
1105 | |
1106 if (winningPrefValue) { | |
1107 extensionPrefStore->prefs()->Set(pref_key, winningPrefValue->DeepCopy()); | |
1108 } else { | |
1109 extensionPrefStore->prefs()->Remove(pref_key, NULL); | |
1110 } | |
1111 | |
1112 if (changed) | |
1113 pref_service()->pref_notifier()->OnPreferenceSet( | |
1114 pref_key.c_str(), PrefNotifier::EXTENSION_STORE); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
hm, 1103 to here really looks like it should be a
battre (please use the other)
2010/11/19 16:03:18
I agree. Added a TODO.
| |
1115 } | |
1116 | |
1117 void ExtensionPrefs::SetExtensionControlledPref(const std::string& extension_id, | |
1118 const std::string& pref_key, | |
1119 Value* value) { | |
1120 DictionaryValue* extensionPreferences = | |
1121 GetExtensionControlledPrefs(extension_id); | |
1122 | |
1123 Value* oldValue = NULL; | |
1124 extensionPreferences->GetWithoutPathExpansion(pref_key, &oldValue); | |
1125 bool modified = subtle::equalValues(oldValue, value); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
if (!modified)
return;
battre (please use the other)
2010/11/19 16:03:18
Done. Also inserted the missing !.
| |
1126 | |
1127 if (value == NULL) | |
1128 extensionPreferences->RemoveWithoutPathExpansion(pref_key, NULL); | |
1129 else | |
1130 extensionPreferences->SetWithoutPathExpansion(pref_key, value); | |
1131 | |
1132 if (modified) | |
1133 pref_service()->ScheduleSavePersistentPrefs(); | |
Mattias Nissler (ping if slow)
2010/11/19 10:36:12
You don't need to do that explicitly, the browser
battre (please use the other)
2010/11/19 16:03:18
I think is it better to be crash save. WDYT?
| |
1134 | |
1135 UpdateWinningPref(pref_key); | |
1136 } | |
1137 | |
1138 void ExtensionPrefs::GetExtensionControlledPrefKeys( | |
1139 const std::string& extension_id, std::vector<std::string> *out) const { | |
1140 DCHECK(out != NULL); | |
1141 DictionaryValue* extPrefs = GetExtensionControlledPrefs(extension_id); | |
1142 if (extPrefs) { | |
1143 for (DictionaryValue::key_iterator i = extPrefs->begin_keys(); | |
1144 i != extPrefs->end_keys(); ++i) { | |
1145 out->push_back(*i); | |
1146 } | |
1147 } | |
1148 } | |
1149 | |
923 // static | 1150 // static |
924 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { | 1151 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { |
925 prefs->RegisterDictionaryPref(kExtensionsPref); | 1152 prefs->RegisterDictionaryPref(kExtensionsPref); |
926 prefs->RegisterListPref(kExtensionToolbar); | 1153 prefs->RegisterListPref(kExtensionToolbar); |
927 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); | 1154 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); |
928 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); | 1155 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); |
929 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); | 1156 prefs->RegisterListPref(prefs::kExtensionInstallAllowList); |
930 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); | 1157 prefs->RegisterListPref(prefs::kExtensionInstallDenyList); |
931 prefs->RegisterListPref(prefs::kExtensionInstallForceList); | 1158 prefs->RegisterListPref(prefs::kExtensionInstallForceList); |
932 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); | 1159 prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); |
933 } | 1160 } |
OLD | NEW |