| 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 <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/files/file.h" | 13 #include "base/files/file.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 20 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 21 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 22 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_obse
rver.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/common/extensions/api/file_system_provider.h" | 24 #include "chrome/common/extensions/api/file_system_provider.h" |
| 23 #include "components/keyed_service/core/keyed_service.h" | 25 #include "components/keyed_service/core/keyed_service.h" |
| 24 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
| 25 #include "extensions/browser/extension_registry_observer.h" | 27 #include "extensions/browser/extension_registry_observer.h" |
| 26 #include "extensions/common/extension.h" | 28 #include "extensions/common/extension.h" |
| 27 | 29 |
| 28 namespace extensions { | 30 namespace extensions { |
| 29 class ExtensionRegistry; | 31 class ExtensionRegistry; |
| 30 } // namespace extensions | 32 } // namespace extensions |
| 31 | 33 |
| 32 namespace user_prefs { | 34 namespace user_prefs { |
| 33 class PrefRegistrySyncable; | 35 class PrefRegistrySyncable; |
| 34 } // namespace user_prefs | 36 } // namespace user_prefs |
| 35 | 37 |
| 36 namespace chromeos { | 38 namespace chromeos { |
| 37 namespace file_system_provider { | 39 namespace file_system_provider { |
| 38 | 40 |
| 39 // Key names for preferences. | 41 // Key names for preferences. |
| 40 extern const char kPrefKeyFileSystemId[]; | 42 extern const char kPrefKeyFileSystemId[]; |
| 41 extern const char kPrefKeyDisplayName[]; | 43 extern const char kPrefKeyDisplayName[]; |
| 42 extern const char kPrefKeyWritable[]; | 44 extern const char kPrefKeyWritable[]; |
| 45 extern const char kPrefKeySupportsNotifyTag[]; |
| 43 | 46 |
| 44 class ProvidedFileSystemFactoryInterface; | 47 class ProvidedFileSystemFactoryInterface; |
| 45 class ProvidedFileSystemInfo; | 48 class ProvidedFileSystemInfo; |
| 46 class ProvidedFileSystemInterface; | 49 class ProvidedFileSystemInterface; |
| 47 class ServiceFactory; | 50 class ServiceFactory; |
| 48 | 51 |
| 49 // Registers preferences to remember registered file systems between reboots. | 52 // Registers preferences to remember registered file systems between reboots. |
| 50 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 53 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 51 | 54 |
| 52 // Manages and registers the file system provider service. Maintains provided | 55 // Manages and registers the file system provider service. Maintains provided |
| 53 // file systems. | 56 // file systems. |
| 54 class Service : public KeyedService, | 57 class Service : public KeyedService, |
| 55 public extensions::ExtensionRegistryObserver { | 58 public extensions::ExtensionRegistryObserver, |
| 59 public ProvidedFileSystemObserver { |
| 56 public: | 60 public: |
| 57 typedef base::Callback<ProvidedFileSystemInterface*( | 61 typedef base::Callback<ProvidedFileSystemInterface*( |
| 58 Profile* profile, | 62 Profile* profile, |
| 59 const ProvidedFileSystemInfo& file_system_info)> | 63 const ProvidedFileSystemInfo& file_system_info)> |
| 60 FileSystemFactoryCallback; | 64 FileSystemFactoryCallback; |
| 61 | 65 |
| 62 // Reason for unmounting. In case of UNMOUNT_REASON_SHUTDOWN, the file system | 66 // Reason for unmounting. In case of UNMOUNT_REASON_SHUTDOWN, the file system |
| 63 // will be remounted automatically after a reboot. In case of | 67 // will be remounted automatically after a reboot. In case of |
| 64 // UNMOUNT_REASON_USER it will be permanently unmounted. | 68 // UNMOUNT_REASON_USER it will be permanently unmounted. |
| 65 enum UnmountReason { UNMOUNT_REASON_USER, UNMOUNT_REASON_SHUTDOWN }; | 69 enum UnmountReason { UNMOUNT_REASON_USER, UNMOUNT_REASON_SHUTDOWN }; |
| 66 | 70 |
| 67 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry); | 71 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry); |
| 68 virtual ~Service(); | 72 virtual ~Service(); |
| 69 | 73 |
| 70 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, | 74 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, |
| 71 // where an event router is not available. | 75 // where an event router is not available. |
| 72 void SetFileSystemFactoryForTesting( | 76 void SetFileSystemFactoryForTesting( |
| 73 const FileSystemFactoryCallback& factory_callback); | 77 const FileSystemFactoryCallback& factory_callback); |
| 74 | 78 |
| 75 // Mounts a file system provided by an extension with the |extension_id|. If | 79 // Mounts a file system provided by an extension with the |extension_id|. If |
| 76 // |writable| is set to true, then the file system is mounted in a R/W mode. | 80 // |writable| is set to true, then the file system is mounted in a R/W mode. |
| 77 // Otherwise, only read-only operations are supported. For success, returns | 81 // Otherwise, only read-only operations are supported. If change notification |
| 82 // tags are supported, then |supports_notify_tag| must be true. Note, that |
| 83 // it is required in order to enable the internal cache. For success, returns |
| 78 // true, otherwise false. | 84 // true, otherwise false. |
| 79 bool MountFileSystem(const std::string& extension_id, | 85 bool MountFileSystem(const std::string& extension_id, |
| 80 const std::string& file_system_id, | 86 const std::string& file_system_id, |
| 81 const std::string& display_name, | 87 const std::string& display_name, |
| 82 bool writable); | 88 bool writable, |
| 89 bool supports_notify_tag); |
| 83 | 90 |
| 84 // Unmounts a file system with the specified |file_system_id| for the | 91 // Unmounts a file system with the specified |file_system_id| for the |
| 85 // |extension_id|. For success returns true, otherwise false. | 92 // |extension_id|. For success returns true, otherwise false. |
| 86 bool UnmountFileSystem(const std::string& extension_id, | 93 bool UnmountFileSystem(const std::string& extension_id, |
| 87 const std::string& file_system_id, | 94 const std::string& file_system_id, |
| 88 UnmountReason reason); | 95 UnmountReason reason); |
| 89 | 96 |
| 90 // Requests unmounting of the file system. The callback is called when the | 97 // Requests unmounting of the file system. The callback is called when the |
| 91 // request is accepted or rejected, with an error code. Returns false if the | 98 // request is accepted or rejected, with an error code. Returns false if the |
| 92 // request could not been created, true otherwise. | 99 // request could not been created, true otherwise. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 117 | 124 |
| 118 // extensions::ExtensionRegistryObserver overrides. | 125 // extensions::ExtensionRegistryObserver overrides. |
| 119 virtual void OnExtensionUnloaded( | 126 virtual void OnExtensionUnloaded( |
| 120 content::BrowserContext* browser_context, | 127 content::BrowserContext* browser_context, |
| 121 const extensions::Extension* extension, | 128 const extensions::Extension* extension, |
| 122 extensions::UnloadedExtensionInfo::Reason reason) override; | 129 extensions::UnloadedExtensionInfo::Reason reason) override; |
| 123 virtual void OnExtensionLoaded( | 130 virtual void OnExtensionLoaded( |
| 124 content::BrowserContext* browser_context, | 131 content::BrowserContext* browser_context, |
| 125 const extensions::Extension* extension) override; | 132 const extensions::Extension* extension) override; |
| 126 | 133 |
| 134 // ProvidedFileSystemInterface::Observer overrides. |
| 135 virtual void OnObservedEntryChanged( |
| 136 const ProvidedFileSystemInfo& file_system_info, |
| 137 const base::FilePath& observed_path, |
| 138 ProvidedFileSystemObserver::ChangeType change_type, |
| 139 const ProvidedFileSystemObserver::ChildChanges& child_changes, |
| 140 const base::Closure& callback) override; |
| 141 virtual void OnObservedEntryTagUpdated( |
| 142 const ProvidedFileSystemInfo& file_system_info, |
| 143 const base::FilePath& observed_path) override; |
| 144 virtual void OnObservedEntryListChanged( |
| 145 const ProvidedFileSystemInfo& file_system_info) override; |
| 146 |
| 127 private: | 147 private: |
| 128 // Key is a pair of an extension id and file system id, which makes it | 148 // Key is a pair of an extension id and file system id, which makes it |
| 129 // unique among the entire service instance. | 149 // unique among the entire service instance. |
| 130 typedef std::pair<std::string, std::string> FileSystemKey; | 150 typedef std::pair<std::string, std::string> FileSystemKey; |
| 131 | 151 |
| 132 typedef std::map<FileSystemKey, ProvidedFileSystemInterface*> | 152 typedef std::map<FileSystemKey, ProvidedFileSystemInterface*> |
| 133 ProvidedFileSystemMap; | 153 ProvidedFileSystemMap; |
| 134 typedef std::map<std::string, FileSystemKey> MountPointNameToKeyMap; | 154 typedef std::map<std::string, FileSystemKey> MountPointNameToKeyMap; |
| 135 | 155 |
| 136 // Called when the providing extension accepts or refuses a unmount request. | 156 // Called when the providing extension accepts or refuses a unmount request. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 160 base::ThreadChecker thread_checker_; | 180 base::ThreadChecker thread_checker_; |
| 161 base::WeakPtrFactory<Service> weak_ptr_factory_; | 181 base::WeakPtrFactory<Service> weak_ptr_factory_; |
| 162 | 182 |
| 163 DISALLOW_COPY_AND_ASSIGN(Service); | 183 DISALLOW_COPY_AND_ASSIGN(Service); |
| 164 }; | 184 }; |
| 165 | 185 |
| 166 } // namespace file_system_provider | 186 } // namespace file_system_provider |
| 167 } // namespace chromeos | 187 } // namespace chromeos |
| 168 | 188 |
| 169 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 189 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
| OLD | NEW |