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

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: Fixed tests. 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_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/04/11 06:01:50 Perhaps I might have asked this previously, but ju
mtomasz 2014/04/11 07:11:56 Basically, I wanted to avoid situation, when an ma
hashimoto 2014/04/14 10:43:42 Makes sense.
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,
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 Request(); 69 Request();
65 ~Request(); 70 ~Request();
66 71
67 // Provided file system handling the request. 72 // Providing extension's ID.
68 ProvidedFileSystem file_system; 73 std::string extension_id;
74
75 // Provided file system's ID.
76 int file_system_id;
69 77
70 // Callback to be called on success. 78 // Callback to be called on success.
71 SuccessCallback success_callback; 79 SuccessCallback success_callback;
72 80
73 // Callback to be called on error. 81 // Callback to be called on error.
74 ErrorCallback error_callback; 82 ErrorCallback error_callback;
75 }; 83 };
76 84
77 typedef std::map<int, Request> RequestMap; 85 typedef std::map<int, Request> RequestMap;
78 86
79 RequestMap requests_; 87 RequestMap requests_;
80 int next_id_; 88 int next_id_;
81 89
82 DISALLOW_COPY_AND_ASSIGN(RequestManager); 90 DISALLOW_COPY_AND_ASSIGN(RequestManager);
83 }; 91 };
84 92
85 } // namespace file_system_provider 93 } // namespace file_system_provider
86 } // namespace chromeos 94 } // namespace chromeos
87 95
88 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ 96 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698