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