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/service.h" | 5 #include "chrome/browser/chromeos/file_system_provider/service.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 21 matching lines...) Expand all Loading... |
32 Profile* profile, | 32 Profile* profile, |
33 const ProvidedFileSystemInfo& file_system_info) { | 33 const ProvidedFileSystemInfo& file_system_info) { |
34 DCHECK(profile); | 34 DCHECK(profile); |
35 return new ProvidedFileSystem(profile, file_system_info); | 35 return new ProvidedFileSystem(profile, file_system_info); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 const char kPrefKeyFileSystemId[] = "file-system-id"; | 40 const char kPrefKeyFileSystemId[] = "file-system-id"; |
41 const char kPrefKeyDisplayName[] = "display-name"; | 41 const char kPrefKeyDisplayName[] = "display-name"; |
| 42 const char kPrefKeyWritable[] = "writable"; |
42 | 43 |
43 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 44 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
44 registry->RegisterDictionaryPref( | 45 registry->RegisterDictionaryPref( |
45 prefs::kFileSystemProviderMounted, | 46 prefs::kFileSystemProviderMounted, |
46 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 47 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
47 } | 48 } |
48 | 49 |
49 Service::Service(Profile* profile, | 50 Service::Service(Profile* profile, |
50 extensions::ExtensionRegistry* extension_registry) | 51 extensions::ExtensionRegistry* extension_registry) |
51 : profile_(profile), | 52 : profile_(profile), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 95 } |
95 | 96 |
96 void Service::SetFileSystemFactoryForTesting( | 97 void Service::SetFileSystemFactoryForTesting( |
97 const FileSystemFactoryCallback& factory_callback) { | 98 const FileSystemFactoryCallback& factory_callback) { |
98 DCHECK(!factory_callback.is_null()); | 99 DCHECK(!factory_callback.is_null()); |
99 file_system_factory_ = factory_callback; | 100 file_system_factory_ = factory_callback; |
100 } | 101 } |
101 | 102 |
102 bool Service::MountFileSystem(const std::string& extension_id, | 103 bool Service::MountFileSystem(const std::string& extension_id, |
103 const std::string& file_system_id, | 104 const std::string& file_system_id, |
104 const std::string& display_name) { | 105 const std::string& display_name, |
| 106 bool writable) { |
105 DCHECK(thread_checker_.CalledOnValidThread()); | 107 DCHECK(thread_checker_.CalledOnValidThread()); |
106 | 108 |
107 // If already exists a file system provided by the same extension with this | 109 // If already exists a file system provided by the same extension with this |
108 // id, then abort. | 110 // id, then abort. |
109 if (GetProvidedFileSystem(extension_id, file_system_id)) { | 111 if (GetProvidedFileSystem(extension_id, file_system_id)) { |
110 FOR_EACH_OBSERVER(Observer, | 112 FOR_EACH_OBSERVER(Observer, |
111 observers_, | 113 observers_, |
112 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 114 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
113 base::File::FILE_ERROR_EXISTS)); | 115 base::File::FILE_ERROR_EXISTS)); |
114 return false; | 116 return false; |
(...skipping 27 matching lines...) Expand all Loading... |
142 Observer, | 144 Observer, |
143 observers_, | 145 observers_, |
144 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 146 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
145 base::File::FILE_ERROR_INVALID_OPERATION)); | 147 base::File::FILE_ERROR_INVALID_OPERATION)); |
146 return false; | 148 return false; |
147 } | 149 } |
148 | 150 |
149 // Store the file system descriptor. Use the mount point name as the file | 151 // Store the file system descriptor. Use the mount point name as the file |
150 // system provider file system id. | 152 // system provider file system id. |
151 // Examples: | 153 // Examples: |
152 // file_system_id = 41 | 154 // file_system_id = hello_world |
153 // mount_point_name = b33f1337-41-5aa5 | 155 // mount_point_name = b33f1337-hello_world-5aa5 |
154 // mount_path = /provided/b33f1337-41-5aa5 | 156 // writable = false |
| 157 // mount_path = /provided/b33f1337-hello_world-5aa5 |
155 ProvidedFileSystemInfo file_system_info( | 158 ProvidedFileSystemInfo file_system_info( |
156 extension_id, file_system_id, display_name, mount_path); | 159 extension_id, file_system_id, display_name, writable, mount_path); |
157 | 160 |
158 ProvidedFileSystemInterface* file_system = | 161 ProvidedFileSystemInterface* file_system = |
159 file_system_factory_.Run(profile_, file_system_info); | 162 file_system_factory_.Run(profile_, file_system_info); |
160 DCHECK(file_system); | 163 DCHECK(file_system); |
161 file_system_map_[FileSystemKey(extension_id, file_system_id)] = file_system; | 164 file_system_map_[FileSystemKey(extension_id, file_system_id)] = file_system; |
162 mount_point_name_to_key_map_[mount_point_name] = | 165 mount_point_name_to_key_map_[mount_point_name] = |
163 FileSystemKey(extension_id, file_system_id); | 166 FileSystemKey(extension_id, file_system_id); |
164 RememberFileSystem(file_system_info); | 167 RememberFileSystem(file_system_info); |
165 | 168 |
166 FOR_EACH_OBSERVER( | 169 FOR_EACH_OBSERVER( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 327 } |
325 } | 328 } |
326 | 329 |
327 void Service::RememberFileSystem( | 330 void Service::RememberFileSystem( |
328 const ProvidedFileSystemInfo& file_system_info) { | 331 const ProvidedFileSystemInfo& file_system_info) { |
329 base::DictionaryValue* file_system = new base::DictionaryValue(); | 332 base::DictionaryValue* file_system = new base::DictionaryValue(); |
330 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, | 333 file_system->SetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
331 file_system_info.file_system_id()); | 334 file_system_info.file_system_id()); |
332 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, | 335 file_system->SetStringWithoutPathExpansion(kPrefKeyDisplayName, |
333 file_system_info.display_name()); | 336 file_system_info.display_name()); |
| 337 file_system->SetBooleanWithoutPathExpansion(kPrefKeyWritable, |
| 338 file_system_info.writable()); |
334 | 339 |
335 PrefService* const pref_service = profile_->GetPrefs(); | 340 PrefService* const pref_service = profile_->GetPrefs(); |
336 DCHECK(pref_service); | 341 DCHECK(pref_service); |
337 | 342 |
338 DictionaryPrefUpdate dict_update(pref_service, | 343 DictionaryPrefUpdate dict_update(pref_service, |
339 prefs::kFileSystemProviderMounted); | 344 prefs::kFileSystemProviderMounted); |
340 | 345 |
341 base::DictionaryValue* file_systems_per_extension = NULL; | 346 base::DictionaryValue* file_systems_per_extension = NULL; |
342 if (!dict_update->GetDictionaryWithoutPathExpansion( | 347 if (!dict_update->GetDictionaryWithoutPathExpansion( |
343 file_system_info.extension_id(), &file_systems_per_extension)) { | 348 file_system_info.extension_id(), &file_systems_per_extension)) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 !it.IsAtEnd(); | 395 !it.IsAtEnd(); |
391 it.Advance()) { | 396 it.Advance()) { |
392 const base::Value* file_system_value = NULL; | 397 const base::Value* file_system_value = NULL; |
393 const base::DictionaryValue* file_system = NULL; | 398 const base::DictionaryValue* file_system = NULL; |
394 file_systems_per_extension_copy->GetWithoutPathExpansion( | 399 file_systems_per_extension_copy->GetWithoutPathExpansion( |
395 it.key(), &file_system_value); | 400 it.key(), &file_system_value); |
396 DCHECK(file_system_value); | 401 DCHECK(file_system_value); |
397 | 402 |
398 std::string file_system_id; | 403 std::string file_system_id; |
399 std::string display_name; | 404 std::string display_name; |
400 if (file_system_value->GetAsDictionary(&file_system)) { | 405 bool writable; |
401 file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, | |
402 &file_system_id); | |
403 file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, | |
404 &display_name); | |
405 } | |
406 | 406 |
407 if (file_system_id.empty() || display_name.empty()) { | 407 if (!file_system_value->GetAsDictionary(&file_system) || |
| 408 !file_system->GetStringWithoutPathExpansion(kPrefKeyFileSystemId, |
| 409 &file_system_id) || |
| 410 !file_system->GetStringWithoutPathExpansion(kPrefKeyDisplayName, |
| 411 &display_name) || |
| 412 !file_system->GetBooleanWithoutPathExpansion(kPrefKeyWritable, |
| 413 &writable) || |
| 414 file_system_id.empty() || display_name.empty()) { |
408 LOG(ERROR) | 415 LOG(ERROR) |
409 << "Malformed provided file system information in preferences."; | 416 << "Malformed provided file system information in preferences."; |
410 continue; | 417 continue; |
411 } | 418 } |
412 | 419 |
413 const bool result = | 420 const bool result = |
414 MountFileSystem(extension_id, file_system_id, display_name); | 421 MountFileSystem(extension_id, file_system_id, display_name, writable); |
415 if (!result) { | 422 if (!result) { |
416 LOG(ERROR) << "Failed to restore a provided file system from " | 423 LOG(ERROR) << "Failed to restore a provided file system from " |
417 << "preferences: " << extension_id << ", " << file_system_id | 424 << "preferences: " << extension_id << ", " << file_system_id |
418 << ", " << display_name << "."; | 425 << ", " << display_name << "."; |
419 // Since remounting of the file system failed, then remove it from | 426 // Since remounting of the file system failed, then remove it from |
420 // preferences to avoid remounting it over and over again with a failure. | 427 // preferences to avoid remounting it over and over again with a failure. |
421 ForgetFileSystem(extension_id, file_system_id); | 428 ForgetFileSystem(extension_id, file_system_id); |
422 } | 429 } |
423 } | 430 } |
424 } | 431 } |
425 | 432 |
426 } // namespace file_system_provider | 433 } // namespace file_system_provider |
427 } // namespace chromeos | 434 } // namespace chromeos |
OLD | NEW |