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 | 23 |
24 namespace chromeos { | 24 namespace chromeos { |
25 namespace file_system_provider { | 25 namespace file_system_provider { |
26 | 26 |
27 class ProvidedFileSystemInfo; | |
28 class ProvidedFileSystemInterface; | |
27 class ServiceFactory; | 29 class ServiceFactory; |
28 | 30 |
29 // Manages and registers the fileSystemProvider service. | 31 // Manages and registers the fileSystemProvider service. |
30 class Service : public KeyedService { | 32 class Service : public KeyedService { |
31 public: | 33 public: |
32 explicit Service(Profile* profile); | 34 explicit Service(Profile* profile); |
33 virtual ~Service(); | 35 virtual ~Service(); |
34 | 36 |
35 // Mounts a file system provided by an extension with the |extension_id|. | 37 // Mounts a file system provided by an extension with the |extension_id|. |
36 // For success, it returns a numeric file system id, which is an | 38 // For success, it returns a numeric file system id, which is an |
37 // auto-incremented non-zero value. For failures, it returns zero. | 39 // auto-incremented non-zero value. For failures, it returns zero. |
38 int MountFileSystem(const std::string& extension_id, | 40 int MountFileSystem(const std::string& extension_id, |
39 const std::string& file_system_name); | 41 const std::string& file_system_name); |
40 | 42 |
41 // Unmounts a file system with the specified |file_system_id| for the | 43 // Unmounts a file system with the specified |file_system_id| for the |
42 // |extension_id|. For success returns true, otherwise false. | 44 // |extension_id|. For success returns true, otherwise false. |
43 bool UnmountFileSystem(const std::string& extension_id, int file_system_id); | 45 bool UnmountFileSystem(const std::string& extension_id, int file_system_id); |
44 | 46 |
45 // Returns a list of currently mounted file systems. All items are copied. | 47 // Requests unmounting of the file system. The callback is called when the |
46 std::vector<ProvidedFileSystem> GetMountedFileSystems(); | 48 // request is accepted or rejected, with an error code. Returns false if the |
49 // request could not been created, true otherwise. | |
50 bool RequestUnmount(const std::string& extension_id, int file_system_id); | |
47 | 51 |
48 // Handles successful response for the |request_id|. If |has_next| is false, | 52 // Returns a list of information of all currently provided file systems. All |
49 // then the request is disposed, after handling the |response|. On error, | 53 // items are copied. |
50 // returns false, and the request is disposed. | 54 std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList(); |
51 bool FulfillRequest(const std::string& extension_id, | |
52 int file_system_id, | |
53 int request_id, | |
54 scoped_ptr<base::DictionaryValue> result, | |
55 bool has_next); | |
56 | 55 |
57 // Handles error response for the |request_id|. If handling the error fails, | 56 // Returns a provided file system with |file_system_id|, handled by |
58 // returns false. Always disposes the request. | 57 // the extension with |extension_id|. If not found, then returns NULL. |
59 bool RejectRequest(const std::string& extension_id, | 58 ProvidedFileSystemInterface* GetProvidedFileSystem( |
60 int file_system_id, | 59 const std::string& extension_id, |
61 int request_id, | 60 int file_system_id); |
62 base::File::Error error); | |
63 | |
64 // Requests unmounting of a file system with the passed |file_system_id|. | |
65 // Returns true is unmounting has been requested. False, if the request is | |
66 // invalid (eg. already unmounted). | |
67 bool RequestUnmount(int file_system_id); | |
68 | 61 |
69 // Adds and removes observers. | 62 // Adds and removes observers. |
70 void AddObserver(Observer* observer); | 63 void AddObserver(Observer* observer); |
71 void RemoveObserver(Observer* observer); | 64 void RemoveObserver(Observer* observer); |
72 | 65 |
73 // Gets the singleton instance for the |context|. | 66 // Gets the singleton instance for the |context|. |
74 static Service* Get(content::BrowserContext* context); | 67 static Service* Get(content::BrowserContext* context); |
75 | 68 |
76 // BrowserContextKeyedService overrides. | 69 // BrowserContextKeyedService overrides. |
77 virtual void Shutdown() OVERRIDE; | 70 virtual void Shutdown() OVERRIDE; |
78 | 71 |
72 // Getter for the request manager. Used by the extension API to forward | |
73 // replies. Valid as long as the service. | |
74 RequestManager* request_manager() { return &request_manager_; } | |
75 | |
79 private: | 76 private: |
80 typedef std::map<int, ProvidedFileSystem> FileSystemMap; | 77 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap; |
81 | 78 |
82 // Called when the providing extension calls the success callback for the | 79 // Called when the providing extension accepts or refuses a unmount request. |
83 // onUnmountRequested event. | 80 // If |error| is equal to FILE_OK, then the request is accepted. |
84 void OnRequestUnmountError(const ProvidedFileSystem& file_system, | 81 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info, |
85 base::File::Error error); | 82 base::File::Error error); |
86 | 83 |
87 RequestManager request_manager_; | 84 RequestManager request_manager_; |
88 Profile* profile_; | 85 Profile* profile_; |
89 ObserverList<Observer> observers_; | 86 ObserverList<Observer> observers_; |
90 FileSystemMap file_systems_; | 87 ScopedVector<ProvidedFileSystemInterface> file_systems_; |
88 | |
89 // Values owned by above ScopedVector. | |
hashimoto
2014/03/26 03:03:01
Managing two containers is difficult.
How about ow
mtomasz
2014/03/26 05:45:13
Good point. Done.
| |
90 ProvidedFileSystemMap file_system_map_; | |
91 | |
91 int next_id_; | 92 int next_id_; |
92 base::WeakPtrFactory<Service> weak_ptr_factory_; | 93 base::WeakPtrFactory<Service> weak_ptr_factory_; |
93 | 94 |
94 DISALLOW_COPY_AND_ASSIGN(Service); | 95 DISALLOW_COPY_AND_ASSIGN(Service); |
95 }; | 96 }; |
96 | 97 |
97 } // namespace file_system_provider | 98 } // namespace file_system_provider |
98 } // namespace chromeos | 99 } // namespace chromeos |
99 | 100 |
100 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ | 101 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ |
OLD | NEW |