| 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/stl_util.h" |    8 #include "base/stl_util.h" | 
|    9 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |    9 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 
|   10 #include "chrome/browser/chromeos/file_system_provider/observer.h" |   10 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 
|   11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |   11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 
|   12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
     .h" |   12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
     .h" | 
|   13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
     rface.h" |   13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
     rface.h" | 
|   14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" |   14 #include "chrome/browser/chromeos/file_system_provider/service_factory.h" | 
|   15 #include "content/public/browser/browser_thread.h" |   15 #include "content/public/browser/browser_thread.h" | 
|   16 #include "extensions/browser/event_router.h" |   16 #include "extensions/browser/event_router.h" | 
|   17 #include "extensions/browser/extension_registry.h" |   17 #include "extensions/browser/extension_registry.h" | 
|   18 #include "extensions/browser/extension_system.h" |   18 #include "extensions/browser/extension_system.h" | 
|   19 #include "webkit/browser/fileapi/external_mount_points.h" |   19 #include "webkit/browser/fileapi/external_mount_points.h" | 
|   20  |   20  | 
 |   21 using content::BrowserThread; | 
 |   22  | 
|   21 namespace chromeos { |   23 namespace chromeos { | 
|   22 namespace file_system_provider { |   24 namespace file_system_provider { | 
|   23 namespace { |   25 namespace { | 
|   24  |   26  | 
|   25 // Maximum number of file systems to be mounted in the same time, per profile. |   27 // Maximum number of file systems to be mounted in the same time, per profile. | 
|   26 const size_t kMaxFileSystems = 16; |   28 const size_t kMaxFileSystems = 16; | 
|   27  |   29  | 
|   28 // Default factory for provided file systems. The |event_router| must not be |   30 // Default factory for provided file systems. The |event_router| must not be | 
|   29 // NULL. |   31 // NULL. | 
|   30 ProvidedFileSystemInterface* CreateProvidedFileSystem( |   32 ProvidedFileSystemInterface* CreateProvidedFileSystem( | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   78 } |   80 } | 
|   79  |   81  | 
|   80 void Service::SetFileSystemFactoryForTests( |   82 void Service::SetFileSystemFactoryForTests( | 
|   81     const FileSystemFactoryCallback& factory_callback) { |   83     const FileSystemFactoryCallback& factory_callback) { | 
|   82   DCHECK(!factory_callback.is_null()); |   84   DCHECK(!factory_callback.is_null()); | 
|   83   file_system_factory_ = factory_callback; |   85   file_system_factory_ = factory_callback; | 
|   84 } |   86 } | 
|   85  |   87  | 
|   86 int Service::MountFileSystem(const std::string& extension_id, |   88 int Service::MountFileSystem(const std::string& extension_id, | 
|   87                              const std::string& file_system_name) { |   89                              const std::string& file_system_name) { | 
|   88   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |   90   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
|   89  |   91  | 
|   90   // Restrict number of file systems to prevent system abusing. |   92   // Restrict number of file systems to prevent system abusing. | 
|   91   if (file_system_map_.size() + 1 > kMaxFileSystems) { |   93   if (file_system_map_.size() + 1 > kMaxFileSystems) { | 
|   92     FOR_EACH_OBSERVER( |   94     FOR_EACH_OBSERVER( | 
|   93         Observer, |   95         Observer, | 
|   94         observers_, |   96         observers_, | 
|   95         OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |   97         OnProvidedFileSystemMount(ProvidedFileSystemInfo(), | 
|   96                                   base::File::FILE_ERROR_TOO_MANY_OPENED)); |   98                                   base::File::FILE_ERROR_TOO_MANY_OPENED)); | 
|   97     return 0; |   99     return 0; | 
|   98   } |  100   } | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  144       Observer, |  146       Observer, | 
|  145       observers_, |  147       observers_, | 
|  146       OnProvidedFileSystemMount(file_system_info, base::File::FILE_OK)); |  148       OnProvidedFileSystemMount(file_system_info, base::File::FILE_OK)); | 
|  147  |  149  | 
|  148   next_id_++; |  150   next_id_++; | 
|  149   return file_system_id; |  151   return file_system_id; | 
|  150 } |  152 } | 
|  151  |  153  | 
|  152 bool Service::UnmountFileSystem(const std::string& extension_id, |  154 bool Service::UnmountFileSystem(const std::string& extension_id, | 
|  153                                 int file_system_id) { |  155                                 int file_system_id) { | 
|  154   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |  156   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
|  155  |  157  | 
|  156   const ProvidedFileSystemMap::iterator file_system_it = |  158   const ProvidedFileSystemMap::iterator file_system_it = | 
|  157       file_system_map_.find(file_system_id); |  159       file_system_map_.find(file_system_id); | 
|  158   if (file_system_it == file_system_map_.end() || |  160   if (file_system_it == file_system_map_.end() || | 
|  159       file_system_it->second->GetFileSystemInfo().extension_id() != |  161       file_system_it->second->GetFileSystemInfo().extension_id() != | 
|  160           extension_id) { |  162           extension_id) { | 
|  161     const ProvidedFileSystemInfo empty_file_system_info; |  163     const ProvidedFileSystemInfo empty_file_system_info; | 
|  162     FOR_EACH_OBSERVER( |  164     FOR_EACH_OBSERVER( | 
|  163         Observer, |  165         Observer, | 
|  164         observers_, |  166         observers_, | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
|  192  |  194  | 
|  193   mount_point_name_to_id_map_.erase(mount_point_name); |  195   mount_point_name_to_id_map_.erase(mount_point_name); | 
|  194  |  196  | 
|  195   delete file_system_it->second; |  197   delete file_system_it->second; | 
|  196   file_system_map_.erase(file_system_it); |  198   file_system_map_.erase(file_system_it); | 
|  197  |  199  | 
|  198   return true; |  200   return true; | 
|  199 } |  201 } | 
|  200  |  202  | 
|  201 bool Service::RequestUnmount(int file_system_id) { |  203 bool Service::RequestUnmount(int file_system_id) { | 
|  202   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |  204   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
|  203  |  205  | 
|  204   ProvidedFileSystemMap::iterator file_system_it = |  206   ProvidedFileSystemMap::iterator file_system_it = | 
|  205       file_system_map_.find(file_system_id); |  207       file_system_map_.find(file_system_id); | 
|  206   if (file_system_it == file_system_map_.end()) |  208   if (file_system_it == file_system_map_.end()) | 
|  207     return false; |  209     return false; | 
|  208  |  210  | 
|  209   file_system_it->second->RequestUnmount( |  211   file_system_it->second->RequestUnmount( | 
|  210       base::Bind(&Service::OnRequestUnmountStatus, |  212       base::Bind(&Service::OnRequestUnmountStatus, | 
|  211                  weak_ptr_factory_.GetWeakPtr(), |  213                  weak_ptr_factory_.GetWeakPtr(), | 
|  212                  file_system_it->second->GetFileSystemInfo())); |  214                  file_system_it->second->GetFileSystemInfo())); | 
|  213   return true; |  215   return true; | 
|  214 } |  216 } | 
|  215  |  217  | 
|  216 std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { |  218 std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { | 
|  217   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |  219   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
|  218  |  220  | 
|  219   std::vector<ProvidedFileSystemInfo> result; |  221   std::vector<ProvidedFileSystemInfo> result; | 
|  220   for (ProvidedFileSystemMap::const_iterator it = file_system_map_.begin(); |  222   for (ProvidedFileSystemMap::const_iterator it = file_system_map_.begin(); | 
|  221        it != file_system_map_.end(); |  223        it != file_system_map_.end(); | 
|  222        ++it) { |  224        ++it) { | 
|  223     result.push_back(it->second->GetFileSystemInfo()); |  225     result.push_back(it->second->GetFileSystemInfo()); | 
|  224   } |  226   } | 
|  225   return result; |  227   return result; | 
|  226 } |  228 } | 
|  227  |  229  | 
|  228 ProvidedFileSystemInterface* Service::GetProvidedFileSystem( |  230 ProvidedFileSystemInterface* Service::GetProvidedFileSystem( | 
|  229     const std::string& extension_id, |  231     const std::string& extension_id, | 
|  230     int file_system_id) { |  232     int file_system_id) { | 
|  231   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |  233   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
|  232  |  234  | 
|  233   const ProvidedFileSystemMap::const_iterator file_system_it = |  235   const ProvidedFileSystemMap::const_iterator file_system_it = | 
|  234       file_system_map_.find(file_system_id); |  236       file_system_map_.find(file_system_id); | 
|  235   if (file_system_it == file_system_map_.end() || |  237   if (file_system_it == file_system_map_.end() || | 
|  236       file_system_it->second->GetFileSystemInfo().extension_id() != |  238       file_system_it->second->GetFileSystemInfo().extension_id() != | 
|  237           extension_id) { |  239           extension_id) { | 
|  238     return NULL; |  240     return NULL; | 
|  239   } |  241   } | 
|  240  |  242  | 
|  241   return file_system_it->second; |  243   return file_system_it->second; | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  256     if (file_system_info.extension_id() == extension->id()) { |  258     if (file_system_info.extension_id() == extension->id()) { | 
|  257       bool result = UnmountFileSystem(file_system_info.extension_id(), |  259       bool result = UnmountFileSystem(file_system_info.extension_id(), | 
|  258                                       file_system_info.file_system_id()); |  260                                       file_system_info.file_system_id()); | 
|  259       DCHECK(result); |  261       DCHECK(result); | 
|  260     } |  262     } | 
|  261   } |  263   } | 
|  262 } |  264 } | 
|  263  |  265  | 
|  264 ProvidedFileSystemInterface* Service::GetProvidedFileSystem( |  266 ProvidedFileSystemInterface* Service::GetProvidedFileSystem( | 
|  265     const std::string& mount_point_name) { |  267     const std::string& mount_point_name) { | 
|  266   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |  268   DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
|  267  |  269  | 
|  268   const MountPointNameToIdMap::const_iterator mapping_it = |  270   const MountPointNameToIdMap::const_iterator mapping_it = | 
|  269       mount_point_name_to_id_map_.find(mount_point_name); |  271       mount_point_name_to_id_map_.find(mount_point_name); | 
|  270   if (mapping_it == mount_point_name_to_id_map_.end()) |  272   if (mapping_it == mount_point_name_to_id_map_.end()) | 
|  271     return NULL; |  273     return NULL; | 
|  272  |  274  | 
|  273   const ProvidedFileSystemMap::const_iterator file_system_it = |  275   const ProvidedFileSystemMap::const_iterator file_system_it = | 
|  274       file_system_map_.find(mapping_it->second); |  276       file_system_map_.find(mapping_it->second); | 
|  275   if (file_system_it == file_system_map_.end()) |  277   if (file_system_it == file_system_map_.end()) | 
|  276     return NULL; |  278     return NULL; | 
|  277  |  279  | 
|  278   return file_system_it->second; |  280   return file_system_it->second; | 
|  279 } |  281 } | 
|  280  |  282  | 
|  281 void Service::OnRequestUnmountStatus( |  283 void Service::OnRequestUnmountStatus( | 
|  282     const ProvidedFileSystemInfo& file_system_info, |  284     const ProvidedFileSystemInfo& file_system_info, | 
|  283     base::File::Error error) { |  285     base::File::Error error) { | 
|  284   // Notify observers about failure in unmounting, since mount() will not be |  286   // Notify observers about failure in unmounting, since mount() will not be | 
|  285   // called by the provided file system. In case of success mount() will be |  287   // called by the provided file system. In case of success mount() will be | 
|  286   // invoked, and observers notified, so there is no need to call them now. |  288   // invoked, and observers notified, so there is no need to call them now. | 
|  287   if (error != base::File::FILE_OK) { |  289   if (error != base::File::FILE_OK) { | 
|  288     FOR_EACH_OBSERVER(Observer, |  290     FOR_EACH_OBSERVER(Observer, | 
|  289                       observers_, |  291                       observers_, | 
|  290                       OnProvidedFileSystemUnmount(file_system_info, error)); |  292                       OnProvidedFileSystemUnmount(file_system_info, error)); | 
|  291   } |  293   } | 
|  292 } |  294 } | 
|  293  |  295  | 
|  294 }  // namespace file_system_provider |  296 }  // namespace file_system_provider | 
|  295 }  // namespace chromeos |  297 }  // namespace chromeos | 
| OLD | NEW |