| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 121 |
| 122 base::File::Error Service::MountFileSystemInternal( | 122 base::File::Error Service::MountFileSystemInternal( |
| 123 const std::string& extension_id, | 123 const std::string& extension_id, |
| 124 const MountOptions& options, | 124 const MountOptions& options, |
| 125 MountContext context) { | 125 MountContext context) { |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
| 127 | 127 |
| 128 // If already exists a file system provided by the same extension with this | 128 // If already exists a file system provided by the same extension with this |
| 129 // id, then abort. | 129 // id, then abort. |
| 130 if (GetProvidedFileSystem(extension_id, options.file_system_id)) { | 130 if (GetProvidedFileSystem(extension_id, options.file_system_id)) { |
| 131 FOR_EACH_OBSERVER( | 131 for (auto& observer : observers_) { |
| 132 Observer, observers_, | 132 observer.OnProvidedFileSystemMount(ProvidedFileSystemInfo(), context, |
| 133 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), context, | 133 base::File::FILE_ERROR_EXISTS); |
| 134 base::File::FILE_ERROR_EXISTS)); | 134 } |
| 135 return base::File::FILE_ERROR_EXISTS; | 135 return base::File::FILE_ERROR_EXISTS; |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Restrict number of file systems to prevent system abusing. | 138 // Restrict number of file systems to prevent system abusing. |
| 139 if (file_system_map_.size() + 1 > kMaxFileSystems) { | 139 if (file_system_map_.size() + 1 > kMaxFileSystems) { |
| 140 FOR_EACH_OBSERVER( | 140 for (auto& observer : observers_) { |
| 141 Observer, observers_, | 141 observer.OnProvidedFileSystemMount( |
| 142 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), context, | 142 ProvidedFileSystemInfo(), context, |
| 143 base::File::FILE_ERROR_TOO_MANY_OPENED)); | 143 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 144 } |
| 144 return base::File::FILE_ERROR_TOO_MANY_OPENED; | 145 return base::File::FILE_ERROR_TOO_MANY_OPENED; |
| 145 } | 146 } |
| 146 | 147 |
| 147 storage::ExternalMountPoints* const mount_points = | 148 storage::ExternalMountPoints* const mount_points = |
| 148 storage::ExternalMountPoints::GetSystemInstance(); | 149 storage::ExternalMountPoints::GetSystemInstance(); |
| 149 DCHECK(mount_points); | 150 DCHECK(mount_points); |
| 150 | 151 |
| 151 // The mount point path and name are unique per system, since they are system | 152 // The mount point path and name are unique per system, since they are system |
| 152 // wide. This is necessary for copying between profiles. | 153 // wide. This is necessary for copying between profiles. |
| 153 const base::FilePath& mount_path = | 154 const base::FilePath& mount_path = |
| 154 util::GetMountPath(profile_, extension_id, options.file_system_id); | 155 util::GetMountPath(profile_, extension_id, options.file_system_id); |
| 155 const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); | 156 const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); |
| 156 | 157 |
| 157 if (!mount_points->RegisterFileSystem( | 158 if (!mount_points->RegisterFileSystem( |
| 158 mount_point_name, storage::kFileSystemTypeProvided, | 159 mount_point_name, storage::kFileSystemTypeProvided, |
| 159 storage::FileSystemMountOption( | 160 storage::FileSystemMountOption( |
| 160 storage::FlushPolicy::FLUSH_ON_COMPLETION), | 161 storage::FlushPolicy::FLUSH_ON_COMPLETION), |
| 161 mount_path)) { | 162 mount_path)) { |
| 162 FOR_EACH_OBSERVER( | 163 for (auto& observer : observers_) { |
| 163 Observer, observers_, | 164 observer.OnProvidedFileSystemMount( |
| 164 OnProvidedFileSystemMount(ProvidedFileSystemInfo(), context, | 165 ProvidedFileSystemInfo(), context, |
| 165 base::File::FILE_ERROR_INVALID_OPERATION)); | 166 base::File::FILE_ERROR_INVALID_OPERATION); |
| 167 } |
| 166 return base::File::FILE_ERROR_INVALID_OPERATION; | 168 return base::File::FILE_ERROR_INVALID_OPERATION; |
| 167 } | 169 } |
| 168 | 170 |
| 169 ProvidingExtensionInfo provider_info; | 171 ProvidingExtensionInfo provider_info; |
| 170 // TODO(mtomasz): Set up a testing extension in unit tests. | 172 // TODO(mtomasz): Set up a testing extension in unit tests. |
| 171 GetProvidingExtensionInfo(extension_id, &provider_info); | 173 GetProvidingExtensionInfo(extension_id, &provider_info); |
| 172 // Store the file system descriptor. Use the mount point name as the file | 174 // Store the file system descriptor. Use the mount point name as the file |
| 173 // system provider file system id. | 175 // system provider file system id. |
| 174 // Examples: | 176 // Examples: |
| 175 // file_system_id = hello_world | 177 // file_system_id = hello_world |
| (...skipping 12 matching lines...) Expand all Loading... |
| 188 | 190 |
| 189 ProvidedFileSystemInterface* file_system = | 191 ProvidedFileSystemInterface* file_system = |
| 190 file_system_factory_.Run(profile_, file_system_info); | 192 file_system_factory_.Run(profile_, file_system_info); |
| 191 DCHECK(file_system); | 193 DCHECK(file_system); |
| 192 file_system_map_[FileSystemKey(extension_id, options.file_system_id)] = | 194 file_system_map_[FileSystemKey(extension_id, options.file_system_id)] = |
| 193 file_system; | 195 file_system; |
| 194 mount_point_name_to_key_map_[mount_point_name] = | 196 mount_point_name_to_key_map_[mount_point_name] = |
| 195 FileSystemKey(extension_id, options.file_system_id); | 197 FileSystemKey(extension_id, options.file_system_id); |
| 196 registry_->RememberFileSystem(file_system_info, *file_system->GetWatchers()); | 198 registry_->RememberFileSystem(file_system_info, *file_system->GetWatchers()); |
| 197 | 199 |
| 198 FOR_EACH_OBSERVER(Observer, observers_, | 200 for (auto& observer : observers_) { |
| 199 OnProvidedFileSystemMount(file_system_info, context, | 201 observer.OnProvidedFileSystemMount(file_system_info, context, |
| 200 base::File::FILE_OK)); | 202 base::File::FILE_OK); |
| 203 } |
| 201 | 204 |
| 202 return base::File::FILE_OK; | 205 return base::File::FILE_OK; |
| 203 } | 206 } |
| 204 | 207 |
| 205 base::File::Error Service::UnmountFileSystem(const std::string& extension_id, | 208 base::File::Error Service::UnmountFileSystem(const std::string& extension_id, |
| 206 const std::string& file_system_id, | 209 const std::string& file_system_id, |
| 207 UnmountReason reason) { | 210 UnmountReason reason) { |
| 208 DCHECK(thread_checker_.CalledOnValidThread()); | 211 DCHECK(thread_checker_.CalledOnValidThread()); |
| 209 | 212 |
| 210 const ProvidedFileSystemMap::iterator file_system_it = | 213 const ProvidedFileSystemMap::iterator file_system_it = |
| 211 file_system_map_.find(FileSystemKey(extension_id, file_system_id)); | 214 file_system_map_.find(FileSystemKey(extension_id, file_system_id)); |
| 212 if (file_system_it == file_system_map_.end()) { | 215 if (file_system_it == file_system_map_.end()) { |
| 213 const ProvidedFileSystemInfo empty_file_system_info; | 216 const ProvidedFileSystemInfo empty_file_system_info; |
| 214 FOR_EACH_OBSERVER( | 217 for (auto& observer : observers_) { |
| 215 Observer, | 218 observer.OnProvidedFileSystemUnmount(empty_file_system_info, |
| 216 observers_, | 219 base::File::FILE_ERROR_NOT_FOUND); |
| 217 OnProvidedFileSystemUnmount(empty_file_system_info, | 220 } |
| 218 base::File::FILE_ERROR_NOT_FOUND)); | |
| 219 return base::File::FILE_ERROR_NOT_FOUND; | 221 return base::File::FILE_ERROR_NOT_FOUND; |
| 220 } | 222 } |
| 221 | 223 |
| 222 storage::ExternalMountPoints* const mount_points = | 224 storage::ExternalMountPoints* const mount_points = |
| 223 storage::ExternalMountPoints::GetSystemInstance(); | 225 storage::ExternalMountPoints::GetSystemInstance(); |
| 224 DCHECK(mount_points); | 226 DCHECK(mount_points); |
| 225 | 227 |
| 226 const ProvidedFileSystemInfo& file_system_info = | 228 const ProvidedFileSystemInfo& file_system_info = |
| 227 file_system_it->second->GetFileSystemInfo(); | 229 file_system_it->second->GetFileSystemInfo(); |
| 228 | 230 |
| 229 const std::string mount_point_name = | 231 const std::string mount_point_name = |
| 230 file_system_info.mount_path().BaseName().value(); | 232 file_system_info.mount_path().BaseName().value(); |
| 231 if (!mount_points->RevokeFileSystem(mount_point_name)) { | 233 if (!mount_points->RevokeFileSystem(mount_point_name)) { |
| 232 FOR_EACH_OBSERVER( | 234 for (auto& observer : observers_) { |
| 233 Observer, | 235 observer.OnProvidedFileSystemUnmount( |
| 234 observers_, | 236 file_system_info, base::File::FILE_ERROR_INVALID_OPERATION); |
| 235 OnProvidedFileSystemUnmount(file_system_info, | 237 } |
| 236 base::File::FILE_ERROR_INVALID_OPERATION)); | |
| 237 return base::File::FILE_ERROR_INVALID_OPERATION; | 238 return base::File::FILE_ERROR_INVALID_OPERATION; |
| 238 } | 239 } |
| 239 | 240 |
| 240 FOR_EACH_OBSERVER( | 241 for (auto& observer : observers_) |
| 241 Observer, | 242 observer.OnProvidedFileSystemUnmount(file_system_info, base::File::FILE_OK); |
| 242 observers_, | |
| 243 OnProvidedFileSystemUnmount(file_system_info, base::File::FILE_OK)); | |
| 244 | 243 |
| 245 mount_point_name_to_key_map_.erase(mount_point_name); | 244 mount_point_name_to_key_map_.erase(mount_point_name); |
| 246 | 245 |
| 247 if (reason == UNMOUNT_REASON_USER) { | 246 if (reason == UNMOUNT_REASON_USER) { |
| 248 registry_->ForgetFileSystem(file_system_info.extension_id(), | 247 registry_->ForgetFileSystem(file_system_info.extension_id(), |
| 249 file_system_info.file_system_id()); | 248 file_system_info.file_system_id()); |
| 250 } | 249 } |
| 251 | 250 |
| 252 delete file_system_it->second; | 251 delete file_system_it->second; |
| 253 file_system_map_.erase(file_system_it); | 252 file_system_map_.erase(file_system_it); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 return file_system_it->second; | 429 return file_system_it->second; |
| 431 } | 430 } |
| 432 | 431 |
| 433 void Service::OnRequestUnmountStatus( | 432 void Service::OnRequestUnmountStatus( |
| 434 const ProvidedFileSystemInfo& file_system_info, | 433 const ProvidedFileSystemInfo& file_system_info, |
| 435 base::File::Error error) { | 434 base::File::Error error) { |
| 436 // Notify observers about failure in unmounting, since mount() will not be | 435 // Notify observers about failure in unmounting, since mount() will not be |
| 437 // called by the provided file system. In case of success mount() will be | 436 // called by the provided file system. In case of success mount() will be |
| 438 // invoked, and observers notified, so there is no need to call them now. | 437 // invoked, and observers notified, so there is no need to call them now. |
| 439 if (error != base::File::FILE_OK) { | 438 if (error != base::File::FILE_OK) { |
| 440 FOR_EACH_OBSERVER(Observer, | 439 for (auto& observer : observers_) |
| 441 observers_, | 440 observer.OnProvidedFileSystemUnmount(file_system_info, error); |
| 442 OnProvidedFileSystemUnmount(file_system_info, error)); | |
| 443 } | 441 } |
| 444 } | 442 } |
| 445 | 443 |
| 446 void Service::OnWatcherChanged(const ProvidedFileSystemInfo& file_system_info, | 444 void Service::OnWatcherChanged(const ProvidedFileSystemInfo& file_system_info, |
| 447 const Watcher& watcher, | 445 const Watcher& watcher, |
| 448 storage::WatcherManager::ChangeType change_type, | 446 storage::WatcherManager::ChangeType change_type, |
| 449 const Changes& changes, | 447 const Changes& changes, |
| 450 const base::Closure& callback) { | 448 const base::Closure& callback) { |
| 451 callback.Run(); | 449 callback.Run(); |
| 452 } | 450 } |
| 453 | 451 |
| 454 void Service::OnWatcherTagUpdated( | 452 void Service::OnWatcherTagUpdated( |
| 455 const ProvidedFileSystemInfo& file_system_info, | 453 const ProvidedFileSystemInfo& file_system_info, |
| 456 const Watcher& watcher) { | 454 const Watcher& watcher) { |
| 457 PrefService* const pref_service = profile_->GetPrefs(); | 455 PrefService* const pref_service = profile_->GetPrefs(); |
| 458 DCHECK(pref_service); | 456 DCHECK(pref_service); |
| 459 | 457 |
| 460 registry_->UpdateWatcherTag(file_system_info, watcher); | 458 registry_->UpdateWatcherTag(file_system_info, watcher); |
| 461 } | 459 } |
| 462 | 460 |
| 463 void Service::OnWatcherListChanged( | 461 void Service::OnWatcherListChanged( |
| 464 const ProvidedFileSystemInfo& file_system_info, | 462 const ProvidedFileSystemInfo& file_system_info, |
| 465 const Watchers& watchers) { | 463 const Watchers& watchers) { |
| 466 registry_->RememberFileSystem(file_system_info, watchers); | 464 registry_->RememberFileSystem(file_system_info, watchers); |
| 467 } | 465 } |
| 468 | 466 |
| 469 } // namespace file_system_provider | 467 } // namespace file_system_provider |
| 470 } // namespace chromeos | 468 } // namespace chromeos |
| OLD | NEW |