| 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 "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if (!request->handler->Execute(request_id)) { | 112 if (!request->handler->Execute(request_id)) { |
| 113 DestroyRequest(request_id); | 113 DestroyRequest(request_id); |
| 114 return 0; | 114 return 0; |
| 115 } | 115 } |
| 116 | 116 |
| 117 FOR_EACH_OBSERVER(Observer, observers_, OnRequestExecuted(request_id)); | 117 FOR_EACH_OBSERVER(Observer, observers_, OnRequestExecuted(request_id)); |
| 118 | 118 |
| 119 return request_id; | 119 return request_id; |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool RequestManager::FulfillRequest(int request_id, | 122 base::File::Error RequestManager::FulfillRequest( |
| 123 scoped_ptr<RequestValue> response, | 123 int request_id, |
| 124 bool has_more) { | 124 scoped_ptr<RequestValue> response, |
| 125 bool has_more) { |
| 125 CHECK(response.get()); | 126 CHECK(response.get()); |
| 126 RequestMap::iterator request_it = requests_.find(request_id); | 127 RequestMap::iterator request_it = requests_.find(request_id); |
| 127 if (request_it == requests_.end()) | 128 if (request_it == requests_.end()) |
| 128 return false; | 129 return base::File::FILE_ERROR_NOT_FOUND; |
| 129 | 130 |
| 130 FOR_EACH_OBSERVER(Observer, | 131 FOR_EACH_OBSERVER(Observer, |
| 131 observers_, | 132 observers_, |
| 132 OnRequestFulfilled(request_id, *response.get(), has_more)); | 133 OnRequestFulfilled(request_id, *response.get(), has_more)); |
| 133 | 134 |
| 134 request_it->second->handler->OnSuccess(request_id, response.Pass(), has_more); | 135 request_it->second->handler->OnSuccess(request_id, response.Pass(), has_more); |
| 135 | 136 |
| 136 if (!has_more) { | 137 if (!has_more) { |
| 137 DestroyRequest(request_id); | 138 DestroyRequest(request_id); |
| 138 } else { | 139 } else { |
| 139 if (notification_manager_) | 140 if (notification_manager_) |
| 140 notification_manager_->HideUnresponsiveNotification(request_id); | 141 notification_manager_->HideUnresponsiveNotification(request_id); |
| 141 ResetTimer(request_id); | 142 ResetTimer(request_id); |
| 142 } | 143 } |
| 143 | 144 |
| 144 return true; | 145 return base::File::FILE_OK; |
| 145 } | 146 } |
| 146 | 147 |
| 147 bool RequestManager::RejectRequest(int request_id, | 148 base::File::Error RequestManager::RejectRequest( |
| 148 scoped_ptr<RequestValue> response, | 149 int request_id, |
| 149 base::File::Error error) { | 150 scoped_ptr<RequestValue> response, |
| 151 base::File::Error error) { |
| 150 CHECK(response.get()); | 152 CHECK(response.get()); |
| 151 RequestMap::iterator request_it = requests_.find(request_id); | 153 RequestMap::iterator request_it = requests_.find(request_id); |
| 152 if (request_it == requests_.end()) | 154 if (request_it == requests_.end()) |
| 153 return false; | 155 return base::File::FILE_ERROR_NOT_FOUND; |
| 154 | 156 |
| 155 FOR_EACH_OBSERVER(Observer, | 157 FOR_EACH_OBSERVER(Observer, |
| 156 observers_, | 158 observers_, |
| 157 OnRequestRejected(request_id, *response.get(), error)); | 159 OnRequestRejected(request_id, *response.get(), error)); |
| 158 request_it->second->handler->OnError(request_id, response.Pass(), error); | 160 request_it->second->handler->OnError(request_id, response.Pass(), error); |
| 159 DestroyRequest(request_id); | 161 DestroyRequest(request_id); |
| 160 | 162 |
| 161 return true; | 163 return base::File::FILE_OK; |
| 162 } | 164 } |
| 163 | 165 |
| 164 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) { | 166 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) { |
| 165 timeout_ = timeout; | 167 timeout_ = timeout; |
| 166 } | 168 } |
| 167 | 169 |
| 168 std::vector<int> RequestManager::GetActiveRequestIds() const { | 170 std::vector<int> RequestManager::GetActiveRequestIds() const { |
| 169 std::vector<int> result; | 171 std::vector<int> result; |
| 170 | 172 |
| 171 for (RequestMap::const_iterator request_it = requests_.begin(); | 173 for (RequestMap::const_iterator request_it = requests_.begin(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 notification_manager_->HideUnresponsiveNotification(request_id); | 252 notification_manager_->HideUnresponsiveNotification(request_id); |
| 251 | 253 |
| 252 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); | 254 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); |
| 253 | 255 |
| 254 TRACE_EVENT_ASYNC_END0( | 256 TRACE_EVENT_ASYNC_END0( |
| 255 "file_system_provider", "RequestManager::Request", request_id); | 257 "file_system_provider", "RequestManager::Request", request_id); |
| 256 } | 258 } |
| 257 | 259 |
| 258 } // namespace file_system_provider | 260 } // namespace file_system_provider |
| 259 } // namespace chromeos | 261 } // namespace chromeos |
| OLD | NEW |