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

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

Issue 210803003: [fsp] Decouple file_service_provider::Service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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_REQUEST_MANAGER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
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 "chrome/browser/chromeos/file_system_provider/observer.h" 14 #include "chrome/browser/chromeos/file_system_provider/observer.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
16 16
17 namespace base { 17 namespace base {
18 class DictionaryValue; 18 class DictionaryValue;
19 } // namespace base 19 } // namespace base
20 20
21 namespace chromeos { 21 namespace chromeos {
22 namespace file_system_provider { 22 namespace file_system_provider {
23 23
24 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>, bool has_next)> 24 typedef base::Callback<void(scoped_ptr<base::DictionaryValue> result,
25 SuccessCallback; 25 bool has_next)> SuccessCallback;
26 typedef base::Callback<void(base::File::Error)> ErrorCallback; 26 typedef base::Callback<void(base::File::Error)> ErrorCallback;
27 27
28 // Manages requests between the service, async utils and the providing 28 // Manages requests between the service, async utils and the providing
29 // extensions. 29 // extensions.
30 // TODO(mtomasz): Create for each provided file system.
30 class RequestManager : public Observer { 31 class RequestManager : public Observer {
31 public: 32 public:
32 RequestManager(); 33 RequestManager();
33 virtual ~RequestManager(); 34 virtual ~RequestManager();
34 35
35 // Creates a request and returns its request id (greater than 0). Returns 0 in 36 // Creates a request and returns its request id (greater than 0). Returns 0 in
36 // case of an error (eg. too many requests). The passed callbacks can be NULL. 37 // case of an error (eg. too many requests). The passed callbacks can be NULL.
37 int CreateRequest(const ProvidedFileSystem& file_system, 38 int CreateRequest(const std::string extension_id,
hashimoto 2014/03/26 03:03:01 nit: const std::string&
mtomasz 2014/03/26 05:45:13 Oops. Done.
39 int file_system_id,
38 const SuccessCallback& success_callback, 40 const SuccessCallback& success_callback,
39 const ErrorCallback& error_callback); 41 const ErrorCallback& error_callback);
40 42
41 // Handles successful response for the |request_id|. If |has_next| is false, 43 // Handles successful response for the |request_id|. If |has_next| is false,
42 // then the request is disposed, after handling the |response|. On error, 44 // then the request is disposed, after handling the |response|. On error,
43 // returns false, and the request is disposed. 45 // returns false, and the request is disposed.
44 bool FulfillRequest(const ProvidedFileSystem& file_system, 46 bool FulfillRequest(const std::string& extension_id,
47 int file_system_id,
45 int request_id, 48 int request_id,
46 scoped_ptr<base::DictionaryValue> response, 49 scoped_ptr<base::DictionaryValue> response,
47 bool has_next); 50 bool has_next);
48 51
49 // Handles error response for the |request_id|. If handling the error fails, 52 // Handles error response for the |request_id|. If handling the error fails,
50 // returns false. Always disposes the request. 53 // returns false. Always disposes the request.
51 bool RejectRequest(const ProvidedFileSystem& file_system, 54 bool RejectRequest(const std::string& extension_id,
55 int file_system_id,
52 int request_id, 56 int request_id,
53 base::File::Error error); 57 base::File::Error error);
54 58
55 // file_system_provider::Observer overrides. 59 // file_system_provider::Observer overrides.
56 virtual void OnProvidedFileSystemMount(const ProvidedFileSystem& file_system, 60 virtual void OnProvidedFileSystemMount(
57 base::File::Error error) OVERRIDE; 61 const ProvidedFileSystemInfo& file_system_info,
hashimoto 2014/03/26 03:03:01 Why don't these methods take (extension_id, file_s
mtomasz 2014/03/26 05:45:13 Just to match the observer's interface. As for Cr
hashimoto 2014/03/26 06:53:04 Thank you for clearly explaining about your plan.
62 base::File::Error error) OVERRIDE;
58 virtual void OnProvidedFileSystemUnmount( 63 virtual void OnProvidedFileSystemUnmount(
59 const ProvidedFileSystem& file_system, 64 const ProvidedFileSystemInfo& file_system_info,
60 base::File::Error error) OVERRIDE; 65 base::File::Error error) OVERRIDE;
61 66
62 private: 67 private:
63 struct Request { 68 struct Request {
64 // Provided file system handling the request. 69 // Providing extension's ID.
65 ProvidedFileSystem file_system; 70 std::string extension_id;
71
72 // Provided file system's ID.
73 int file_system_id;
66 74
67 // Callback to be called on success. 75 // Callback to be called on success.
68 SuccessCallback success_callback; 76 SuccessCallback success_callback;
69 77
70 // Callback to be called on error. 78 // Callback to be called on error.
71 ErrorCallback error_callback; 79 ErrorCallback error_callback;
72 }; 80 };
73 81
74 typedef std::map<int, Request> RequestMap; 82 typedef std::map<int, Request> RequestMap;
75 83
76 RequestMap requests_; 84 RequestMap requests_;
77 int next_id_; 85 int next_id_;
78 86
79 DISALLOW_COPY_AND_ASSIGN(RequestManager); 87 DISALLOW_COPY_AND_ASSIGN(RequestManager);
80 }; 88 };
81 89
82 } // namespace file_system_provider 90 } // namespace file_system_provider
83 } // namespace chromeos 91 } // namespace chromeos
84 92
85 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ 93 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698