OLD | NEW |
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/extension_prefs.h" | 5 #include "chrome/browser/extensions/extension_prefs.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/api/alarms/alarm_manager.h" |
10 #include "chrome/browser/extensions/extension_pref_store.h" | 11 #include "chrome/browser/extensions/extension_pref_store.h" |
11 #include "chrome/browser/extensions/extension_sorting.h" | 12 #include "chrome/browser/extensions/extension_sorting.h" |
12 #include "chrome/browser/prefs/pref_notifier.h" | 13 #include "chrome/browser/prefs/pref_notifier.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/extensions/manifest.h" | 17 #include "chrome/common/extensions/manifest.h" |
17 #include "chrome/common/extensions/url_pattern.h" | 18 #include "chrome/common/extensions/url_pattern.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // A preference that contains extension-set content settings. | 150 // A preference that contains extension-set content settings. |
150 const char kPrefContentSettings[] = "content_settings"; | 151 const char kPrefContentSettings[] = "content_settings"; |
151 | 152 |
152 // A preference that contains extension-set content settings. | 153 // A preference that contains extension-set content settings. |
153 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; | 154 const char kPrefIncognitoContentSettings[] = "incognito_content_settings"; |
154 | 155 |
155 // A list of event names that this extension has registered from its lazy | 156 // A list of event names that this extension has registered from its lazy |
156 // background page. | 157 // background page. |
157 const char kRegisteredEvents[] = "events"; | 158 const char kRegisteredEvents[] = "events"; |
158 | 159 |
| 160 // A list of alarms that this extension has set. |
| 161 const char kRegisteredAlarms[] = "alarms"; |
| 162 const char kAlarmScheduledRunTime[] = "scheduled_run_time"; |
| 163 |
159 // Provider of write access to a dictionary storing extension prefs. | 164 // Provider of write access to a dictionary storing extension prefs. |
160 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 165 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
161 public: | 166 public: |
162 ScopedExtensionPrefUpdate(PrefService* service, | 167 ScopedExtensionPrefUpdate(PrefService* service, |
163 const std::string& extension_id) : | 168 const std::string& extension_id) : |
164 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), | 169 DictionaryPrefUpdate(service, ExtensionPrefs::kExtensionsPref), |
165 extension_id_(extension_id) {} | 170 extension_id_(extension_id) {} |
166 | 171 |
167 virtual ~ScopedExtensionPrefUpdate() { | 172 virtual ~ScopedExtensionPrefUpdate() { |
168 } | 173 } |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 void ExtensionPrefs::SetRegisteredEvents( | 931 void ExtensionPrefs::SetRegisteredEvents( |
927 const std::string& extension_id, const std::set<std::string>& events) { | 932 const std::string& extension_id, const std::set<std::string>& events) { |
928 ListValue* value = new ListValue(); | 933 ListValue* value = new ListValue(); |
929 for (std::set<std::string>::const_iterator it = events.begin(); | 934 for (std::set<std::string>::const_iterator it = events.begin(); |
930 it != events.end(); ++it) { | 935 it != events.end(); ++it) { |
931 value->Append(new StringValue(*it)); | 936 value->Append(new StringValue(*it)); |
932 } | 937 } |
933 UpdateExtensionPref(extension_id, kRegisteredEvents, value); | 938 UpdateExtensionPref(extension_id, kRegisteredEvents, value); |
934 } | 939 } |
935 | 940 |
| 941 std::vector<extensions::AlarmPref> ExtensionPrefs::GetRegisteredAlarms( |
| 942 const std::string& extension_id) { |
| 943 std::vector<extensions::AlarmPref> alarms; |
| 944 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
| 945 if (!extension) |
| 946 return alarms; |
| 947 |
| 948 base::ListValue* list = NULL; |
| 949 if (!extension->GetList(kRegisteredAlarms, &list)) |
| 950 return alarms; |
| 951 |
| 952 typedef extensions::AlarmManager::Alarm Alarm; |
| 953 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 954 base::DictionaryValue* alarm_dict = NULL; |
| 955 extensions::AlarmPref alarm; |
| 956 alarm.alarm.reset(new Alarm()); |
| 957 if (list->GetDictionary(i, &alarm_dict) && |
| 958 Alarm::Populate(*alarm_dict, alarm.alarm.get())) { |
| 959 alarm.scheduled_run_time = ReadTime(alarm_dict, kAlarmScheduledRunTime); |
| 960 alarms.push_back(alarm); |
| 961 } |
| 962 } |
| 963 return alarms; |
| 964 } |
| 965 |
| 966 void ExtensionPrefs::SetRegisteredAlarms( |
| 967 const std::string& extension_id, |
| 968 const std::vector<extensions::AlarmPref>& alarms) { |
| 969 base::ListValue* list = new ListValue(); |
| 970 for (size_t i = 0; i < alarms.size(); ++i) { |
| 971 scoped_ptr<base::DictionaryValue> alarm = alarms[i].alarm->ToValue().Pass(); |
| 972 SaveTime(alarm.get(), kAlarmScheduledRunTime, alarms[i].scheduled_run_time); |
| 973 list->Append(alarm.release()); |
| 974 } |
| 975 UpdateExtensionPref(extension_id, kRegisteredAlarms, list); |
| 976 } |
| 977 |
936 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { | 978 bool ExtensionPrefs::IsIncognitoEnabled(const std::string& extension_id) { |
937 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); | 979 return ReadExtensionPrefBoolean(extension_id, kPrefIncognitoEnabled); |
938 } | 980 } |
939 | 981 |
940 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, | 982 void ExtensionPrefs::SetIsIncognitoEnabled(const std::string& extension_id, |
941 bool enabled) { | 983 bool enabled) { |
942 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, | 984 UpdateExtensionPref(extension_id, kPrefIncognitoEnabled, |
943 Value::CreateBooleanValue(enabled)); | 985 Value::CreateBooleanValue(enabled)); |
944 } | 986 } |
945 | 987 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 FilePath::StringType path = MakePathRelative(install_directory_, | 1165 FilePath::StringType path = MakePathRelative(install_directory_, |
1124 extension->path()); | 1166 extension->path()); |
1125 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); | 1167 extension_dict->Set(kPrefPath, Value::CreateStringValue(path)); |
1126 // We store prefs about LOAD extensions, but don't cache their manifest | 1168 // We store prefs about LOAD extensions, but don't cache their manifest |
1127 // since it may change on disk. | 1169 // since it may change on disk. |
1128 if (extension->location() != Extension::LOAD) { | 1170 if (extension->location() != Extension::LOAD) { |
1129 extension_dict->Set(kPrefManifest, | 1171 extension_dict->Set(kPrefManifest, |
1130 extension->manifest()->value()->DeepCopy()); | 1172 extension->manifest()->value()->DeepCopy()); |
1131 } | 1173 } |
1132 | 1174 |
1133 // Clear any events that may be registered from a previous install. | 1175 // Clear any events and alarms that may be registered from a previous install. |
1134 extension_dict->Remove(kRegisteredEvents, NULL); | 1176 extension_dict->Remove(kRegisteredEvents, NULL); |
| 1177 extension_dict->Remove(kRegisteredAlarms, NULL); |
1135 | 1178 |
1136 if (extension->is_app()) { | 1179 if (extension->is_app()) { |
1137 StringOrdinal new_page_ordinal = page_ordinal.IsValid() ? | 1180 StringOrdinal new_page_ordinal = page_ordinal.IsValid() ? |
1138 page_ordinal : extension_sorting_->GetNaturalAppPageOrdinal(); | 1181 page_ordinal : extension_sorting_->GetNaturalAppPageOrdinal(); |
1139 if (!extension_sorting_->GetPageOrdinal(id).IsValid()) | 1182 if (!extension_sorting_->GetPageOrdinal(id).IsValid()) |
1140 extension_sorting_->SetPageOrdinal(id, new_page_ordinal); | 1183 extension_sorting_->SetPageOrdinal(id, new_page_ordinal); |
1141 if (!extension_sorting_->GetAppLaunchOrdinal(id).IsValid()) | 1184 if (!extension_sorting_->GetAppLaunchOrdinal(id).IsValid()) |
1142 extension_sorting_->SetAppLaunchOrdinal( | 1185 extension_sorting_->SetAppLaunchOrdinal( |
1143 id, extension_sorting_->CreateNextAppLaunchOrdinal(new_page_ordinal)); | 1186 id, extension_sorting_->CreateNextAppLaunchOrdinal(new_page_ordinal)); |
1144 } | 1187 } |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, | 1847 prefs->RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, |
1805 "0", // default value | 1848 "0", // default value |
1806 PrefService::UNSYNCABLE_PREF); | 1849 PrefService::UNSYNCABLE_PREF); |
1807 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, | 1850 prefs->RegisterInt64Pref(prefs::kLastExtensionsUpdateCheck, |
1808 0, // default value | 1851 0, // default value |
1809 PrefService::UNSYNCABLE_PREF); | 1852 PrefService::UNSYNCABLE_PREF); |
1810 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, | 1853 prefs->RegisterInt64Pref(prefs::kNextExtensionsUpdateCheck, |
1811 0, // default value | 1854 0, // default value |
1812 PrefService::UNSYNCABLE_PREF); | 1855 PrefService::UNSYNCABLE_PREF); |
1813 } | 1856 } |
OLD | NEW |