| 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 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 5 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 "RequestManager::Request", | 66 "RequestManager::Request", |
| 67 request_id, | 67 request_id, |
| 68 "type", | 68 "type", |
| 69 type); | 69 type); |
| 70 | 70 |
| 71 Request* request = new Request; | 71 Request* request = new Request; |
| 72 request->handler = std::move(handler); | 72 request->handler = std::move(handler); |
| 73 requests_[request_id] = request; | 73 requests_[request_id] = request; |
| 74 ResetTimer(request_id); | 74 ResetTimer(request_id); |
| 75 | 75 |
| 76 FOR_EACH_OBSERVER(Observer, observers_, OnRequestCreated(request_id, type)); | 76 for (auto& observer : observers_) |
| 77 observer.OnRequestCreated(request_id, type); |
| 77 | 78 |
| 78 // Execute the request implementation. In case of an execution failure, | 79 // Execute the request implementation. In case of an execution failure, |
| 79 // unregister and return 0. This may often happen, eg. if the providing | 80 // unregister and return 0. This may often happen, eg. if the providing |
| 80 // extension is not listening for the request event being sent. | 81 // extension is not listening for the request event being sent. |
| 81 // In such case, we should abort as soon as possible. | 82 // In such case, we should abort as soon as possible. |
| 82 if (!request->handler->Execute(request_id)) { | 83 if (!request->handler->Execute(request_id)) { |
| 83 DestroyRequest(request_id); | 84 DestroyRequest(request_id); |
| 84 return 0; | 85 return 0; |
| 85 } | 86 } |
| 86 | 87 |
| 87 FOR_EACH_OBSERVER(Observer, observers_, OnRequestExecuted(request_id)); | 88 for (auto& observer : observers_) |
| 89 observer.OnRequestExecuted(request_id); |
| 88 | 90 |
| 89 return request_id; | 91 return request_id; |
| 90 } | 92 } |
| 91 | 93 |
| 92 base::File::Error RequestManager::FulfillRequest( | 94 base::File::Error RequestManager::FulfillRequest( |
| 93 int request_id, | 95 int request_id, |
| 94 std::unique_ptr<RequestValue> response, | 96 std::unique_ptr<RequestValue> response, |
| 95 bool has_more) { | 97 bool has_more) { |
| 96 CHECK(response.get()); | 98 CHECK(response.get()); |
| 97 RequestMap::iterator request_it = requests_.find(request_id); | 99 RequestMap::iterator request_it = requests_.find(request_id); |
| 98 if (request_it == requests_.end()) | 100 if (request_it == requests_.end()) |
| 99 return base::File::FILE_ERROR_NOT_FOUND; | 101 return base::File::FILE_ERROR_NOT_FOUND; |
| 100 | 102 |
| 101 FOR_EACH_OBSERVER(Observer, | 103 for (auto& observer : observers_) |
| 102 observers_, | 104 observer.OnRequestFulfilled(request_id, *response.get(), has_more); |
| 103 OnRequestFulfilled(request_id, *response.get(), has_more)); | |
| 104 | 105 |
| 105 request_it->second->handler->OnSuccess(request_id, std::move(response), | 106 request_it->second->handler->OnSuccess(request_id, std::move(response), |
| 106 has_more); | 107 has_more); |
| 107 | 108 |
| 108 if (!has_more) { | 109 if (!has_more) { |
| 109 DestroyRequest(request_id); | 110 DestroyRequest(request_id); |
| 110 } else { | 111 } else { |
| 111 if (notification_manager_) | 112 if (notification_manager_) |
| 112 notification_manager_->HideUnresponsiveNotification(request_id); | 113 notification_manager_->HideUnresponsiveNotification(request_id); |
| 113 ResetTimer(request_id); | 114 ResetTimer(request_id); |
| 114 } | 115 } |
| 115 | 116 |
| 116 return base::File::FILE_OK; | 117 return base::File::FILE_OK; |
| 117 } | 118 } |
| 118 | 119 |
| 119 base::File::Error RequestManager::RejectRequest( | 120 base::File::Error RequestManager::RejectRequest( |
| 120 int request_id, | 121 int request_id, |
| 121 std::unique_ptr<RequestValue> response, | 122 std::unique_ptr<RequestValue> response, |
| 122 base::File::Error error) { | 123 base::File::Error error) { |
| 123 CHECK(response.get()); | 124 CHECK(response.get()); |
| 124 RequestMap::iterator request_it = requests_.find(request_id); | 125 RequestMap::iterator request_it = requests_.find(request_id); |
| 125 if (request_it == requests_.end()) | 126 if (request_it == requests_.end()) |
| 126 return base::File::FILE_ERROR_NOT_FOUND; | 127 return base::File::FILE_ERROR_NOT_FOUND; |
| 127 | 128 |
| 128 FOR_EACH_OBSERVER(Observer, | 129 for (auto& observer : observers_) |
| 129 observers_, | 130 observer.OnRequestRejected(request_id, *response.get(), error); |
| 130 OnRequestRejected(request_id, *response.get(), error)); | |
| 131 request_it->second->handler->OnError(request_id, std::move(response), error); | 131 request_it->second->handler->OnError(request_id, std::move(response), error); |
| 132 DestroyRequest(request_id); | 132 DestroyRequest(request_id); |
| 133 | 133 |
| 134 return base::File::FILE_OK; | 134 return base::File::FILE_OK; |
| 135 } | 135 } |
| 136 | 136 |
| 137 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) { | 137 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) { |
| 138 timeout_ = timeout; | 138 timeout_ = timeout; |
| 139 } | 139 } |
| 140 | 140 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 158 void RequestManager::RemoveObserver(Observer* observer) { | 158 void RequestManager::RemoveObserver(Observer* observer) { |
| 159 DCHECK(observer); | 159 DCHECK(observer); |
| 160 observers_.RemoveObserver(observer); | 160 observers_.RemoveObserver(observer); |
| 161 } | 161 } |
| 162 | 162 |
| 163 RequestManager::Request::Request() {} | 163 RequestManager::Request::Request() {} |
| 164 | 164 |
| 165 RequestManager::Request::~Request() {} | 165 RequestManager::Request::~Request() {} |
| 166 | 166 |
| 167 void RequestManager::OnRequestTimeout(int request_id) { | 167 void RequestManager::OnRequestTimeout(int request_id) { |
| 168 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id)); | 168 for (auto& observer : observers_) |
| 169 observer.OnRequestTimeouted(request_id); |
| 169 | 170 |
| 170 if (!notification_manager_) { | 171 if (!notification_manager_) { |
| 171 RejectRequest(request_id, std::unique_ptr<RequestValue>(new RequestValue()), | 172 RejectRequest(request_id, std::unique_ptr<RequestValue>(new RequestValue()), |
| 172 base::File::FILE_ERROR_ABORT); | 173 base::File::FILE_ERROR_ABORT); |
| 173 return; | 174 return; |
| 174 } | 175 } |
| 175 | 176 |
| 176 if (!IsInteractingWithUser()) { | 177 if (!IsInteractingWithUser()) { |
| 177 notification_manager_->ShowUnresponsiveNotification( | 178 notification_manager_->ShowUnresponsiveNotification( |
| 178 request_id, | 179 request_id, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 RequestMap::iterator request_it = requests_.find(request_id); | 251 RequestMap::iterator request_it = requests_.find(request_id); |
| 251 if (request_it == requests_.end()) | 252 if (request_it == requests_.end()) |
| 252 return; | 253 return; |
| 253 | 254 |
| 254 delete request_it->second; | 255 delete request_it->second; |
| 255 requests_.erase(request_it); | 256 requests_.erase(request_it); |
| 256 | 257 |
| 257 if (notification_manager_) | 258 if (notification_manager_) |
| 258 notification_manager_->HideUnresponsiveNotification(request_id); | 259 notification_manager_->HideUnresponsiveNotification(request_id); |
| 259 | 260 |
| 260 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); | 261 for (auto& observer : observers_) |
| 262 observer.OnRequestDestroyed(request_id); |
| 261 | 263 |
| 262 TRACE_EVENT_ASYNC_END0( | 264 TRACE_EVENT_ASYNC_END0( |
| 263 "file_system_provider", "RequestManager::Request", request_id); | 265 "file_system_provider", "RequestManager::Request", request_id); |
| 264 } | 266 } |
| 265 | 267 |
| 266 } // namespace file_system_provider | 268 } // namespace file_system_provider |
| 267 } // namespace chromeos | 269 } // namespace chromeos |
| OLD | NEW |