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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/file_system_provider/service.h
diff --git a/chrome/browser/chromeos/file_system_provider/service.h b/chrome/browser/chromeos/file_system_provider/service.h
index 735e05fb9bf14f79a37f67a34639838da72c7a7e..adf09c5de2ccb5730fe3729fb3d7af87cf7195b4 100644
--- a/chrome/browser/chromeos/file_system_provider/service.h
+++ b/chrome/browser/chromeos/file_system_provider/service.h
@@ -21,17 +21,36 @@
#include "components/keyed_service/core/keyed_service.h"
#include "content/public/browser/browser_context.h"
+namespace extensions {
+class EventRouter;
+} // namespace extensions
+
namespace chromeos {
namespace file_system_provider {
+class ProvidedFileSystemFactoryInterface;
+class ProvidedFileSystemInfo;
+class ProvidedFileSystemInterface;
class ServiceFactory;
-// Manages and registers the fileSystemProvider service.
+// Manages and registers the file system provider service. Maintains provided
+// file systems.
class Service : public KeyedService {
public:
+ typedef base::Callback<ProvidedFileSystemInterface*(
+ extensions::EventRouter* event_router,
+ RequestManager* request_manager,
+ const ProvidedFileSystemInfo& file_system_info)>
+ FileSystemFactoryCallback;
+
explicit Service(Profile* profile);
virtual ~Service();
+ // Sets a custom ProvidedFileSystemInterface factory. Used by unit tests,
+ // where an event router is not available.
+ void SetFileSystemFactoryForTests(
+ const FileSystemFactoryCallback& factory_callback);
+
// Mounts a file system provided by an extension with the |extension_id|.
// For success, it returns a numeric file system id, which is an
// auto-incremented non-zero value. For failures, it returns zero.
@@ -42,30 +61,21 @@ class Service : public KeyedService {
// |extension_id|. For success returns true, otherwise false.
bool UnmountFileSystem(const std::string& extension_id, int file_system_id);
- // Returns a list of currently mounted file systems. All items are copied.
- std::vector<ProvidedFileSystem> GetMountedFileSystems();
-
- // Handles successful response for the |request_id|. If |has_next| is false,
- // then the request is disposed, after handling the |response|. On error,
- // returns false, and the request is disposed.
- bool FulfillRequest(const std::string& extension_id,
- int file_system_id,
- int request_id,
- scoped_ptr<base::DictionaryValue> result,
- bool has_next);
-
- // Handles error response for the |request_id|. If handling the error fails,
- // returns false. Always disposes the request.
- bool RejectRequest(const std::string& extension_id,
- int file_system_id,
- int request_id,
- base::File::Error error);
-
- // Requests unmounting of a file system with the passed |file_system_id|.
- // Returns true is unmounting has been requested. False, if the request is
- // invalid (eg. already unmounted).
+ // Requests unmounting of the file system. The callback is called when the
+ // request is accepted or rejected, with an error code. Returns false if the
+ // request could not been created, true otherwise.
bool RequestUnmount(int file_system_id);
+ // Returns a list of information of all currently provided file systems. All
+ // items are copied.
+ std::vector<ProvidedFileSystemInfo> GetProvidedFileSystemInfoList();
+
+ // Returns a provided file system with |file_system_id|, handled by
+ // the extension with |extension_id|. If not found, then returns NULL.
+ ProvidedFileSystemInterface* GetProvidedFileSystem(
+ const std::string& extension_id,
+ int file_system_id);
+
// Adds and removes observers.
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
@@ -76,18 +86,23 @@ class Service : public KeyedService {
// BrowserContextKeyedService overrides.
virtual void Shutdown() OVERRIDE;
+ // Getter for the request manager. Used by the extension API to forward
+ // replies. Valid as long as the service.
+ RequestManager* request_manager() { return &request_manager_; }
+
private:
- typedef std::map<int, ProvidedFileSystem> FileSystemMap;
+ typedef std::map<int, ProvidedFileSystemInterface*> ProvidedFileSystemMap;
- // Called when the providing extension calls the success callback for the
- // onUnmountRequested event.
- void OnRequestUnmountError(const ProvidedFileSystem& file_system,
- base::File::Error error);
+ // Called when the providing extension accepts or refuses a unmount request.
+ // If |error| is equal to FILE_OK, then the request is accepted.
+ void OnRequestUnmountStatus(const ProvidedFileSystemInfo& file_system_info,
+ base::File::Error error);
RequestManager request_manager_;
Profile* profile_;
+ FileSystemFactoryCallback file_system_factory_;
ObserverList<Observer> observers_;
- FileSystemMap file_systems_;
+ ProvidedFileSystemMap file_system_map_; // Owns pointers.
int next_id_;
base::WeakPtrFactory<Service> weak_ptr_factory_;

Powered by Google App Engine
This is Rietveld 408576698