| 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 20 matching lines...) Expand all Loading... |
| 31 ProvidedFileSystemInterface* CreateProvidedFileSystem( | 31 ProvidedFileSystemInterface* CreateProvidedFileSystem( |
| 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 kPrefKeyFileSystemName[] = "file-system-name"; | 41 const char kPrefKeyDisplayName[] = "display-name"; |
| 42 | 42 |
| 43 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 43 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 44 registry->RegisterDictionaryPref( | 44 registry->RegisterDictionaryPref( |
| 45 prefs::kFileSystemProviderMounted, | 45 prefs::kFileSystemProviderMounted, |
| 46 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 46 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 47 } | 47 } |
| 48 | 48 |
| 49 Service::Service(Profile* profile, | 49 Service::Service(Profile* profile, |
| 50 extensions::ExtensionRegistry* extension_registry) | 50 extensions::ExtensionRegistry* extension_registry) |
| 51 : profile_(profile), | 51 : profile_(profile), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 void Service::SetFileSystemFactoryForTesting( | 92 void Service::SetFileSystemFactoryForTesting( |
| 93 const FileSystemFactoryCallback& factory_callback) { | 93 const FileSystemFactoryCallback& factory_callback) { |
| 94 DCHECK(!factory_callback.is_null()); | 94 DCHECK(!factory_callback.is_null()); |
| 95 file_system_factory_ = factory_callback; | 95 file_system_factory_ = factory_callback; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool Service::MountFileSystem(const std::string& extension_id, | 98 bool Service::MountFileSystem(const std::string& extension_id, |
| 99 const std::string& file_system_id, | 99 const std::string& file_system_id, |
| 100 const std::string& file_system_name) { | 100 const std::string& display_name) { |
| 101 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
| 102 | 102 |
| 103 // If already exists a file system provided by the same extension with this | 103 // If already exists a file system provided by the same extension with this |
| 104 // id, then abort. | 104 // id, then abort. |
| 105 if (GetProvidedFileSystem(extension_id, file_system_id)) { | 105 if (GetProvidedFileSystem(extension_id, file_system_id)) { |
| 106 FOR_EACH_OBSERVER(Observer, | 106 FOR_EACH_OBSERVER(Observer, |
| 107 observers_, | 107 observers_, |
| 108 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 108 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
| 109 base::File::FILE_ERROR_EXISTS)); | 109 base::File::FILE_ERROR_EXISTS)); |
| 110 return false; | 110 return false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Store the file system descriptor. Use the mount point name as the file | 145 // Store the file system descriptor. Use the mount point name as the file |
| 146 // system provider file system id. | 146 // system provider file system id. |
| 147 // Examples: | 147 // Examples: |
| 148 // file_system_id = 41 | 148 // file_system_id = 41 |
| 149 // mount_point_name = b33f1337-41-5aa5 | 149 // mount_point_name = b33f1337-41-5aa5 |
| 150 // mount_path = /provided/b33f1337-41-5aa5 | 150 // mount_path = /provided/b33f1337-41-5aa5 |
| 151 ProvidedFileSystemInfo file_system_info( | 151 ProvidedFileSystemInfo file_system_info( |
| 152 extension_id, file_system_id, file_system_name, mount_path); | 152 extension_id, file_system_id, display_name, mount_path); |
| 153 | 153 |
| 154 ProvidedFileSystemInterface* file_system = | 154 ProvidedFileSystemInterface* file_system = |
| 155 file_system_factory_.Run(profile_, file_system_info); | 155 file_system_factory_.Run(profile_, file_system_info); |
| 156 DCHECK(file_system); | 156 DCHECK(file_system); |
| 157 file_system_map_[FileSystemKey(extension_id, file_system_id)] = file_system; | 157 file_system_map_[FileSystemKey(extension_id, file_system_id)] = file_system; |
| 158 mount_point_name_to_key_map_[mount_point_name] = | 158 mount_point_name_to_key_map_[mount_point_name] = |
| 159 FileSystemKey(extension_id, file_system_id); | 159 FileSystemKey(extension_id, file_system_id); |
| 160 | 160 |
| 161 FOR_EACH_OBSERVER( | 161 FOR_EACH_OBSERVER( |
| 162 Observer, | 162 Observer, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 it != file_system_info_list.end(); | 324 it != file_system_info_list.end(); |
| 325 ++it) { | 325 ++it) { |
| 326 base::ListValue* file_systems = NULL; | 326 base::ListValue* file_systems = NULL; |
| 327 if (!extensions.GetList(it->extension_id(), &file_systems)) { | 327 if (!extensions.GetList(it->extension_id(), &file_systems)) { |
| 328 file_systems = new base::ListValue(); | 328 file_systems = new base::ListValue(); |
| 329 extensions.Set(it->extension_id(), file_systems); | 329 extensions.Set(it->extension_id(), file_systems); |
| 330 } | 330 } |
| 331 | 331 |
| 332 base::DictionaryValue* file_system = new base::DictionaryValue(); | 332 base::DictionaryValue* file_system = new base::DictionaryValue(); |
| 333 file_system->SetString(kPrefKeyFileSystemId, it->file_system_id()); | 333 file_system->SetString(kPrefKeyFileSystemId, it->file_system_id()); |
| 334 file_system->SetString(kPrefKeyFileSystemName, it->file_system_name()); | 334 file_system->SetString(kPrefKeyDisplayName, it->display_name()); |
| 335 file_systems->Append(file_system); | 335 file_systems->Append(file_system); |
| 336 } | 336 } |
| 337 | 337 |
| 338 PrefService* pref_service = profile_->GetPrefs(); | 338 PrefService* pref_service = profile_->GetPrefs(); |
| 339 DCHECK(pref_service); | 339 DCHECK(pref_service); |
| 340 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); | 340 pref_service->Set(prefs::kFileSystemProviderMounted, extensions); |
| 341 pref_service->CommitPendingWrite(); | 341 pref_service->CommitPendingWrite(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 void Service::ForgetFileSystems(const std::string& extension_id) { | 344 void Service::ForgetFileSystems(const std::string& extension_id) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 367 | 367 |
| 368 for (size_t i = 0; i < file_systems->GetSize(); ++i) { | 368 for (size_t i = 0; i < file_systems->GetSize(); ++i) { |
| 369 const base::DictionaryValue* file_system = NULL; | 369 const base::DictionaryValue* file_system = NULL; |
| 370 file_systems->GetDictionary(i, &file_system); | 370 file_systems->GetDictionary(i, &file_system); |
| 371 DCHECK(file_system); | 371 DCHECK(file_system); |
| 372 | 372 |
| 373 std::string file_system_id; | 373 std::string file_system_id; |
| 374 file_system->GetString(kPrefKeyFileSystemId, &file_system_id); | 374 file_system->GetString(kPrefKeyFileSystemId, &file_system_id); |
| 375 DCHECK(!file_system_id.empty()); | 375 DCHECK(!file_system_id.empty()); |
| 376 | 376 |
| 377 std::string file_system_name; | 377 std::string display_name; |
| 378 file_system->GetString(kPrefKeyFileSystemName, &file_system_name); | 378 file_system->GetString(kPrefKeyDisplayName, &display_name); |
| 379 DCHECK(!file_system_name.empty()); | 379 DCHECK(!display_name.empty()); |
| 380 | 380 |
| 381 if (file_system_id.empty() || file_system_name.empty()) { | 381 if (file_system_id.empty() || display_name.empty()) { |
| 382 LOG(ERROR) | 382 LOG(ERROR) |
| 383 << "Malformed provided file system information in preferences."; | 383 << "Malformed provided file system information in preferences."; |
| 384 continue; | 384 continue; |
| 385 } | 385 } |
| 386 | 386 |
| 387 const bool result = | 387 const bool result = |
| 388 MountFileSystem(extension_id, file_system_id, file_system_name); | 388 MountFileSystem(extension_id, file_system_id, display_name); |
| 389 if (!result) { | 389 if (!result) { |
| 390 LOG(ERROR) << "Failed to restore a provided file system from " | 390 LOG(ERROR) << "Failed to restore a provided file system from " |
| 391 << "preferences: " << extension_id << ", " << file_system_id | 391 << "preferences: " << extension_id << ", " << file_system_id |
| 392 << ", " << file_system_name << "."; | 392 << ", " << display_name << "."; |
| 393 } | 393 } |
| 394 } | 394 } |
| 395 } | 395 } |
| 396 | 396 |
| 397 } // namespace file_system_provider | 397 } // namespace file_system_provider |
| 398 } // namespace chromeos | 398 } // namespace chromeos |
| OLD | NEW |