| 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/chromeos/file_system_provider/request_manager.h" | |
| 19 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/extensions/api/file_system_provider.h" | 19 #include "chrome/common/extensions/api/file_system_provider.h" |
| 21 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 22 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 23 | 22 |
| 24 namespace extensions { | 23 namespace extensions { |
| 25 class EventRouter; | 24 class EventRouter; |
| 26 } // namespace extensions | 25 } // namespace extensions |
| 27 | 26 |
| 28 namespace chromeos { | 27 namespace chromeos { |
| 29 namespace file_system_provider { | 28 namespace file_system_provider { |
| 30 | 29 |
| 31 class ProvidedFileSystemFactoryInterface; | 30 class ProvidedFileSystemFactoryInterface; |
| 32 class ProvidedFileSystemInfo; | 31 class ProvidedFileSystemInfo; |
| 33 class ProvidedFileSystemInterface; | 32 class ProvidedFileSystemInterface; |
| 34 class ServiceFactory; | 33 class ServiceFactory; |
| 35 | 34 |
| 36 // Manages and registers the file system provider service. Maintains provided | 35 // Manages and registers the file system provider service. Maintains provided |
| 37 // file systems. | 36 // file systems. |
| 38 class Service : public KeyedService { | 37 class Service : public KeyedService { |
| 39 public: | 38 public: |
| 40 typedef base::Callback<ProvidedFileSystemInterface*( | 39 typedef base::Callback<ProvidedFileSystemInterface*( |
| 41 extensions::EventRouter* event_router, | 40 extensions::EventRouter* event_router, |
| 42 RequestManager* request_manager, | |
| 43 const ProvidedFileSystemInfo& file_system_info)> | 41 const ProvidedFileSystemInfo& file_system_info)> |
| 44 FileSystemFactoryCallback; | 42 FileSystemFactoryCallback; |
| 45 | 43 |
| 46 explicit Service(Profile* profile); | 44 explicit Service(Profile* profile); |
| 47 virtual ~Service(); | 45 virtual ~Service(); |
| 48 | 46 |
| 49 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, | 47 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests, |
| 50 // where an event router is not available. | 48 // where an event router is not available. |
| 51 void SetFileSystemFactoryForTests( | 49 void SetFileSystemFactoryForTests( |
| 52 const FileSystemFactoryCallback& factory_callback); | 50 const FileSystemFactoryCallback& factory_callback); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 79 // Adds and removes observers. | 77 // Adds and removes observers. |
| 80 void AddObserver(Observer* observer); | 78 void AddObserver(Observer* observer); |
| 81 void RemoveObserver(Observer* observer); | 79 void RemoveObserver(Observer* observer); |
| 82 | 80 |
| 83 // Gets the singleton instance for the |context|. | 81 // Gets the singleton instance for the |context|. |
| 84 static Service* Get(content::BrowserContext* context); | 82 static Service* Get(content::BrowserContext* context); |
| 85 | 83 |
| 86 // BrowserContextKeyedService overrides. | 84 // BrowserContextKeyedService overrides. |
| 87 virtual void Shutdown() OVERRIDE; | 85 virtual void Shutdown() OVERRIDE; |
| 88 | 86 |
| 89 // Getter for the request manager. Used by the extension API to forward | |
| 90 // replies. Valid as long as the service. | |
| 91 RequestManager* request_manager() { return &request_manager_; } | |
| 92 | |
| 93 private: | 87 private: |
| 94 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; | 88 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; |
| 95 | 89 |
| 96 // Called when the providing extension accepts or refuses a unmount request. | 90 // Called when the providing extension accepts or refuses a unmount request. |
| 97 // If |error| is equal to FILE_OK, then the request is accepted. | 91 // If |error| is equal to FILE_OK, then the request is accepted. |
| 98 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, | 92 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, |
| 99 base::File::Error error); | 93 base::File::Error error); |
| 100 | 94 |
| 101 RequestManager request_manager_; | |
| 102 Profile* profile_; | 95 Profile* profile_; |
| 103 FileSystemFactoryCallback file_system_factory_; | 96 FileSystemFactoryCallback file_system_factory_; |
| 104 ObserverList<Observer> observers_; | 97 ObserverList<Observer> observers_; |
| 105 ProvidedFileSystemMap file_system_map_; // Owns pointers. | 98 ProvidedFileSystemMap file_system_map_; // Owns pointers. |
| 106 int next_id_; | 99 int next_id_; |
| 107 base::WeakPtrFactory<Service> weak_ptr_factory_; | 100 base::WeakPtrFactory<Service> weak_ptr_factory_; |
| 108 | 101 |
| 109 DISALLOW_COPY_AND_ASSIGN(Service); | 102 DISALLOW_COPY_AND_ASSIGN(Service); |
| 110 }; | 103 }; |
| 111 | 104 |
| 112 } // namespace file_system_provider | 105 } // namespace file_system_provider |
| 113 } // namespace chromeos | 106 } // namespace chromeos |
| 114 | 107 |
| 115 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 108 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
| OLD | NEW |