| 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 <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/file_system_provider/observer.h" | 17 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/extensions/api/file_system_provider.h" | 19 #include "chrome/common/extensions/api/file_system_provider.h" |
| 20 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 21 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 22 #include "extensions/browser/extension_registry_observer.h" |
| 23 |
| 24 namespace extensions { |
| 25 class Extension; |
| 26 class ExtensionRegistry; |
| 27 } // namespace extensions |
| 22 | 28 |
| 23 namespace extensions { | 29 namespace extensions { |
| 24 class EventRouter; | 30 class EventRouter; |
| 25 } // namespace extensions | 31 } // namespace extensions |
| 26 | 32 |
| 27 namespace chromeos { | 33 namespace chromeos { |
| 28 namespace file_system_provider { | 34 namespace file_system_provider { |
| 29 | 35 |
| 30 class ProvidedFileSystemFactoryInterface; | 36 class ProvidedFileSystemFactoryInterface; |
| 31 class ProvidedFileSystemInfo; | 37 class ProvidedFileSystemInfo; |
| 32 class ProvidedFileSystemInterface; | 38 class ProvidedFileSystemInterface; |
| 33 class ServiceFactory; | 39 class ServiceFactory; |
| 34 | 40 |
| 35 // Manages and registers the file system provider service. Maintains provided | 41 // Manages and registers the file system provider service. Maintains provided |
| 36 // file systems. | 42 // file systems. |
| 37 class Service : public KeyedService { | 43 class Service : public KeyedService, |
| 44 public extensions::ExtensionRegistryObserver { |
| 38 public: | 45 public: |
| 39 typedef base::Callback<ProvidedFileSystemInterface*( | 46 typedef base::Callback<ProvidedFileSystemInterface*( |
| 40 extensions::EventRouter* event_router, | 47 extensions::EventRouter* event_router, |
| 41 const ProvidedFileSystemInfo& file_system_info)> | 48 const ProvidedFileSystemInfo& file_system_info)> |
| 42 FileSystemFactoryCallback; | 49 FileSystemFactoryCallback; |
| 43 | 50 |
| 44 explicit Service(Profile* profile); | 51 Service(Profile* profile, extensions::ExtensionRegistry* extension_registry); |
| 45 virtual ~Service(); | 52 virtual ~Service(); |
| 46 | 53 |
| 47 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, | 54 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, |
| 48 // where an event router is not available. | 55 // where an event router is not available. |
| 49 void SetFileSystemFactoryForTests( | 56 void SetFileSystemFactoryForTests( |
| 50 const FileSystemFactoryCallback& factory_callback); | 57 const FileSystemFactoryCallback& factory_callback); |
| 51 | 58 |
| 52 // Mounts a file system provided by an extension with the |extension_id|. | 59 // Mounts a file system provided by an extension with the |extension_id|. |
| 53 // For success, it returns a numeric file system id, which is an | 60 // For success, it returns a numeric file system id, which is an |
| 54 // auto-incremented non-zero value. For failures, it returns zero. | 61 // auto-incremented non-zero value. For failures, it returns zero. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 74 const std::string& extension_id, | 81 const std::string& extension_id, |
| 75 int file_system_id); | 82 int file_system_id); |
| 76 | 83 |
| 77 // Adds and removes observers. | 84 // Adds and removes observers. |
| 78 void AddObserver(Observer* observer); | 85 void AddObserver(Observer* observer); |
| 79 void RemoveObserver(Observer* observer); | 86 void RemoveObserver(Observer* observer); |
| 80 | 87 |
| 81 // Gets the singleton instance for the |context|. | 88 // Gets the singleton instance for the |context|. |
| 82 static Service* Get(content::BrowserContext* context); | 89 static Service* Get(content::BrowserContext* context); |
| 83 | 90 |
| 84 // BrowserContextKeyedService overrides. | 91 // extensions::ExtensionRegistryObserver overrides. |
| 85 virtual void Shutdown() OVERRIDE; | 92 virtual void OnExtensionUnloaded(const extensions::Extension* extension) |
| 93 OVERRIDE; |
| 86 | 94 |
| 87 private: | 95 private: |
| 88 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; | 96 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; |
| 89 | 97 |
| 90 // Called when the providing extension accepts or refuses a unmount request. | 98 // Called when the providing extension accepts or refuses a unmount request. |
| 91 // If |error| is equal to FILE_OK, then the request is accepted. | 99 // If |error| is equal to FILE_OK, then the request is accepted. |
| 92 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, | 100 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, |
| 93 base::File::Error error); | 101 base::File::Error error); |
| 94 | 102 |
| 95 Profile* profile_; | 103 Profile* profile_; |
| 104 extensions::ExtensionRegistry* extension_registry_; // Not owned. |
| 96 FileSystemFactoryCallback file_system_factory_; | 105 FileSystemFactoryCallback file_system_factory_; |
| 97 ObserverList<Observer> observers_; | 106 ObserverList<Observer> observers_; |
| 98 ProvidedFileSystemMap file_system_map_; // Owns pointers. | 107 ProvidedFileSystemMap file_system_map_; // Owns pointers. |
| 99 int next_id_; | 108 int next_id_; |
| 100 base::WeakPtrFactory<Service> weak_ptr_factory_; | 109 base::WeakPtrFactory<Service> weak_ptr_factory_; |
| 101 | 110 |
| 102 DISALLOW_COPY_AND_ASSIGN(Service); | 111 DISALLOW_COPY_AND_ASSIGN(Service); |
| 103 }; | 112 }; |
| 104 | 113 |
| 105 } // namespace file_system_provider | 114 } // namespace file_system_provider |
| 106 } // namespace chromeos | 115 } // namespace chromeos |
| 107 | 116 |
| 108 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 117 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
| OLD | NEW |