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" | 18 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/common/extensions/api/file_system_provider.h" | 20 #include "chrome/common/extensions/api/file_system_provider.h" |
21 #include "components/keyed_service/core/keyed_service.h" | 21 #include "components/keyed_service/core/keyed_service.h" |
22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "extensions/browser/extension_registry_observer.h" |
| 24 |
| 25 namespace extensions { |
| 26 class Extension; |
| 27 class ExtensionRegistry; |
| 28 } // namespace extensions |
23 | 29 |
24 namespace chromeos { | 30 namespace chromeos { |
25 namespace file_system_provider { | 31 namespace file_system_provider { |
26 | 32 |
27 class ProvidedFileSystemInfo; | 33 class ProvidedFileSystemInfo; |
28 class ProvidedFileSystemInterface; | 34 class ProvidedFileSystemInterface; |
29 class ServiceFactory; | 35 class ServiceFactory; |
30 | 36 |
31 // Manages and registers the fileSystemProvider service. | 37 // Manages and registers the fileSystemProvider service. |
32 class Service : public KeyedService { | 38 class Service : public KeyedService, |
| 39 public extensions::ExtensionRegistryObserver { |
33 public: | 40 public: |
34 explicit Service(Profile* profile); | 41 explicit Service(Profile* profile, |
| 42 extensions::ExtensionRegistry* extension_registry); |
35 virtual ~Service(); | 43 virtual ~Service(); |
36 | 44 |
37 // Mounts a file system provided by an extension with the |extension_id|. | 45 // Mounts a file system provided by an extension with the |extension_id|. |
38 // For success, it returns a numeric file system id, which is an | 46 // For success, it returns a numeric file system id, which is an |
39 // auto-incremented non-zero value. For failures, it returns zero. | 47 // auto-incremented non-zero value. For failures, it returns zero. |
40 int MountFileSystem(const std::string& extension_id, | 48 int MountFileSystem(const std::string& extension_id, |
41 const std::string& file_system_name); | 49 const std::string& file_system_name); |
42 | 50 |
43 // Unmounts a file system with the specified |file_system_id| for the | 51 // Unmounts a file system with the specified |file_system_id| for the |
44 // |extension_id|. For success returns true, otherwise false. | 52 // |extension_id|. For success returns true, otherwise false. |
(...skipping 17 matching lines...) Expand all Loading... |
62 // Adds and removes observers. | 70 // Adds and removes observers. |
63 void AddObserver(Observer* observer); | 71 void AddObserver(Observer* observer); |
64 void RemoveObserver(Observer* observer); | 72 void RemoveObserver(Observer* observer); |
65 | 73 |
66 // Gets the singleton instance for the |context|. | 74 // Gets the singleton instance for the |context|. |
67 static Service* Get(content::BrowserContext* context); | 75 static Service* Get(content::BrowserContext* context); |
68 | 76 |
69 // BrowserContextKeyedService overrides. | 77 // BrowserContextKeyedService overrides. |
70 virtual void Shutdown() OVERRIDE; | 78 virtual void Shutdown() OVERRIDE; |
71 | 79 |
| 80 // extensions::ExtensionRegistryObserver overrides. |
| 81 virtual void OnExtensionUnloaded(const extensions::Extension* extension) |
| 82 OVERRIDE; |
| 83 |
72 // Getter for the request manager. Used by the extension API to forward | 84 // Getter for the request manager. Used by the extension API to forward |
73 // replies. Valid as long as the service. | 85 // replies. Valid as long as the service. |
74 RequestManager* request_manager() { return &request_manager_; } | 86 RequestManager* request_manager() { return &request_manager_; } |
75 | 87 |
76 private: | 88 private: |
77 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; | 89 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; |
78 | 90 |
79 // Called when the providing extension accepts or refuses a unmount request. | 91 // Called when the providing extension accepts or refuses a unmount request. |
80 // If |error| is equal to FILE_OK, then the request is accepted. | 92 // If |error| is equal to FILE_OK, then the request is accepted. |
81 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, | 93 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, |
82 base::File::Error error); | 94 base::File::Error error); |
83 | 95 |
| 96 Profile* profile_; |
| 97 |
| 98 // Owned by extensions::ExtensionRegistryFactory. |
| 99 extensions::ExtensionRegistry* extension_registry_; |
| 100 |
84 RequestManager request_manager_; | 101 RequestManager request_manager_; |
85 Profile* profile_; | |
86 ObserverList<Observer> observers_; | 102 ObserverList<Observer> observers_; |
87 ProvidedFileSystemMap file_system_map_; // Owns pointers. | 103 ProvidedFileSystemMap file_system_map_; // Owns pointers. |
88 | 104 |
89 int next_id_; | 105 int next_id_; |
90 base::WeakPtrFactory<Service> weak_ptr_factory_; | 106 base::WeakPtrFactory<Service> weak_ptr_factory_; |
91 | 107 |
92 DISALLOW_COPY_AND_ASSIGN(Service); | 108 DISALLOW_COPY_AND_ASSIGN(Service); |
93 }; | 109 }; |
94 | 110 |
95 } // namespace file_system_provider | 111 } // namespace file_system_provider |
96 } // namespace chromeos | 112 } // namespace chromeos |
97 | 113 |
98 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 114 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
OLD | NEW |