Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/registry.cc

Issue 1077823005: Declare providing extension capabilities in the manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed tests. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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";
30 const char kPrefKeySupportsNotifyTag[] = "supports-notify-tag"; 29 const char kPrefKeySupportsNotifyTag[] = "supports-notify-tag";
31 const char kPrefKeyWatchers[] = "watchers"; 30 const char kPrefKeyWatchers[] = "watchers";
32 const char kPrefKeyWatcherEntryPath[] = "entry-path"; 31 const char kPrefKeyWatcherEntryPath[] = "entry-path";
33 const char kPrefKeyWatcherRecursive[] = "recursive"; 32 const char kPrefKeyWatcherRecursive[] = "recursive";
34 const char kPrefKeyWatcherLastTag[] = "last-tag"; 33 const char kPrefKeyWatcherLastTag[] = "last-tag";
35 const char kPrefKeyWatcherPersistentOrigins[] = "persistent-origins"; 34 const char kPrefKeyWatcherPersistentOrigins[] = "persistent-origins";
36 const char kPrefKeyOpenedFilesLimit[] = "opened-files-limit"; 35 const char kPrefKeyOpenedFilesLimit[] = "opened-files-limit";
37 36
38 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 37 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
39 registry->RegisterDictionaryPref(prefs::kFileSystemProviderMounted); 38 registry->RegisterDictionaryPref(prefs::kFileSystemProviderMounted);
40 } 39 }
41 40
42 std::string SourceToString(Source source) {
43 switch (source) {
44 case SOURCE_UNKNOWN:
45 return "unknown";
46 case SOURCE_FILE:
47 return "file";
48 case SOURCE_DEVICE:
49 return "device";
50 case SOURCE_NETWORK:
51 return "network";
52 }
53 NOTREACHED();
54 return std::string();
55 }
56
57 bool StringToSource(const std::string& source, Source* result) {
58 if (source.compare("unknown") == 0) {
59 *result = SOURCE_UNKNOWN;
60 return true;
61 }
62 if (source.compare("file") == 0) {
63 *result = SOURCE_FILE;
64 return true;
65 }
66 if (source.compare("device") == 0) {
67 *result = SOURCE_DEVICE;
68 return true;
69 }
70 if (source.compare("network") == 0) {
71 *result = SOURCE_NETWORK;
72 return true;
73 }
74 return false;
75 }
76
77 Registry::Registry(Profile* profile) : profile_(profile) { 41 Registry::Registry(Profile* profile) : profile_(profile) {
78 } 42 }
79 43
80 Registry::~Registry() { 44 Registry::~Registry() {
81 } 45 }
82 46
83 void Registry::RememberFileSystem( 47 void Registry::RememberFileSystem(
84 const ProvidedFileSystemInfo& file_system_info, 48 const ProvidedFileSystemInfo& file_system_info,
85 const Watchers& watchers) { 49 const Watchers& watchers) {
86 base::DictionaryValue* const file_system = new base::DictionaryValue(); 50 base::DictionaryValue* const file_system = new base::DictionaryValue();
87 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, 51 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId,
88 file_system_info.file_system_id()); 52 file_system_info.file_system_id());
89 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, 53 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName,
90 file_system_info.display_name()); 54 file_system_info.display_name());
91 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, 55 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable,
92 file_system_info.writable()); 56 file_system_info.writable());
93 file_system->SetStringWithoutPathExpansion(
94 kPrefKeySource, SourceToString(file_system_info.source()));
95 file_system->SetBooleanWithoutPathExpansion( 57 file_system->SetBooleanWithoutPathExpansion(
96 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); 58 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag());
97 file_system->SetIntegerWithoutPathExpansion( 59 file_system->SetIntegerWithoutPathExpansion(
98 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit()); 60 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit());
99 61
100 base::DictionaryValue* const watchers_value = new base::DictionaryValue(); 62 base::DictionaryValue* const watchers_value = new base::DictionaryValue();
101 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value); 63 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value);
102 64
103 for (const auto& it : watchers) { 65 for (const auto& it : watchers) {
104 base::DictionaryValue* const watcher = new base::DictionaryValue(); 66 base::DictionaryValue* const watcher = new base::DictionaryValue();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 const base::DictionaryValue* file_system = NULL; 144 const base::DictionaryValue* file_system = NULL;
183 file_systems_per_extension->GetWithoutPathExpansion(it.key(), 145 file_systems_per_extension->GetWithoutPathExpansion(it.key(),
184 &file_system_value); 146 &file_system_value);
185 DCHECK(file_system_value); 147 DCHECK(file_system_value);
186 148
187 std::string file_system_id; 149 std::string file_system_id;
188 std::string display_name; 150 std::string display_name;
189 bool writable = false; 151 bool writable = false;
190 bool supports_notify_tag = false; 152 bool supports_notify_tag = false;
191 int opened_files_limit = 0; 153 int opened_files_limit = 0;
192 std::string source_as_string;
193 Source source = SOURCE_UNKNOWN;
194 154
195 // TODO(mtomasz): Move opened files limit to the mandatory list above in 155 // TODO(mtomasz): Move opened files limit to the mandatory list above in
196 // M42. 156 // M42.
197 if ((!file_system_value->GetAsDictionary(&file_system) || 157 if ((!file_system_value->GetAsDictionary(&file_system) ||
198 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, 158 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId,
199 &file_system_id) || 159 &file_system_id) ||
200 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, 160 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName,
201 &display_name) || 161 &display_name) ||
202 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, 162 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable,
203 &writable) || 163 &writable) ||
204 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, 164 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag,
205 &supports_notify_tag) || 165 &supports_notify_tag) ||
206 file_system_id.empty() || display_name.empty()) || 166 file_system_id.empty() || display_name.empty()) ||
207 // Optional fields. 167 // Optional fields.
208 (file_system->GetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, 168 (file_system->GetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit,
209 &opened_files_limit) && 169 &opened_files_limit) &&
210 (file_system->GetStringWithoutPathExpansion(kPrefKeySource, 170 opened_files_limit < 0)) {
211 &source_as_string) &&
212 !StringToSource(source_as_string, &source)))) {
213 LOG(ERROR) 171 LOG(ERROR)
214 << "Malformed provided file system information in preferences."; 172 << "Malformed provided file system information in preferences.";
215 continue; 173 continue;
216 } 174 }
217 175
218 MountOptions options; 176 MountOptions options;
219 options.file_system_id = file_system_id; 177 options.file_system_id = file_system_id;
220 options.display_name = display_name; 178 options.display_name = display_name;
221 options.writable = writable; 179 options.writable = writable;
222 options.source = source;
223 options.supports_notify_tag = supports_notify_tag; 180 options.supports_notify_tag = supports_notify_tag;
224 options.opened_files_limit = opened_files_limit; 181 options.opened_files_limit = opened_files_limit;
225 182
226 RestoredFileSystem restored_file_system; 183 RestoredFileSystem restored_file_system;
227 restored_file_system.extension_id = extension_id; 184 restored_file_system.extension_id = extension_id;
228 restored_file_system.options = options; 185 restored_file_system.options = options;
229 186
230 // Restore watchers. It's optional, since this field is new. 187 // Restore watchers. It's optional, since this field is new.
231 const base::DictionaryValue* watchers = NULL; 188 const base::DictionaryValue* watchers = NULL;
232 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, 189 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 LOG(ERROR) << "Broken preferences detected while updating a tag."; 270 LOG(ERROR) << "Broken preferences detected while updating a tag.";
314 return; 271 return;
315 } 272 }
316 273
317 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, 274 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag,
318 watcher.last_tag); 275 watcher.last_tag);
319 } 276 }
320 277
321 } // namespace file_system_provider 278 } // namespace file_system_provider
322 } // namespace chromeos 279 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698