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 "chrome/browser/chromeos/file_system_provider/registry.h" | 5 #include "chrome/browser/chromeos/file_system_provider/registry.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 11 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
12 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 12 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
15 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 15 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "components/pref_registry/pref_registry_syncable.h" | 18 #include "components/pref_registry/pref_registry_syncable.h" |
19 #include "extensions/browser/extension_registry.h" | 19 #include "extensions/browser/extension_registry.h" |
20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
21 #include "storage/browser/fileapi/external_mount_points.h" | 21 #include "storage/browser/fileapi/external_mount_points.h" |
22 | 22 |
23 namespace chromeos { | 23 namespace chromeos { |
24 namespace file_system_provider { | 24 namespace file_system_provider { |
25 | 25 |
26 const char kPrefKeyFileSystemId[] = "file-system-id"; | 26 const char kPrefKeyFileSystemId[] = "file-system-id"; |
27 const char kPrefKeyDisplayName[] = "display-name"; | 27 const char kPrefKeyDisplayName[] = "display-name"; |
28 const char kPrefKeyWritable[] = "writable"; | 28 const char kPrefKeyWritable[] = "writable"; |
| 29 const char kPrefKeySource[] = "source"; |
29 const char kPrefKeySupportsNotifyTag[] = "supports-notify-tag"; | 30 const char kPrefKeySupportsNotifyTag[] = "supports-notify-tag"; |
30 const char kPrefKeyWatchers[] = "watchers"; | 31 const char kPrefKeyWatchers[] = "watchers"; |
31 const char kPrefKeyWatcherEntryPath[] = "entry-path"; | 32 const char kPrefKeyWatcherEntryPath[] = "entry-path"; |
32 const char kPrefKeyWatcherRecursive[] = "recursive"; | 33 const char kPrefKeyWatcherRecursive[] = "recursive"; |
33 const char kPrefKeyWatcherLastTag[] = "last-tag"; | 34 const char kPrefKeyWatcherLastTag[] = "last-tag"; |
34 const char kPrefKeyWatcherPersistentOrigins[] = "persistent-origins"; | 35 const char kPrefKeyWatcherPersistentOrigins[] = "persistent-origins"; |
35 const char kPrefKeyOpenedFilesLimit[] = "opened-files-limit"; | 36 const char kPrefKeyOpenedFilesLimit[] = "opened-files-limit"; |
36 | 37 |
37 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 38 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
38 registry->RegisterDictionaryPref( | 39 registry->RegisterDictionaryPref( |
39 prefs::kFileSystemProviderMounted, | 40 prefs::kFileSystemProviderMounted, |
40 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 41 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
41 } | 42 } |
42 | 43 |
| 44 std::string SourceToString(Source source) { |
| 45 switch (source) { |
| 46 case SOURCE_UNKNOWN: |
| 47 return "unknown"; |
| 48 case SOURCE_FILE: |
| 49 return "file"; |
| 50 case SOURCE_DEVICE: |
| 51 return "device"; |
| 52 case SOURCE_NETWORK: |
| 53 return "network"; |
| 54 } |
| 55 NOTREACHED(); |
| 56 return std::string(); |
| 57 } |
| 58 |
| 59 bool StringToSource(const std::string& source, Source* result) { |
| 60 if (source.compare("unknown") == 0) { |
| 61 *result = SOURCE_UNKNOWN; |
| 62 return true; |
| 63 } |
| 64 if (source.compare("file") == 0) { |
| 65 *result = SOURCE_FILE; |
| 66 return true; |
| 67 } |
| 68 if (source.compare("device") == 0) { |
| 69 *result = SOURCE_DEVICE; |
| 70 return true; |
| 71 } |
| 72 if (source.compare("network") == 0) { |
| 73 *result = SOURCE_NETWORK; |
| 74 return true; |
| 75 } |
| 76 return false; |
| 77 } |
| 78 |
43 Registry::Registry(Profile* profile) : profile_(profile) { | 79 Registry::Registry(Profile* profile) : profile_(profile) { |
44 } | 80 } |
45 | 81 |
46 Registry::~Registry() { | 82 Registry::~Registry() { |
47 } | 83 } |
48 | 84 |
49 void Registry::RememberFileSystem( | 85 void Registry::RememberFileSystem( |
50 const ProvidedFileSystemInfo& file_system_info, | 86 const ProvidedFileSystemInfo& file_system_info, |
51 const Watchers& watchers) { | 87 const Watchers& watchers) { |
52 base::DictionaryValue* const file_system = new base::DictionaryValue(); | 88 base::DictionaryValue* const file_system = new base::DictionaryValue(); |
53 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 89 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
54 file_system_info.file_system_id()); | 90 file_system_info.file_system_id()); |
55 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, | 91 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, |
56 file_system_info.display_name()); | 92 file_system_info.display_name()); |
57 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, | 93 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, |
58 file_system_info.writable()); | 94 file_system_info.writable()); |
| 95 file_system->SetStringWithoutPathExpansion( |
| 96 kPrefKeySource, SourceToString(file_system_info.source())); |
59 file_system->SetBooleanWithoutPathExpansion( | 97 file_system->SetBooleanWithoutPathExpansion( |
60 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); | 98 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); |
61 file_system->SetIntegerWithoutPathExpansion( | 99 file_system->SetIntegerWithoutPathExpansion( |
62 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit()); | 100 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit()); |
63 | 101 |
64 base::DictionaryValue* const watchers_value = new base::DictionaryValue(); | 102 base::DictionaryValue* const watchers_value = new base::DictionaryValue(); |
65 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value); | 103 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value); |
66 | 104 |
67 for (const auto& it : watchers) { | 105 for (const auto& it : watchers) { |
68 base::DictionaryValue* const watcher = new base::DictionaryValue(); | 106 base::DictionaryValue* const watcher = new base::DictionaryValue(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 const base::DictionaryValue* file_system = NULL; | 184 const base::DictionaryValue* file_system = NULL; |
147 file_systems_per_extension->GetWithoutPathExpansion(it.key(), | 185 file_systems_per_extension->GetWithoutPathExpansion(it.key(), |
148 &file_system_value); | 186 &file_system_value); |
149 DCHECK(file_system_value); | 187 DCHECK(file_system_value); |
150 | 188 |
151 std::string file_system_id; | 189 std::string file_system_id; |
152 std::string display_name; | 190 std::string display_name; |
153 bool writable = false; | 191 bool writable = false; |
154 bool supports_notify_tag = false; | 192 bool supports_notify_tag = false; |
155 int opened_files_limit = 0; | 193 int opened_files_limit = 0; |
| 194 std::string source_as_string; |
| 195 Source source = SOURCE_UNKNOWN; |
156 | 196 |
157 // TODO(mtomasz): Move opened files limit to the mandatory list above in | 197 // TODO(mtomasz): Move opened files limit to the mandatory list above in |
158 // M42. | 198 // M42. |
159 if ((!file_system_value->GetAsDictionary(&file_system) || | 199 if ((!file_system_value->GetAsDictionary(&file_system) || |
160 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 200 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
161 &file_system_id) || | 201 &file_system_id) || |
162 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, | 202 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, |
163 &display_name) || | 203 &display_name) || |
164 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, | 204 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, |
165 &writable) || | 205 &writable) || |
166 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, | 206 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, |
167 &supports_notify_tag) || | 207 &supports_notify_tag) || |
168 file_system_id.empty() || display_name.empty()) || | 208 file_system_id.empty() || display_name.empty()) || |
| 209 // Optional fields. |
169 (file_system->GetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, | 210 (file_system->GetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, |
170 &opened_files_limit) && | 211 &opened_files_limit) && |
171 opened_files_limit < 0)) { | 212 (file_system->GetStringWithoutPathExpansion(kPrefKeySource, |
| 213 &source_as_string) && |
| 214 !StringToSource(source_as_string, &source)))) { |
172 LOG(ERROR) | 215 LOG(ERROR) |
173 << "Malformed provided file system information in preferences."; | 216 << "Malformed provided file system information in preferences."; |
174 continue; | 217 continue; |
175 } | 218 } |
176 | 219 |
177 MountOptions options; | 220 MountOptions options; |
178 options.file_system_id = file_system_id; | 221 options.file_system_id = file_system_id; |
179 options.display_name = display_name; | 222 options.display_name = display_name; |
180 options.writable = writable; | 223 options.writable = writable; |
| 224 options.source = source; |
181 options.supports_notify_tag = supports_notify_tag; | 225 options.supports_notify_tag = supports_notify_tag; |
182 options.opened_files_limit = opened_files_limit; | 226 options.opened_files_limit = opened_files_limit; |
183 | 227 |
184 RestoredFileSystem restored_file_system; | 228 RestoredFileSystem restored_file_system; |
185 restored_file_system.extension_id = extension_id; | 229 restored_file_system.extension_id = extension_id; |
186 restored_file_system.options = options; | 230 restored_file_system.options = options; |
187 | 231 |
188 // Restore watchers. It's optional, since this field is new. | 232 // Restore watchers. It's optional, since this field is new. |
189 const base::DictionaryValue* watchers = NULL; | 233 const base::DictionaryValue* watchers = NULL; |
190 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, | 234 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 LOG(ERROR) << "Broken preferences detected while updating a tag."; | 315 LOG(ERROR) << "Broken preferences detected while updating a tag."; |
272 return; | 316 return; |
273 } | 317 } |
274 | 318 |
275 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 319 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
276 watcher.last_tag); | 320 watcher.last_tag); |
277 } | 321 } |
278 | 322 |
279 } // namespace file_system_provider | 323 } // namespace file_system_provider |
280 } // namespace chromeos | 324 } // namespace chromeos |
OLD | NEW |