| 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 26 matching lines...) Expand all Loading... |
| 37 timeout_(base::TimeDelta::FromSeconds(kDefaultTimeout)), | 37 timeout_(base::TimeDelta::FromSeconds(kDefaultTimeout)), |
| 38 weak_ptr_factory_(this) { | 38 weak_ptr_factory_(this) { |
| 39 } | 39 } |
| 40 | 40 |
| 41 RequestManager::~RequestManager() { | 41 RequestManager::~RequestManager() { |
| 42 // Abort all of the active requests. | 42 // Abort all of the active requests. |
| 43 RequestMap::iterator it = requests_.begin(); | 43 RequestMap::iterator it = requests_.begin(); |
| 44 while (it != requests_.end()) { | 44 while (it != requests_.end()) { |
| 45 const int request_id = it->first; | 45 const int request_id = it->first; |
| 46 ++it; | 46 ++it; |
| 47 RejectRequest(request_id, | 47 RejectRequest(request_id, std::unique_ptr<RequestValue>(new RequestValue()), |
| 48 scoped_ptr<RequestValue>(new RequestValue()), | |
| 49 base::File::FILE_ERROR_ABORT); | 48 base::File::FILE_ERROR_ABORT); |
| 50 } | 49 } |
| 51 | 50 |
| 52 DCHECK_EQ(0u, requests_.size()); | 51 DCHECK_EQ(0u, requests_.size()); |
| 53 STLDeleteValues(&requests_); | 52 STLDeleteValues(&requests_); |
| 54 } | 53 } |
| 55 | 54 |
| 56 int RequestManager::CreateRequest(RequestType type, | 55 int RequestManager::CreateRequest(RequestType type, |
| 57 scoped_ptr<HandlerInterface> handler) { | 56 std::unique_ptr<HandlerInterface> handler) { |
| 58 // The request id is unique per request manager, so per service, thereof | 57 // The request id is unique per request manager, so per service, thereof |
| 59 // per profile. | 58 // per profile. |
| 60 int request_id = next_id_++; | 59 int request_id = next_id_++; |
| 61 | 60 |
| 62 // If cycled the int, then signal an error. | 61 // If cycled the int, then signal an error. |
| 63 if (requests_.find(request_id) != requests_.end()) | 62 if (requests_.find(request_id) != requests_.end()) |
| 64 return 0; | 63 return 0; |
| 65 | 64 |
| 66 TRACE_EVENT_ASYNC_BEGIN1("file_system_provider", | 65 TRACE_EVENT_ASYNC_BEGIN1("file_system_provider", |
| 67 "RequestManager::Request", | 66 "RequestManager::Request", |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 return 0; | 84 return 0; |
| 86 } | 85 } |
| 87 | 86 |
| 88 FOR_EACH_OBSERVER(Observer, observers_, OnRequestExecuted(request_id)); | 87 FOR_EACH_OBSERVER(Observer, observers_, OnRequestExecuted(request_id)); |
| 89 | 88 |
| 90 return request_id; | 89 return request_id; |
| 91 } | 90 } |
| 92 | 91 |
| 93 base::File::Error RequestManager::FulfillRequest( | 92 base::File::Error RequestManager::FulfillRequest( |
| 94 int request_id, | 93 int request_id, |
| 95 scoped_ptr<RequestValue> response, | 94 std::unique_ptr<RequestValue> response, |
| 96 bool has_more) { | 95 bool has_more) { |
| 97 CHECK(response.get()); | 96 CHECK(response.get()); |
| 98 RequestMap::iterator request_it = requests_.find(request_id); | 97 RequestMap::iterator request_it = requests_.find(request_id); |
| 99 if (request_it == requests_.end()) | 98 if (request_it == requests_.end()) |
| 100 return base::File::FILE_ERROR_NOT_FOUND; | 99 return base::File::FILE_ERROR_NOT_FOUND; |
| 101 | 100 |
| 102 FOR_EACH_OBSERVER(Observer, | 101 FOR_EACH_OBSERVER(Observer, |
| 103 observers_, | 102 observers_, |
| 104 OnRequestFulfilled(request_id, *response.get(), has_more)); | 103 OnRequestFulfilled(request_id, *response.get(), has_more)); |
| 105 | 104 |
| 106 request_it->second->handler->OnSuccess(request_id, std::move(response), | 105 request_it->second->handler->OnSuccess(request_id, std::move(response), |
| 107 has_more); | 106 has_more); |
| 108 | 107 |
| 109 if (!has_more) { | 108 if (!has_more) { |
| 110 DestroyRequest(request_id); | 109 DestroyRequest(request_id); |
| 111 } else { | 110 } else { |
| 112 if (notification_manager_) | 111 if (notification_manager_) |
| 113 notification_manager_->HideUnresponsiveNotification(request_id); | 112 notification_manager_->HideUnresponsiveNotification(request_id); |
| 114 ResetTimer(request_id); | 113 ResetTimer(request_id); |
| 115 } | 114 } |
| 116 | 115 |
| 117 return base::File::FILE_OK; | 116 return base::File::FILE_OK; |
| 118 } | 117 } |
| 119 | 118 |
| 120 base::File::Error RequestManager::RejectRequest( | 119 base::File::Error RequestManager::RejectRequest( |
| 121 int request_id, | 120 int request_id, |
| 122 scoped_ptr<RequestValue> response, | 121 std::unique_ptr<RequestValue> response, |
| 123 base::File::Error error) { | 122 base::File::Error error) { |
| 124 CHECK(response.get()); | 123 CHECK(response.get()); |
| 125 RequestMap::iterator request_it = requests_.find(request_id); | 124 RequestMap::iterator request_it = requests_.find(request_id); |
| 126 if (request_it == requests_.end()) | 125 if (request_it == requests_.end()) |
| 127 return base::File::FILE_ERROR_NOT_FOUND; | 126 return base::File::FILE_ERROR_NOT_FOUND; |
| 128 | 127 |
| 129 FOR_EACH_OBSERVER(Observer, | 128 FOR_EACH_OBSERVER(Observer, |
| 130 observers_, | 129 observers_, |
| 131 OnRequestRejected(request_id, *response.get(), error)); | 130 OnRequestRejected(request_id, *response.get(), error)); |
| 132 request_it->second->handler->OnError(request_id, std::move(response), error); | 131 request_it->second->handler->OnError(request_id, std::move(response), error); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 162 } | 161 } |
| 163 | 162 |
| 164 RequestManager::Request::Request() {} | 163 RequestManager::Request::Request() {} |
| 165 | 164 |
| 166 RequestManager::Request::~Request() {} | 165 RequestManager::Request::~Request() {} |
| 167 | 166 |
| 168 void RequestManager::OnRequestTimeout(int request_id) { | 167 void RequestManager::OnRequestTimeout(int request_id) { |
| 169 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id)); | 168 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id)); |
| 170 | 169 |
| 171 if (!notification_manager_) { | 170 if (!notification_manager_) { |
| 172 RejectRequest(request_id, | 171 RejectRequest(request_id, std::unique_ptr<RequestValue>(new RequestValue()), |
| 173 scoped_ptr<RequestValue>(new RequestValue()), | |
| 174 base::File::FILE_ERROR_ABORT); | 172 base::File::FILE_ERROR_ABORT); |
| 175 return; | 173 return; |
| 176 } | 174 } |
| 177 | 175 |
| 178 if (!IsInteractingWithUser()) { | 176 if (!IsInteractingWithUser()) { |
| 179 notification_manager_->ShowUnresponsiveNotification( | 177 notification_manager_->ShowUnresponsiveNotification( |
| 180 request_id, | 178 request_id, |
| 181 base::Bind(&RequestManager::OnUnresponsiveNotificationResult, | 179 base::Bind(&RequestManager::OnUnresponsiveNotificationResult, |
| 182 weak_ptr_factory_.GetWeakPtr(), request_id)); | 180 weak_ptr_factory_.GetWeakPtr(), request_id)); |
| 183 } else { | 181 } else { |
| 184 ResetTimer(request_id); | 182 ResetTimer(request_id); |
| 185 } | 183 } |
| 186 } | 184 } |
| 187 | 185 |
| 188 void RequestManager::OnUnresponsiveNotificationResult( | 186 void RequestManager::OnUnresponsiveNotificationResult( |
| 189 int request_id, | 187 int request_id, |
| 190 NotificationManagerInterface::NotificationResult result) { | 188 NotificationManagerInterface::NotificationResult result) { |
| 191 RequestMap::iterator request_it = requests_.find(request_id); | 189 RequestMap::iterator request_it = requests_.find(request_id); |
| 192 if (request_it == requests_.end()) | 190 if (request_it == requests_.end()) |
| 193 return; | 191 return; |
| 194 | 192 |
| 195 if (result == NotificationManagerInterface::CONTINUE) { | 193 if (result == NotificationManagerInterface::CONTINUE) { |
| 196 ResetTimer(request_id); | 194 ResetTimer(request_id); |
| 197 return; | 195 return; |
| 198 } | 196 } |
| 199 | 197 |
| 200 RejectRequest(request_id, | 198 RejectRequest(request_id, std::unique_ptr<RequestValue>(new RequestValue()), |
| 201 scoped_ptr<RequestValue>(new RequestValue()), | |
| 202 base::File::FILE_ERROR_ABORT); | 199 base::File::FILE_ERROR_ABORT); |
| 203 } | 200 } |
| 204 | 201 |
| 205 void RequestManager::ResetTimer(int request_id) { | 202 void RequestManager::ResetTimer(int request_id) { |
| 206 RequestMap::iterator request_it = requests_.find(request_id); | 203 RequestMap::iterator request_it = requests_.find(request_id); |
| 207 if (request_it == requests_.end()) | 204 if (request_it == requests_.end()) |
| 208 return; | 205 return; |
| 209 | 206 |
| 210 request_it->second->timeout_timer.Start( | 207 request_it->second->timeout_timer.Start( |
| 211 FROM_HERE, | 208 FROM_HERE, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 notification_manager_->HideUnresponsiveNotification(request_id); | 258 notification_manager_->HideUnresponsiveNotification(request_id); |
| 262 | 259 |
| 263 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); | 260 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); |
| 264 | 261 |
| 265 TRACE_EVENT_ASYNC_END0( | 262 TRACE_EVENT_ASYNC_END0( |
| 266 "file_system_provider", "RequestManager::Request", request_id); | 263 "file_system_provider", "RequestManager::Request", request_id); |
| 267 } | 264 } |
| 268 | 265 |
| 269 } // namespace file_system_provider | 266 } // namespace file_system_provider |
| 270 } // namespace chromeos | 267 } // namespace chromeos |
| OLD | NEW |