| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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 kPrefKeySupportsNotifyTag[] = "supports-notify-tag"; | 29 const char kPrefKeySupportsNotifyTag[] = "supports-notify-tag"; |
| 30 const char kPrefKeyWatchers[] = "watchers"; | 30 const char kPrefKeyWatchers[] = "watchers"; |
| 31 const char kPrefKeyWatcherEntryPath[] = "entry-path"; | 31 const char kPrefKeyWatcherEntryPath[] = "entry-path"; |
| 32 const char kPrefKeyWatcherRecursive[] = "recursive"; | 32 const char kPrefKeyWatcherRecursive[] = "recursive"; |
| 33 const char kPrefKeyWatcherLastTag[] = "last-tag"; | 33 const char kPrefKeyWatcherLastTag[] = "last-tag"; |
| 34 const char kPrefKeyWatcherPersistentOrigins[] = "persistent-origins"; | 34 const char kPrefKeyWatcherPersistentOrigins[] = "persistent-origins"; |
| 35 const char kPrefKeyOpenedFilesLimit[] = "opened-files-limit"; |
| 35 | 36 |
| 36 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 37 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 37 registry->RegisterDictionaryPref( | 38 registry->RegisterDictionaryPref( |
| 38 prefs::kFileSystemProviderMounted, | 39 prefs::kFileSystemProviderMounted, |
| 39 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 40 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 40 } | 41 } |
| 41 | 42 |
| 42 Registry::Registry(Profile* profile) : profile_(profile) { | 43 Registry::Registry(Profile* profile) : profile_(profile) { |
| 43 } | 44 } |
| 44 | 45 |
| 45 Registry::~Registry() { | 46 Registry::~Registry() { |
| 46 } | 47 } |
| 47 | 48 |
| 48 void Registry::RememberFileSystem( | 49 void Registry::RememberFileSystem( |
| 49 const ProvidedFileSystemInfo& file_system_info, | 50 const ProvidedFileSystemInfo& file_system_info, |
| 50 const Watchers& watchers) { | 51 const Watchers& watchers) { |
| 51 base::DictionaryValue* const file_system = new base::DictionaryValue(); | 52 base::DictionaryValue* const file_system = new base::DictionaryValue(); |
| 52 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 53 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
| 53 file_system_info.file_system_id()); | 54 file_system_info.file_system_id()); |
| 54 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, | 55 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, |
| 55 file_system_info.display_name()); | 56 file_system_info.display_name()); |
| 56 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, | 57 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, |
| 57 file_system_info.writable()); | 58 file_system_info.writable()); |
| 58 file_system->SetBooleanWithoutPathExpansion( | 59 file_system->SetBooleanWithoutPathExpansion( |
| 59 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); | 60 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); |
| 61 file_system->SetIntegerWithoutPathExpansion( |
| 62 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit()); |
| 60 | 63 |
| 61 base::DictionaryValue* const watchers_value = new base::DictionaryValue(); | 64 base::DictionaryValue* const watchers_value = new base::DictionaryValue(); |
| 62 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value); | 65 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value); |
| 63 | 66 |
| 64 for (const auto& it : watchers) { | 67 for (const auto& it : watchers) { |
| 65 base::DictionaryValue* const watcher = new base::DictionaryValue(); | 68 base::DictionaryValue* const watcher = new base::DictionaryValue(); |
| 66 watchers_value->SetWithoutPathExpansion(it.second.entry_path.value(), | 69 watchers_value->SetWithoutPathExpansion(it.second.entry_path.value(), |
| 67 watcher); | 70 watcher); |
| 68 watcher->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, | 71 watcher->SetStringWithoutPathExpansion(kPrefKeyWatcherEntryPath, |
| 69 it.second.entry_path.value()); | 72 it.second.entry_path.value()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 const base::Value* file_system_value = NULL; | 145 const base::Value* file_system_value = NULL; |
| 143 const base::DictionaryValue* file_system = NULL; | 146 const base::DictionaryValue* file_system = NULL; |
| 144 file_systems_per_extension->GetWithoutPathExpansion(it.key(), | 147 file_systems_per_extension->GetWithoutPathExpansion(it.key(), |
| 145 &file_system_value); | 148 &file_system_value); |
| 146 DCHECK(file_system_value); | 149 DCHECK(file_system_value); |
| 147 | 150 |
| 148 std::string file_system_id; | 151 std::string file_system_id; |
| 149 std::string display_name; | 152 std::string display_name; |
| 150 bool writable = false; | 153 bool writable = false; |
| 151 bool supports_notify_tag = false; | 154 bool supports_notify_tag = false; |
| 155 int opened_files_limit = 0; |
| 152 | 156 |
| 153 if (!file_system_value->GetAsDictionary(&file_system) || | 157 // TODO(mtomasz): Move opened files limit to the mandatory list above in |
| 154 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 158 // M42. |
| 155 &file_system_id) || | 159 if ((!file_system_value->GetAsDictionary(&file_system) || |
| 156 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, | 160 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
| 157 &display_name) || | 161 &file_system_id) || |
| 158 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, | 162 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, |
| 159 &writable) || | 163 &display_name) || |
| 160 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, | 164 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, |
| 161 &supports_notify_tag) || | 165 &writable) || |
| 162 file_system_id.empty() || display_name.empty()) { | 166 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, |
| 167 &supports_notify_tag) || |
| 168 file_system_id.empty() || display_name.empty()) || |
| 169 (file_system->GetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, |
| 170 &opened_files_limit) && |
| 171 opened_files_limit < 0)) { |
| 163 LOG(ERROR) | 172 LOG(ERROR) |
| 164 << "Malformed provided file system information in preferences."; | 173 << "Malformed provided file system information in preferences."; |
| 165 continue; | 174 continue; |
| 166 } | 175 } |
| 167 | 176 |
| 168 MountOptions options; | 177 MountOptions options; |
| 169 options.file_system_id = file_system_id; | 178 options.file_system_id = file_system_id; |
| 170 options.display_name = display_name; | 179 options.display_name = display_name; |
| 171 options.writable = writable; | 180 options.writable = writable; |
| 172 options.supports_notify_tag = supports_notify_tag; | 181 options.supports_notify_tag = supports_notify_tag; |
| 182 options.opened_files_limit = opened_files_limit; |
| 173 | 183 |
| 174 RestoredFileSystem restored_file_system; | 184 RestoredFileSystem restored_file_system; |
| 175 restored_file_system.extension_id = extension_id; | 185 restored_file_system.extension_id = extension_id; |
| 176 restored_file_system.options = options; | 186 restored_file_system.options = options; |
| 177 | 187 |
| 178 // Restore watchers. It's optional, since this field is new. | 188 // Restore watchers. It's optional, since this field is new. |
| 179 const base::DictionaryValue* watchers = NULL; | 189 const base::DictionaryValue* watchers = NULL; |
| 180 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, | 190 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, |
| 181 &watchers)) { | 191 &watchers)) { |
| 182 for (base::DictionaryValue::Iterator it(*watchers); !it.IsAtEnd(); | 192 for (base::DictionaryValue::Iterator it(*watchers); !it.IsAtEnd(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 LOG(ERROR) << "Broken preferences detected while updating a tag."; | 271 LOG(ERROR) << "Broken preferences detected while updating a tag."; |
| 262 return; | 272 return; |
| 263 } | 273 } |
| 264 | 274 |
| 265 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, | 275 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, |
| 266 watcher.last_tag); | 276 watcher.last_tag); |
| 267 } | 277 } |
| 268 | 278 |
| 269 } // namespace file_system_provider | 279 } // namespace file_system_provider |
| 270 } // namespace chromeos | 280 } // namespace chromeos |
| OLD | NEW |