Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/request_manager.cc

Issue 335753004: [fsp] Cleanup handling errors for operation requests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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, base::File::FILE_ERROR_ABORT); 52 RejectRequest(request_id,
53 scoped_ptr<RequestValue>(new RequestValue()),
54 base::File::FILE_ERROR_ABORT);
53 } 55 }
54 56
55 DCHECK_EQ(0u, requests_.size()); 57 DCHECK_EQ(0u, requests_.size());
56 STLDeleteValues(&requests_); 58 STLDeleteValues(&requests_);
57 } 59 }
58 60
59 int RequestManager::CreateRequest(RequestType type, 61 int RequestManager::CreateRequest(RequestType type,
60 scoped_ptr<HandlerInterface> handler) { 62 scoped_ptr<HandlerInterface> handler) {
61 // The request id is unique per request manager, so per service, thereof 63 // The request id is unique per request manager, so per service, thereof
62 // per profile. 64 // per profile.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 Observer, observers_, OnRequestFulfilled(request_id, has_more)); 106 Observer, observers_, OnRequestFulfilled(request_id, has_more));
105 107
106 if (!has_more) 108 if (!has_more)
107 DestroyRequest(request_id); 109 DestroyRequest(request_id);
108 else 110 else
109 request_it->second->timeout_timer.Reset(); 111 request_it->second->timeout_timer.Reset();
110 112
111 return true; 113 return true;
112 } 114 }
113 115
114 bool RequestManager::RejectRequest(int request_id, base::File::Error error) { 116 bool RequestManager::RejectRequest(int request_id,
117 scoped_ptr<RequestValue> response,
118 base::File::Error error) {
115 RequestMap::iterator request_it = requests_.find(request_id); 119 RequestMap::iterator request_it = requests_.find(request_id);
116 if (request_it == requests_.end()) 120 if (request_it == requests_.end())
117 return false; 121 return false;
118 122
119 request_it->second->handler->OnError(request_id, error); 123 request_it->second->handler->OnError(request_id, response.Pass(), error);
120
121 FOR_EACH_OBSERVER(Observer, observers_, OnRequestRejected(request_id, error)); 124 FOR_EACH_OBSERVER(Observer, observers_, OnRequestRejected(request_id, error));
122
123 DestroyRequest(request_id); 125 DestroyRequest(request_id);
124 126
125 return true; 127 return true;
126 } 128 }
127 129
128 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) { 130 void RequestManager::SetTimeoutForTesting(const base::TimeDelta& timeout) {
129 timeout_ = timeout; 131 timeout_ = timeout;
130 } 132 }
131 133
132 size_t RequestManager::GetActiveRequestsForLogging() const { 134 size_t RequestManager::GetActiveRequestsForLogging() const {
(...skipping 10 matching lines...) Expand all
143 observers_.RemoveObserver(observer); 145 observers_.RemoveObserver(observer);
144 } 146 }
145 147
146 RequestManager::Request::Request() {} 148 RequestManager::Request::Request() {}
147 149
148 RequestManager::Request::~Request() {} 150 RequestManager::Request::~Request() {}
149 151
150 void RequestManager::OnRequestTimeout(int request_id) { 152 void RequestManager::OnRequestTimeout(int request_id) {
151 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id)); 153 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id));
152 154
153 RejectRequest(request_id, base::File::FILE_ERROR_ABORT); 155 RejectRequest(request_id,
156 scoped_ptr<RequestValue>(new RequestValue()),
157 base::File::FILE_ERROR_ABORT);
154 } 158 }
155 159
156 void RequestManager::DestroyRequest(int request_id) { 160 void RequestManager::DestroyRequest(int request_id) {
157 RequestMap::iterator request_it = requests_.find(request_id); 161 RequestMap::iterator request_it = requests_.find(request_id);
158 if (request_it == requests_.end()) 162 if (request_it == requests_.end())
159 return; 163 return;
160 164
161 delete request_it->second; 165 delete request_it->second;
162 requests_.erase(request_it); 166 requests_.erase(request_it);
163 167
164 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); 168 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id));
165 } 169 }
166 170
167 } // namespace file_system_provider 171 } // namespace file_system_provider
168 } // namespace chromeos 172 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698