| 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/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 | 9 |
| 10 namespace chromeos { | 10 namespace chromeos { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 : next_id_(1), | 42 : next_id_(1), |
| 43 timeout_(base::TimeDelta::FromSeconds(kDefaultTimeout)), | 43 timeout_(base::TimeDelta::FromSeconds(kDefaultTimeout)), |
| 44 weak_ptr_factory_(this) {} | 44 weak_ptr_factory_(this) {} |
| 45 | 45 |
| 46 RequestManager::~RequestManager() { | 46 RequestManager::~RequestManager() { |
| 47 // Abort all of the active requests. | 47 // Abort all of the active requests. |
| 48 RequestMap::iterator it = requests_.begin(); | 48 RequestMap::iterator it = requests_.begin(); |
| 49 while (it != requests_.end()) { | 49 while (it != requests_.end()) { |
| 50 const int request_id = it->first; | 50 const int request_id = it->first; |
| 51 ++it; | 51 ++it; |
| 52 RejectRequest(request_id, | 52 RejectRequest(request_id, base::File::FILE_ERROR_ABORT); |
| 53 scoped_ptr<RequestValue>(new RequestValue()), | |
| 54 base::File::FILE_ERROR_ABORT); | |
| 55 } | 53 } |
| 56 | 54 |
| 57 DCHECK_EQ(0u, requests_.size()); | 55 DCHECK_EQ(0u, requests_.size()); |
| 58 STLDeleteValues(&requests_); | 56 STLDeleteValues(&requests_); |
| 59 } | 57 } |
| 60 | 58 |
| 61 int RequestManager::CreateRequest(RequestType type, | 59 int RequestManager::CreateRequest(RequestType type, |
| 62 scoped_ptr<HandlerInterface> handler) { | 60 scoped_ptr<HandlerInterface> handler) { |
| 63 // The request id is unique per request manager, so per service, thereof | 61 // The request id is unique per request manager, so per service, thereof |
| 64 // per profile. | 62 // per profile. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 Observer, observers_, OnRequestFulfilled(request_id, has_more)); | 104 Observer, observers_, OnRequestFulfilled(request_id, has_more)); |
| 107 | 105 |
| 108 if (!has_more) | 106 if (!has_more) |
| 109 DestroyRequest(request_id); | 107 DestroyRequest(request_id); |
| 110 else | 108 else |
| 111 request_it->second->timeout_timer.Reset(); | 109 request_it->second->timeout_timer.Reset(); |
| 112 | 110 |
| 113 return true; | 111 return true; |
| 114 } | 112 } |
| 115 | 113 |
| 116 bool RequestManager::RejectRequest(int request_id, | 114 bool RequestManager::RejectRequest(int request_id, base::File::Error error) { |
| 117 scoped_ptr<RequestValue> response, | |
| 118 base::File::Error error) { | |
| 119 RequestMap::iterator request_it = requests_.find(request_id); | 115 RequestMap::iterator request_it = requests_.find(request_id); |
| 120 if (request_it == requests_.end()) | 116 if (request_it == requests_.end()) |
| 121 return false; | 117 return false; |
| 122 | 118 |
| 123 request_it->second->handler->OnError(request_id, response.Pass(), error); | 119 request_it->second->handler->OnError(request_id, error); |
| 120 |
| 124 FOR_EACH_OBSERVER(Observer, observers_, OnRequestRejected(request_id, error)); | 121 FOR_EACH_OBSERVER(Observer, observers_, OnRequestRejected(request_id, error)); |
| 122 |
| 125 DestroyRequest(request_id); | 123 DestroyRequest(request_id); |
| 126 | 124 |
| 127 return true; | 125 return true; |
| 128 } | 126 } |
| 129 | 127 |
| 130 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) { | 128 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) { |
| 131 timeout_ = timeout; | 129 timeout_ = timeout; |
| 132 } | 130 } |
| 133 | 131 |
| 134 size_t RequestManager::GetActiveRequestsForLogging() const { | 132 size_t RequestManager::GetActiveRequestsForLogging() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 145 observers_.RemoveObserver(observer); | 143 observers_.RemoveObserver(observer); |
| 146 } | 144 } |
| 147 | 145 |
| 148 RequestManager::Request::Request() {} | 146 RequestManager::Request::Request() {} |
| 149 | 147 |
| 150 RequestManager::Request::~Request() {} | 148 RequestManager::Request::~Request() {} |
| 151 | 149 |
| 152 void RequestManager::OnRequestTimeout(int request_id) { | 150 void RequestManager::OnRequestTimeout(int request_id) { |
| 153 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id)); | 151 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id)); |
| 154 | 152 |
| 155 RejectRequest(request_id, | 153 RejectRequest(request_id, base::File::FILE_ERROR_ABORT); |
| 156 scoped_ptr<RequestValue>(new RequestValue()), | |
| 157 base::File::FILE_ERROR_ABORT); | |
| 158 } | 154 } |
| 159 | 155 |
| 160 void RequestManager::DestroyRequest(int request_id) { | 156 void RequestManager::DestroyRequest(int request_id) { |
| 161 RequestMap::iterator request_it = requests_.find(request_id); | 157 RequestMap::iterator request_it = requests_.find(request_id); |
| 162 if (request_it == requests_.end()) | 158 if (request_it == requests_.end()) |
| 163 return; | 159 return; |
| 164 | 160 |
| 165 delete request_it->second; | 161 delete request_it->second; |
| 166 requests_.erase(request_it); | 162 requests_.erase(request_it); |
| 167 | 163 |
| 168 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); | 164 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); |
| 169 } | 165 } |
| 170 | 166 |
| 171 } // namespace file_system_provider | 167 } // namespace file_system_provider |
| 172 } // namespace chromeos | 168 } // namespace chromeos |
| OLD | NEW |