| 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/values.h" | 19 #include "base/values.h" |
| 19 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 20 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/extensions/api/file_system_provider.h" | 22 #include "chrome/common/extensions/api/file_system_provider.h" |
| 22 #include "components/keyed_service/core/keyed_service.h" | 23 #include "components/keyed_service/core/keyed_service.h" |
| 23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 24 #include "extensions/browser/extension_registry_observer.h" | 25 #include "extensions/browser/extension_registry_observer.h" |
| 25 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 26 | 27 |
| 27 namespace extensions { | 28 namespace extensions { |
| 28 class EventRouter; | 29 class EventRouter; |
| 29 class ExtensionRegistry; | 30 class ExtensionRegistry; |
| 30 } // namespace extensions | 31 } // namespace extensions |
| 31 | 32 |
| 33 namespace user_prefs { |
| 34 class PrefRegistrySyncable; |
| 35 } // namespace user_prefs |
| 36 |
| 32 namespace chromeos { | 37 namespace chromeos { |
| 33 namespace file_system_provider { | 38 namespace file_system_provider { |
| 34 | 39 |
| 40 // Key names for preferences. |
| 41 extern const char kPrefKeyFileSystemId[]; |
| 42 extern const char kPrefKeyFileSystemName[]; |
| 43 |
| 35 class ProvidedFileSystemFactoryInterface; | 44 class ProvidedFileSystemFactoryInterface; |
| 36 class ProvidedFileSystemInfo; | 45 class ProvidedFileSystemInfo; |
| 37 class ProvidedFileSystemInterface; | 46 class ProvidedFileSystemInterface; |
| 38 class ServiceFactory; | 47 class ServiceFactory; |
| 39 | 48 |
| 49 // Registers preferences to remember registered file systems between reboots. |
| 50 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 51 |
| 40 // Manages and registers the file system provider service. Maintains provided | 52 // Manages and registers the file system provider service. Maintains provided |
| 41 // file systems. | 53 // file systems. |
| 42 class Service : public KeyedService, | 54 class Service : public KeyedService, |
| 43 public extensions::ExtensionRegistryObserver { | 55 public extensions::ExtensionRegistryObserver { |
| 44 public: | 56 public: |
| 45 typedef base::Callback<ProvidedFileSystemInterface*( | 57 typedef base::Callback<ProvidedFileSystemInterface*( |
| 46 extensions::EventRouter* event_router, | 58 extensions::EventRouter* event_router, |
| 47 const ProvidedFileSystemInfo& file_system_info)> | 59 const ProvidedFileSystemInfo& file_system_info)> |
| 48 FileSystemFactoryCallback; | 60 FileSystemFactoryCallback; |
| 49 | 61 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void RemoveObserver(Observer* observer); | 104 void RemoveObserver(Observer* observer); |
| 93 | 105 |
| 94 // Gets the singleton instance for the |context|. | 106 // Gets the singleton instance for the |context|. |
| 95 static Service* Get(content::BrowserContext* context); | 107 static Service* Get(content::BrowserContext* context); |
| 96 | 108 |
| 97 // extensions::ExtensionRegistryObserver overrides. | 109 // extensions::ExtensionRegistryObserver overrides. |
| 98 virtual void OnExtensionUnloaded( | 110 virtual void OnExtensionUnloaded( |
| 99 content::BrowserContext* browser_context, | 111 content::BrowserContext* browser_context, |
| 100 const extensions::Extension* extension, | 112 const extensions::Extension* extension, |
| 101 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; | 113 extensions::UnloadedExtensionInfo::Reason reason) OVERRIDE; |
| 114 virtual void OnExtensionLoaded( |
| 115 content::BrowserContext* browser_context, |
| 116 const extensions::Extension* extension) OVERRIDE; |
| 102 | 117 |
| 103 private: | 118 private: |
| 104 // Key is a pair of an extension id and file system id, which makes it | 119 // Key is a pair of an extension id and file system id, which makes it |
| 105 // unique among the entire service instance. | 120 // unique among the entire service instance. |
| 106 typedef std::pair<std::string, std::string> FileSystemKey; | 121 typedef std::pair<std::string, std::string> FileSystemKey; |
| 107 | 122 |
| 108 typedef std::map<FileSystemKey, ProvidedFileSystemInterface*> | 123 typedef std::map<FileSystemKey, ProvidedFileSystemInterface*> |
| 109 ProvidedFileSystemMap; | 124 ProvidedFileSystemMap; |
| 110 typedef std::map<std::string, FileSystemKey> MountPointNameToKeyMap; | 125 typedef std::map<std::string, FileSystemKey> MountPointNameToKeyMap; |
| 111 | 126 |
| 112 // Called when the providing extension accepts or refuses a unmount request. | 127 // Called when the providing extension accepts or refuses a unmount request. |
| 113 // If |error| is equal to FILE_OK, then the request is accepted. | 128 // If |error| is equal to FILE_OK, then the request is accepted. |
| 114 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, | 129 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, |
| 115 base::File::Error error); | 130 base::File::Error error); |
| 116 | 131 |
| 132 // Saves a list of currently mounted file systems to preferences. Called |
| 133 // from a destructor (on shutdown). |
| 134 void RememberFileSystems(); |
| 135 |
| 136 // Removes all of the file systems mounted by the |extension_id| from |
| 137 // preferences, so they are not loaded again after reboot. |
| 138 void ForgetFileSystems(const std::string& extension_id); |
| 139 |
| 140 // Restores from preferences file systems mounted previously by the |
| 141 // |extension_id| providing extension. |
| 142 void RestoreFileSystems(const std::string& extension_id); |
| 143 |
| 117 Profile* profile_; | 144 Profile* profile_; |
| 118 extensions::ExtensionRegistry* extension_registry_; // Not owned. | 145 extensions::ExtensionRegistry* extension_registry_; // Not owned. |
| 119 FileSystemFactoryCallback file_system_factory_; | 146 FileSystemFactoryCallback file_system_factory_; |
| 120 ObserverList<Observer> observers_; | 147 ObserverList<Observer> observers_; |
| 121 ProvidedFileSystemMap file_system_map_; // Owns pointers. | 148 ProvidedFileSystemMap file_system_map_; // Owns pointers. |
| 122 MountPointNameToKeyMap mount_point_name_to_key_map_; | 149 MountPointNameToKeyMap mount_point_name_to_key_map_; |
| 150 base::ThreadChecker thread_checker_; |
| 123 base::WeakPtrFactory<Service> weak_ptr_factory_; | 151 base::WeakPtrFactory<Service> weak_ptr_factory_; |
| 124 | 152 |
| 125 DISALLOW_COPY_AND_ASSIGN(Service); | 153 DISALLOW_COPY_AND_ASSIGN(Service); |
| 126 }; | 154 }; |
| 127 | 155 |
| 128 } // namespace file_system_provider | 156 } // namespace file_system_provider |
| 129 } // namespace chromeos | 157 } // namespace chromeos |
| 130 | 158 |
| 131 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 159 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
| OLD | NEW |