Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/service.h

Issue 210803003: [fsp] Decouple file_service_provider::Service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 extensions {
25 class EventRouter;
26 } // namespace extensions
27
24 namespace chromeos { 28 namespace chromeos {
25 namespace file_system_provider { 29 namespace file_system_provider {
26 30
31 class ProvidedFileSystemFactoryInterface;
32 class ProvidedFileSystemInfo;
33 class ProvidedFileSystemInterface;
27 class ServiceFactory; 34 class ServiceFactory;
28 35
29 // Manages and registers the fileSystemProvider service. 36 // Manages and registers the file system provider service. Maintains provided
37 // file systems.
30 class Service : public KeyedService { 38 class Service : public KeyedService {
31 public: 39 public:
40 typedef base::Callback<ProvidedFileSystemInterface*(
41 extensions::EventRouter* event_router,
42 RequestManager* request_manager,
43 const ProvidedFileSystemInfo& file_system_info)>
44 FileSystemFactoryCallback;
45
32 explicit Service(Profile* profile); 46 explicit Service(Profile* profile);
33 virtual ~Service(); 47 virtual ~Service();
34 48
49 // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests,
50 // where an event router is not available.
51 void SetFileSystemFactoryForTests(
52 const FileSystemFactoryCallback& factory_callback);
53
35 // Mounts a file system provided by an extension with the |extension_id|. 54 // 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 55 // For success, it returns a numeric file system id, which is an
37 // auto-incremented non-zero value. For failures, it returns zero. 56 // auto-incremented non-zero value. For failures, it returns zero.
38 int MountFileSystem(const std::string& extension_id, 57 int MountFileSystem(const std::string& extension_id,
39 const std::string& file_system_name); 58 const std::string& file_system_name);
40 59
41 // Unmounts a file system with the specified |file_system_id| for the 60 // Unmounts a file system with the specified |file_system_id| for the
42 // |extension_id|. For success returns true, otherwise false. 61 // |extension_id|. For success returns true, otherwise false.
43 bool UnmountFileSystem(const std::string& extension_id, int file_system_id); 62 bool UnmountFileSystem(const std::string& extension_id, int file_system_id);
44 63
45 // Returns a list of currently mounted file systems. All items are copied. 64 // Requests unmounting of the file system. The callback is called when the
46 std::vector<ProvidedFileSystem> GetMountedFileSystems(); 65 // request is accepted or rejected, with an error code. Returns false if the
66 // request could not been created, true otherwise.
67 bool RequestUnmount(int file_system_id);
47 68
48 // Handles successful response for the |request_id|. If |has_next| is false, 69 // Returns a list of information of all currently provided file systems. All
49 // then the request is disposed, after handling the |response|. On error, 70 // items are copied.
50 // returns false, and the request is disposed. 71 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 72
57 // Handles error response for the |request_id|. If handling the error fails, 73 // Returns a provided file system with |file_system_id|, handled by
58 // returns false. Always disposes the request. 74 // the extension with |extension_id|. If not found, then returns NULL.
59 bool RejectRequest(const std::string& extension_id, 75 ProvidedFileSystemInterface* GetProvidedFileSystem(
60 int file_system_id, 76 const std::string& extension_id,
61 int request_id, 77 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 78
69 // Adds and removes observers. 79 // Adds and removes observers.
70 void AddObserver(Observer* observer); 80 void AddObserver(Observer* observer);
71 void RemoveObserver(Observer* observer); 81 void RemoveObserver(Observer* observer);
72 82
73 // Gets the singleton instance for the |context|. 83 // Gets the singleton instance for the |context|.
74 static Service* Get(content::BrowserContext* context); 84 static Service* Get(content::BrowserContext* context);
75 85
76 // BrowserContextKeyedService overrides. 86 // BrowserContextKeyedService overrides.
77 virtual void Shutdown() OVERRIDE; 87 virtual void Shutdown() OVERRIDE;
78 88
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
79 private: 93 private:
80 typedef std::map<int, ProvidedFileSystem> FileSystemMap; 94 typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap;
81 95
82 // Called when the providing extension calls the success callback for the 96 // Called when the providing extension accepts or refuses a unmount request.
83 // onUnmountRequested event. 97 // If |error| is equal to FILE_OK, then the request is accepted.
84 void OnRequestUnmountError(const ProvidedFileSystem& file_system, 98 void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info,
85 base::File::Error error); 99 base::File::Error error);
86 100
87 RequestManager request_manager_; 101 RequestManager request_manager_;
88 Profile* profile_; 102 Profile* profile_;
103 FileSystemFactoryCallback file_system_factory_;
89 ObserverList<Observer> observers_; 104 ObserverList<Observer> observers_;
90 FileSystemMap file_systems_; 105 ProvidedFileSystemMap file_system_map_; // Owns pointers.
91 int next_id_; 106 int next_id_;
92 base::WeakPtrFactory<Service> weak_ptr_factory_; 107 base::WeakPtrFactory<Service> weak_ptr_factory_;
93 108
94 DISALLOW_COPY_AND_ASSIGN(Service); 109 DISALLOW_COPY_AND_ASSIGN(Service);
95 }; 110 };
96 111
97 } // namespace file_system_provider 112 } // namespace file_system_provider
98 } // namespace chromeos 113 } // namespace chromeos
99 114
100 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_ 115 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698