OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_prefs.h" | 5 #include "extensions/browser/extension_prefs.h" |
6 | 6 |
7 #include <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/prefs/pref_notifier.h" | 10 #include "base/prefs/pref_notifier.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 189 |
190 // A preference indicating whether the extension is an ephemeral app. | 190 // A preference indicating whether the extension is an ephemeral app. |
191 const char kPrefEphemeralApp[] = "ephemeral_app"; | 191 const char kPrefEphemeralApp[] = "ephemeral_app"; |
192 | 192 |
193 // Am installation parameter bundled with an extension. | 193 // Am installation parameter bundled with an extension. |
194 const char kPrefInstallParam[] = "install_parameter"; | 194 const char kPrefInstallParam[] = "install_parameter"; |
195 | 195 |
196 // A list of installed ids and a signature. | 196 // A list of installed ids and a signature. |
197 const char kInstallSignature[] = "extensions.install_signature"; | 197 const char kInstallSignature[] = "extensions.install_signature"; |
198 | 198 |
| 199 // A boolean preference that indicates whether the extension should not be |
| 200 // synced. Default value is false. |
| 201 const char kPrefDoNotSync[] = "do_not_sync"; |
| 202 |
199 // Provider of write access to a dictionary storing extension prefs. | 203 // Provider of write access to a dictionary storing extension prefs. |
200 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { | 204 class ScopedExtensionPrefUpdate : public DictionaryPrefUpdate { |
201 public: | 205 public: |
202 ScopedExtensionPrefUpdate(PrefService* service, | 206 ScopedExtensionPrefUpdate(PrefService* service, |
203 const std::string& extension_id) : | 207 const std::string& extension_id) : |
204 DictionaryPrefUpdate(service, pref_names::kExtensions), | 208 DictionaryPrefUpdate(service, pref_names::kExtensions), |
205 extension_id_(extension_id) {} | 209 extension_id_(extension_id) {} |
206 | 210 |
207 virtual ~ScopedExtensionPrefUpdate() { | 211 virtual ~ScopedExtensionPrefUpdate() { |
208 } | 212 } |
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 } | 1742 } |
1739 std::string install_time_str; | 1743 std::string install_time_str; |
1740 if (!extension->GetString(kPrefInstallTime, &install_time_str)) | 1744 if (!extension->GetString(kPrefInstallTime, &install_time_str)) |
1741 return base::Time(); | 1745 return base::Time(); |
1742 int64 install_time_i64 = 0; | 1746 int64 install_time_i64 = 0; |
1743 if (!base::StringToInt64(install_time_str, &install_time_i64)) | 1747 if (!base::StringToInt64(install_time_str, &install_time_i64)) |
1744 return base::Time(); | 1748 return base::Time(); |
1745 return base::Time::FromInternalValue(install_time_i64); | 1749 return base::Time::FromInternalValue(install_time_i64); |
1746 } | 1750 } |
1747 | 1751 |
| 1752 bool ExtensionPrefs::DoNotSync(const std::string& extension_id) const { |
| 1753 bool do_not_sync; |
| 1754 if (!ReadPrefAsBoolean(extension_id, kPrefDoNotSync, &do_not_sync)) |
| 1755 return false; |
| 1756 |
| 1757 return do_not_sync; |
| 1758 } |
| 1759 |
1748 base::Time ExtensionPrefs::GetLastLaunchTime( | 1760 base::Time ExtensionPrefs::GetLastLaunchTime( |
1749 const std::string& extension_id) const { | 1761 const std::string& extension_id) const { |
1750 const base::DictionaryValue* extension = GetExtensionPref(extension_id); | 1762 const base::DictionaryValue* extension = GetExtensionPref(extension_id); |
1751 if (!extension) | 1763 if (!extension) |
1752 return base::Time(); | 1764 return base::Time(); |
1753 | 1765 |
1754 std::string launch_time_str; | 1766 std::string launch_time_str; |
1755 if (!extension->GetString(kPrefLastLaunchTime, &launch_time_str)) | 1767 if (!extension->GetString(kPrefLastLaunchTime, &launch_time_str)) |
1756 return base::Time(); | 1768 return base::Time(); |
1757 int64 launch_time_i64 = 0; | 1769 int64 launch_time_i64 = 0; |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 if (!install_parameter.empty()) { | 2135 if (!install_parameter.empty()) { |
2124 extension_dict->Set(kPrefInstallParam, | 2136 extension_dict->Set(kPrefInstallParam, |
2125 new base::StringValue(install_parameter)); | 2137 new base::StringValue(install_parameter)); |
2126 } | 2138 } |
2127 // We store prefs about LOAD extensions, but don't cache their manifest | 2139 // We store prefs about LOAD extensions, but don't cache their manifest |
2128 // since it may change on disk. | 2140 // since it may change on disk. |
2129 if (!Manifest::IsUnpackedLocation(extension->location())) { | 2141 if (!Manifest::IsUnpackedLocation(extension->location())) { |
2130 extension_dict->Set(kPrefManifest, | 2142 extension_dict->Set(kPrefManifest, |
2131 extension->manifest()->value()->DeepCopy()); | 2143 extension->manifest()->value()->DeepCopy()); |
2132 } | 2144 } |
| 2145 |
| 2146 // Only writes kPrefDoNotSync when it is not the default. |
| 2147 if (install_flags & kInstallFlagDoNotSync) |
| 2148 extension_dict->Set(kPrefDoNotSync, new base::FundamentalValue(true)); |
| 2149 else |
| 2150 extension_dict->Remove(kPrefDoNotSync, NULL); |
2133 } | 2151 } |
2134 | 2152 |
2135 void ExtensionPrefs::InitExtensionControlledPrefs( | 2153 void ExtensionPrefs::InitExtensionControlledPrefs( |
2136 ExtensionPrefValueMap* value_map) { | 2154 ExtensionPrefValueMap* value_map) { |
2137 ExtensionIdList extension_ids; | 2155 ExtensionIdList extension_ids; |
2138 GetExtensions(&extension_ids); | 2156 GetExtensions(&extension_ids); |
2139 | 2157 |
2140 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); | 2158 for (ExtensionIdList::iterator extension_id = extension_ids.begin(); |
2141 extension_id != extension_ids.end(); | 2159 extension_id != extension_ids.end(); |
2142 ++extension_id) { | 2160 ++extension_id) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2226 extension_pref_value_map_->RegisterExtension( | 2244 extension_pref_value_map_->RegisterExtension( |
2227 extension_id, install_time, is_enabled, is_incognito_enabled); | 2245 extension_id, install_time, is_enabled, is_incognito_enabled); |
2228 | 2246 |
2229 FOR_EACH_OBSERVER( | 2247 FOR_EACH_OBSERVER( |
2230 ExtensionPrefsObserver, | 2248 ExtensionPrefsObserver, |
2231 observer_list_, | 2249 observer_list_, |
2232 OnExtensionRegistered(extension_id, install_time, is_enabled)); | 2250 OnExtensionRegistered(extension_id, install_time, is_enabled)); |
2233 } | 2251 } |
2234 | 2252 |
2235 } // namespace extensions | 2253 } // namespace extensions |
OLD | NEW |