| 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_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 <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/files/file.h" | 14 #include "base/files/file.h" |
| 14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "base/timer/timer.h" | 19 #include "base/timer/timer.h" |
| 20 #include "chrome/browser/chromeos/file_system_provider/notification_manager_inte
rface.h" | 20 #include "chrome/browser/chromeos/file_system_provider/notification_manager_inte
rface.h" |
| 21 #include "chrome/browser/chromeos/file_system_provider/request_value.h" | 21 #include "chrome/browser/chromeos/file_system_provider/request_value.h" |
| 22 | 22 |
| 23 class Profile; | 23 class Profile; |
| 24 | 24 |
| 25 namespace chromeos { | 25 namespace chromeos { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 virtual ~HandlerInterface() {} | 60 virtual ~HandlerInterface() {} |
| 61 | 61 |
| 62 // Called when the request is created. Executes the request implementation. | 62 // Called when the request is created. Executes the request implementation. |
| 63 // Returns false in case of a execution failure. | 63 // Returns false in case of a execution failure. |
| 64 virtual bool Execute(int request_id) = 0; | 64 virtual bool Execute(int request_id) = 0; |
| 65 | 65 |
| 66 // Success callback invoked by the providing extension in response to | 66 // Success callback invoked by the providing extension in response to |
| 67 // Execute(). It may be called more than once, until |has_more| is set to | 67 // Execute(). It may be called more than once, until |has_more| is set to |
| 68 // false. | 68 // false. |
| 69 virtual void OnSuccess(int request_id, | 69 virtual void OnSuccess(int request_id, |
| 70 scoped_ptr<RequestValue> result, | 70 std::unique_ptr<RequestValue> result, |
| 71 bool has_more) = 0; | 71 bool has_more) = 0; |
| 72 | 72 |
| 73 // Error callback invoked by the providing extension in response to | 73 // Error callback invoked by the providing extension in response to |
| 74 // Execute(). It can be called at most once. It can be also called if the | 74 // Execute(). It can be called at most once. It can be also called if the |
| 75 // request is aborted due to a timeout. | 75 // request is aborted due to a timeout. |
| 76 virtual void OnError(int request_id, | 76 virtual void OnError(int request_id, |
| 77 scoped_ptr<RequestValue> result, | 77 std::unique_ptr<RequestValue> result, |
| 78 base::File::Error error) = 0; | 78 base::File::Error error) = 0; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Observes activities in the request manager. | 81 // Observes activities in the request manager. |
| 82 class Observer { | 82 class Observer { |
| 83 public: | 83 public: |
| 84 virtual ~Observer() {} | 84 virtual ~Observer() {} |
| 85 | 85 |
| 86 // Called when the request is created. | 86 // Called when the request is created. |
| 87 virtual void OnRequestCreated(int request_id, RequestType type) = 0; | 87 virtual void OnRequestCreated(int request_id, RequestType type) = 0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 109 // Creates a request manager for |profile| and |extension_id|. Note, that | 109 // Creates a request manager for |profile| and |extension_id|. Note, that |
| 110 // there may be multiple instances of request managers per extension. | 110 // there may be multiple instances of request managers per extension. |
| 111 RequestManager(Profile* profile, | 111 RequestManager(Profile* profile, |
| 112 const std::string& extension_id, | 112 const std::string& extension_id, |
| 113 NotificationManagerInterface* notification_manager); | 113 NotificationManagerInterface* notification_manager); |
| 114 virtual ~RequestManager(); | 114 virtual ~RequestManager(); |
| 115 | 115 |
| 116 // Creates a request and returns its request id (greater than 0). Returns 0 in | 116 // Creates a request and returns its request id (greater than 0). Returns 0 in |
| 117 // case of an error (eg. too many requests). The |type| argument indicates | 117 // case of an error (eg. too many requests). The |type| argument indicates |
| 118 // what kind of request it is. | 118 // what kind of request it is. |
| 119 int CreateRequest(RequestType type, scoped_ptr<HandlerInterface> handler); | 119 int CreateRequest(RequestType type, |
| 120 std::unique_ptr<HandlerInterface> handler); |
| 120 | 121 |
| 121 // Handles successful response for the |request_id|. If |has_more| is false, | 122 // Handles successful response for the |request_id|. If |has_more| is false, |
| 122 // then the request is disposed, after handling the |response|. On success, | 123 // then the request is disposed, after handling the |response|. On success, |
| 123 // returns base::File::FILE_OK. Otherwise returns an error code. |response| | 124 // returns base::File::FILE_OK. Otherwise returns an error code. |response| |
| 124 // must not be NULL. | 125 // must not be NULL. |
| 125 base::File::Error FulfillRequest(int request_id, | 126 base::File::Error FulfillRequest(int request_id, |
| 126 scoped_ptr<RequestValue> response, | 127 std::unique_ptr<RequestValue> response, |
| 127 bool has_more); | 128 bool has_more); |
| 128 | 129 |
| 129 // Handles error response for the |request_id|. If handling the error | 130 // Handles error response for the |request_id|. If handling the error |
| 130 // succeeds, theen returns base::File::FILE_OK. Otherwise returns an error | 131 // succeeds, theen returns base::File::FILE_OK. Otherwise returns an error |
| 131 // code. Always disposes the request. |response| must not be NULL. | 132 // code. Always disposes the request. |response| must not be NULL. |
| 132 base::File::Error RejectRequest(int request_id, | 133 base::File::Error RejectRequest(int request_id, |
| 133 scoped_ptr<RequestValue> response, | 134 std::unique_ptr<RequestValue> response, |
| 134 base::File::Error error); | 135 base::File::Error error); |
| 135 | 136 |
| 136 // Sets a custom timeout for tests. The new timeout value will be applied to | 137 // Sets a custom timeout for tests. The new timeout value will be applied to |
| 137 // new requests | 138 // new requests |
| 138 void SetTimeoutForTesting(const base::TimeDelta& timeout); | 139 void SetTimeoutForTesting(const base::TimeDelta& timeout); |
| 139 | 140 |
| 140 // Gets list of active request ids. | 141 // Gets list of active request ids. |
| 141 std::vector<int> GetActiveRequestIds() const; | 142 std::vector<int> GetActiveRequestIds() const; |
| 142 | 143 |
| 143 // Adds and removes observers. | 144 // Adds and removes observers. |
| 144 void AddObserver(Observer* observer); | 145 void AddObserver(Observer* observer); |
| 145 void RemoveObserver(Observer* observer); | 146 void RemoveObserver(Observer* observer); |
| 146 | 147 |
| 147 private: | 148 private: |
| 148 struct Request { | 149 struct Request { |
| 149 Request(); | 150 Request(); |
| 150 ~Request(); | 151 ~Request(); |
| 151 | 152 |
| 152 // Timer for discarding the request during a timeout. | 153 // Timer for discarding the request during a timeout. |
| 153 base::OneShotTimer timeout_timer; | 154 base::OneShotTimer timeout_timer; |
| 154 | 155 |
| 155 // Handler tied to this request. | 156 // Handler tied to this request. |
| 156 scoped_ptr<HandlerInterface> handler; | 157 std::unique_ptr<HandlerInterface> handler; |
| 157 | 158 |
| 158 private: | 159 private: |
| 159 DISALLOW_COPY_AND_ASSIGN(Request); | 160 DISALLOW_COPY_AND_ASSIGN(Request); |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 typedef std::map<int, Request*> RequestMap; | 163 typedef std::map<int, Request*> RequestMap; |
| 163 | 164 |
| 164 // Destroys the request with the passed |request_id|. | 165 // Destroys the request with the passed |request_id|. |
| 165 void DestroyRequest(int request_id); | 166 void DestroyRequest(int request_id); |
| 166 | 167 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 189 base::ObserverList<Observer> observers_; | 190 base::ObserverList<Observer> observers_; |
| 190 base::WeakPtrFactory<RequestManager> weak_ptr_factory_; | 191 base::WeakPtrFactory<RequestManager> weak_ptr_factory_; |
| 191 | 192 |
| 192 DISALLOW_COPY_AND_ASSIGN(RequestManager); | 193 DISALLOW_COPY_AND_ASSIGN(RequestManager); |
| 193 }; | 194 }; |
| 194 | 195 |
| 195 } // namespace file_system_provider | 196 } // namespace file_system_provider |
| 196 } // namespace chromeos | 197 } // namespace chromeos |
| 197 | 198 |
| 198 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ | 199 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
| OLD | NEW |