| 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 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 13 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 19 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 48 | 49 |
| 49 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry); | 50 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry); |
| 50 virtual ~Service(); | 51 virtual ~Service(); |
| 51 | 52 |
| 52 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, | 53 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, |
| 53 // where an event router is not available. | 54 // where an event router is not available. |
| 54 void SetFileSystemFactoryForTests( | 55 void SetFileSystemFactoryForTests( |
| 55 const FileSystemFactoryCallback& factory_callback); | 56 const FileSystemFactoryCallback& factory_callback); |
| 56 | 57 |
| 57 // Mounts a file system provided by an extension with the |extension_id|. | 58 // Mounts a file system provided by an extension with the |extension_id|. |
| 58 // For success, it returns a numeric file system id, which is an | 59 // For success, returns true, otherwise false. |
| 59 // auto-incremented non-zero value. For failures, it returns zero. | 60 bool MountFileSystem(const std::string& extension_id, |
| 60 int MountFileSystem(const std::string& extension_id, | 61 const std::string& file_system_id, |
| 61 const std::string& file_system_name); | 62 const std::string& file_system_name); |
| 62 | 63 |
| 63 // Unmounts a file system with the specified |file_system_id| for the | 64 // Unmounts a file system with the specified |file_system_id| for the |
| 64 // |extension_id|. For success returns true, otherwise false. | 65 // |extension_id|. For success returns true, otherwise false. |
| 65 bool UnmountFileSystem(const std::string& extension_id, int file_system_id); | 66 bool UnmountFileSystem(const std::string& extension_id, |
| 67 const std::string& file_system_id); |
| 66 | 68 |
| 67 // Requests unmounting of the file system. The callback is called when the | 69 // Requests unmounting of the file system. The callback is called when the |
| 68 // request is accepted or rejected, with an error code. Returns false if the | 70 // request is accepted or rejected, with an error code. Returns false if the |
| 69 // request could not been created, true otherwise. | 71 // request could not been created, true otherwise. |
| 70 bool RequestUnmount(int file_system_id); | 72 bool RequestUnmount(const std::string& extension_id, |
| 73 const std::string& file_system_id); |
| 71 | 74 |
| 72 // Returns a list of information of all currently provided file systems. All | 75 // Returns a list of information of all currently provided file systems. All |
| 73 // items are copied. | 76 // items are copied. |
| 74 std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList(); | 77 std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList(); |
| 75 | 78 |
| 76 // Returns a provided file system with |file_system_id|, handled by | 79 // Returns a provided file system with |file_system_id|, handled by |
| 77 // the extension with |extension_id|. If not found, then returns NULL. | 80 // the extension with |extension_id|. If not found, then returns NULL. |
| 78 ProvidedFileSystemInterface* GetProvidedFileSystem( | 81 ProvidedFileSystemInterface* GetProvidedFileSystem( |
| 79 const std::string& extension_id, | 82 const std::string& extension_id, |
| 80 int file_system_id); | 83 const std::string& file_system_id); |
| 81 | 84 |
| 82 // Returns a provided file system attached to the the passed | 85 // Returns a provided file system attached to the the passed |
| 83 // |mount_point_name|. If not found, then returns NULL. | 86 // |mount_point_name|. If not found, then returns NULL. |
| 84 ProvidedFileSystemInterface* GetProvidedFileSystem( | 87 ProvidedFileSystemInterface* GetProvidedFileSystem( |
| 85 const std::string& mount_point_name); | 88 const std::string& mount_point_name); |
| 86 | 89 |
| 87 // Adds and removes observers. | 90 // Adds and removes observers. |
| 88 void AddObserver(Observer* observer); | 91 void AddObserver(Observer* observer); |
| 89 void RemoveObserver(Observer* observer); | 92 void RemoveObserver(Observer* observer); |
| 90 | 93 |
| 91 // Gets the singleton instance for the |context|. | 94 // Gets the singleton instance for the |context|. |
| 92 static Service* Get(content::BrowserContext* context); | 95 static Service* Get(content::BrowserContext* context); |
| 93 | 96 |
| 94 // extensions::ExtensionRegistryObserver overrides. | 97 // extensions::ExtensionRegistryObserver overrides. |
| 95 virtual void OnExtensionUnloaded( | 98 virtual void OnExtensionUnloaded( |
| 96 content::BrowserContext* browser_context, | 99 content::BrowserContext* browser_context, |
| 97 const extensions::Extension* extension, | 100 const extensions::Extension* extension, |
| 98 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; | 101 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 99 | 102 |
| 100 private: | 103 private: |
| 101 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; | 104 // Key is a pair of an extension id and file system id, which makes it |
| 102 typedef std::map<std::string, int> MountPointNameToIdMap; | 105 // unique among the entire service instance. |
| 106 typedef std::pair<std::string, std::string> FileSystemKey; |
| 107 |
| 108 typedef std::map<FileSystemKey, ProvidedFileSystemInterface*> |
| 109 ProvidedFileSystemMap; |
| 110 typedef std::map<std::string, FileSystemKey> MountPointNameToKeyMap; |
| 103 | 111 |
| 104 // Called when the providing extension accepts or refuses a unmount request. | 112 // Called when the providing extension accepts or refuses a unmount request. |
| 105 // If |error| is equal to FILE_OK, then the request is accepted. | 113 // If |error| is equal to FILE_OK, then the request is accepted. |
| 106 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, | 114 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, |
| 107 base::File::Error error); | 115 base::File::Error error); |
| 108 | 116 |
| 109 Profile* profile_; | 117 Profile* profile_; |
| 110 extensions::ExtensionRegistry* extension_registry_; // Not owned. | 118 extensions::ExtensionRegistry* extension_registry_; // Not owned. |
| 111 FileSystemFactoryCallback file_system_factory_; | 119 FileSystemFactoryCallback file_system_factory_; |
| 112 ObserverList<Observer> observers_; | 120 ObserverList<Observer> observers_; |
| 113 ProvidedFileSystemMap file_system_map_; // Owns pointers. | 121 ProvidedFileSystemMap file_system_map_; // Owns pointers. |
| 114 MountPointNameToIdMap mount_point_name_to_id_map_; | 122 MountPointNameToKeyMap mount_point_name_to_key_map_; |
| 115 int next_id_; | 123 int next_index_; |
| 116 base::WeakPtrFactory<Service> weak_ptr_factory_; | 124 base::WeakPtrFactory<Service> weak_ptr_factory_; |
| 117 | 125 |
| 118 DISALLOW_COPY_AND_ASSIGN(Service); | 126 DISALLOW_COPY_AND_ASSIGN(Service); |
| 119 }; | 127 }; |
| 120 | 128 |
| 121 } // namespace file_system_provider | 129 } // namespace file_system_provider |
| 122 } // namespace chromeos | 130 } // namespace chromeos |
| 123 | 131 |
| 124 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 132 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
| OLD | NEW |