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

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. Created 5 years, 8 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( 38 registry->RegisterDictionaryPref(
40 prefs::kFileSystemProviderMounted, 39 prefs::kFileSystemProviderMounted,
41 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 40 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
42 } 41 }
43 42
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
79 Registry::Registry(Profile* profile) : profile_(profile) { 43 Registry::Registry(Profile* profile) : profile_(profile) {
80 } 44 }
81 45
82 Registry::~Registry() { 46 Registry::~Registry() {
83 } 47 }
84 48
85 void Registry::RememberFileSystem( 49 void Registry::RememberFileSystem(
86 const ProvidedFileSystemInfo& file_system_info, 50 const ProvidedFileSystemInfo& file_system_info,
87 const Watchers& watchers) { 51 const Watchers& watchers) {
88 base::DictionaryValue* const file_system = new base::DictionaryValue(); 52 base::DictionaryValue* const file_system = new base::DictionaryValue();
89 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, 53 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId,
90 file_system_info.file_system_id()); 54 file_system_info.file_system_id());
91 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, 55 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName,
92 file_system_info.display_name()); 56 file_system_info.display_name());
93 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, 57 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable,
94 file_system_info.writable()); 58 file_system_info.writable());
95 file_system->SetStringWithoutPathExpansion(
96 kPrefKeySource, SourceToString(file_system_info.source()));
97 file_system->SetBooleanWithoutPathExpansion( 59 file_system->SetBooleanWithoutPathExpansion(
98 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag()); 60 kPrefKeySupportsNotifyTag, file_system_info.supports_notify_tag());
99 file_system->SetIntegerWithoutPathExpansion( 61 file_system->SetIntegerWithoutPathExpansion(
100 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit()); 62 kPrefKeyOpenedFilesLimit, file_system_info.opened_files_limit());
101 63
102 base::DictionaryValue* const watchers_value = new base::DictionaryValue(); 64 base::DictionaryValue* const watchers_value = new base::DictionaryValue();
103 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value); 65 file_system->SetWithoutPathExpansion(kPrefKeyWatchers, watchers_value);
104 66
105 for (const auto& it : watchers) { 67 for (const auto& it : watchers) {
106 base::DictionaryValue* const watcher = new base::DictionaryValue(); 68 base::DictionaryValue* const watcher = new base::DictionaryValue();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 const base::DictionaryValue* file_system = NULL; 146 const base::DictionaryValue* file_system = NULL;
185 file_systems_per_extension->GetWithoutPathExpansion(it.key(), 147 file_systems_per_extension->GetWithoutPathExpansion(it.key(),
186 &file_system_value); 148 &file_system_value);
187 DCHECK(file_system_value); 149 DCHECK(file_system_value);
188 150
189 std::string file_system_id; 151 std::string file_system_id;
190 std::string display_name; 152 std::string display_name;
191 bool writable = false; 153 bool writable = false;
192 bool supports_notify_tag = false; 154 bool supports_notify_tag = false;
193 int opened_files_limit = 0; 155 int opened_files_limit = 0;
194 std::string source_as_string;
195 Source source = SOURCE_UNKNOWN;
196 156
197 // TODO(mtomasz): Move opened files limit to the mandatory list above in 157 // TODO(mtomasz): Move opened files limit to the mandatory list above in
198 // M42. 158 // M42.
199 if ((!file_system_value->GetAsDictionary(&file_system) || 159 if ((!file_system_value->GetAsDictionary(&file_system) ||
200 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, 160 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId,
201 &file_system_id) || 161 &file_system_id) ||
202 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, 162 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName,
203 &display_name) || 163 &display_name) ||
204 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, 164 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable,
205 &writable) || 165 &writable) ||
206 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag, 166 !file_system->GetBooleanWithoutPathExpansion(kPrefKeySupportsNotifyTag,
207 &supports_notify_tag) || 167 &supports_notify_tag) ||
208 file_system_id.empty() || display_name.empty()) || 168 file_system_id.empty() || display_name.empty()) ||
209 // Optional fields. 169 // Optional fields.
210 (file_system->GetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit, 170 (file_system->GetIntegerWithoutPathExpansion(kPrefKeyOpenedFilesLimit,
211 &opened_files_limit) && 171 &opened_files_limit))) {
212 (file_system->GetStringWithoutPathExpansion(kPrefKeySource,
213 &source_as_string) &&
214 !StringToSource(source_as_string, &source)))) {
215 LOG(ERROR) 172 LOG(ERROR)
216 << "Malformed provided file system information in preferences."; 173 << "Malformed provided file system information in preferences.";
217 continue; 174 continue;
218 } 175 }
219 176
220 MountOptions options; 177 MountOptions options;
221 options.file_system_id = file_system_id; 178 options.file_system_id = file_system_id;
222 options.display_name = display_name; 179 options.display_name = display_name;
223 options.writable = writable; 180 options.writable = writable;
224 options.source = source;
225 options.supports_notify_tag = supports_notify_tag; 181 options.supports_notify_tag = supports_notify_tag;
226 options.opened_files_limit = opened_files_limit; 182 options.opened_files_limit = opened_files_limit;
227 183
228 RestoredFileSystem restored_file_system; 184 RestoredFileSystem restored_file_system;
229 restored_file_system.extension_id = extension_id; 185 restored_file_system.extension_id = extension_id;
230 restored_file_system.options = options; 186 restored_file_system.options = options;
231 187
232 // Restore watchers. It's optional, since this field is new. 188 // Restore watchers. It's optional, since this field is new.
233 const base::DictionaryValue* watchers = NULL; 189 const base::DictionaryValue* watchers = NULL;
234 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers, 190 if (file_system->GetDictionaryWithoutPathExpansion(kPrefKeyWatchers,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 LOG(ERROR) << "Broken preferences detected while updating a tag."; 271 LOG(ERROR) << "Broken preferences detected while updating a tag.";
316 return; 272 return;
317 } 273 }
318 274
319 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag, 275 watcher_value->SetStringWithoutPathExpansion(kPrefKeyWatcherLastTag,
320 watcher.last_tag); 276 watcher.last_tag);
321 } 277 }
322 278
323 } // namespace file_system_provider 279 } // namespace file_system_provider
324 } // namespace chromeos 280 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698