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

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

Issue 350683002: [fsp] Add notifications in case of slow operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed clang. 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/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 21 matching lines...) Expand all
32 return "CLOSE_FILE"; 32 return "CLOSE_FILE";
33 case READ_FILE: 33 case READ_FILE:
34 return "READ_FILE"; 34 return "READ_FILE";
35 case TESTING: 35 case TESTING:
36 return "TESTING"; 36 return "TESTING";
37 } 37 }
38 NOTREACHED(); 38 NOTREACHED();
39 return ""; 39 return "";
40 } 40 }
41 41
42 RequestManager::RequestManager() 42 RequestManager::RequestManager(
43 : next_id_(1), 43 NotificationManagerInterface* notification_manager)
44 : notification_manager_(notification_manager),
45 next_id_(1),
44 timeout_(base::TimeDelta::FromSeconds(kDefaultTimeout)), 46 timeout_(base::TimeDelta::FromSeconds(kDefaultTimeout)),
45 weak_ptr_factory_(this) {} 47 weak_ptr_factory_(this) {
48 }
46 49
47 RequestManager::~RequestManager() { 50 RequestManager::~RequestManager() {
48 // Abort all of the active requests. 51 // Abort all of the active requests.
49 RequestMap::iterator it = requests_.begin(); 52 RequestMap::iterator it = requests_.begin();
50 while (it != requests_.end()) { 53 while (it != requests_.end()) {
51 const int request_id = it->first; 54 const int request_id = it->first;
52 ++it; 55 ++it;
53 RejectRequest(request_id, 56 RejectRequest(request_id,
54 scoped_ptr<RequestValue>(new RequestValue()), 57 scoped_ptr<RequestValue>(new RequestValue()),
55 base::File::FILE_ERROR_ABORT); 58 base::File::FILE_ERROR_ABORT);
(...skipping 14 matching lines...) Expand all
70 return 0; 73 return 0;
71 74
72 TRACE_EVENT_ASYNC_BEGIN1("file_system_provider", 75 TRACE_EVENT_ASYNC_BEGIN1("file_system_provider",
73 "RequestManager::Request", 76 "RequestManager::Request",
74 request_id, 77 request_id,
75 "type", 78 "type",
76 type); 79 type);
77 80
78 Request* request = new Request; 81 Request* request = new Request;
79 request->handler = handler.Pass(); 82 request->handler = handler.Pass();
80 request->timeout_timer.Start(FROM_HERE,
81 timeout_,
82 base::Bind(&RequestManager::OnRequestTimeout,
83 weak_ptr_factory_.GetWeakPtr(),
84 request_id));
85 requests_[request_id] = request; 83 requests_[request_id] = request;
84 ResetTimer(request_id);
86 85
87 FOR_EACH_OBSERVER(Observer, observers_, OnRequestCreated(request_id, type)); 86 FOR_EACH_OBSERVER(Observer, observers_, OnRequestCreated(request_id, type));
88 87
89 // Execute the request implementation. In case of an execution failure, 88 // Execute the request implementation. In case of an execution failure,
90 // unregister and return 0. This may often happen, eg. if the providing 89 // unregister and return 0. This may often happen, eg. if the providing
91 // extension is not listening for the request event being sent. 90 // extension is not listening for the request event being sent.
92 // In such case, we should abort as soon as possible. 91 // In such case, we should abort as soon as possible.
93 if (!request->handler->Execute(request_id)) { 92 if (!request->handler->Execute(request_id)) {
94 DestroyRequest(request_id); 93 DestroyRequest(request_id);
95 return 0; 94 return 0;
96 } 95 }
97 96
98 FOR_EACH_OBSERVER(Observer, observers_, OnRequestExecuted(request_id)); 97 FOR_EACH_OBSERVER(Observer, observers_, OnRequestExecuted(request_id));
99 98
100 return request_id; 99 return request_id;
101 } 100 }
102 101
103 bool RequestManager::FulfillRequest(int request_id, 102 bool RequestManager::FulfillRequest(int request_id,
104 scoped_ptr<RequestValue> response, 103 scoped_ptr<RequestValue> response,
105 bool has_more) { 104 bool has_more) {
106 RequestMap::iterator request_it = requests_.find(request_id); 105 RequestMap::iterator request_it = requests_.find(request_id);
107 if (request_it == requests_.end()) 106 if (request_it == requests_.end())
108 return false; 107 return false;
109 108
110 request_it->second->handler->OnSuccess(request_id, response.Pass(), has_more); 109 request_it->second->handler->OnSuccess(request_id, response.Pass(), has_more);
111 110
112 FOR_EACH_OBSERVER( 111 FOR_EACH_OBSERVER(
113 Observer, observers_, OnRequestFulfilled(request_id, has_more)); 112 Observer, observers_, OnRequestFulfilled(request_id, has_more));
114 113
115 if (!has_more) 114 if (!has_more) {
116 DestroyRequest(request_id); 115 DestroyRequest(request_id);
117 else 116 } else {
118 request_it->second->timeout_timer.Reset(); 117 if (notification_manager_)
118 notification_manager_->HideUnresponsiveNotification(request_id);
119 ResetTimer(request_id);
120 }
119 121
120 return true; 122 return true;
121 } 123 }
122 124
123 bool RequestManager::RejectRequest(int request_id, 125 bool RequestManager::RejectRequest(int request_id,
124 scoped_ptr<RequestValue> response, 126 scoped_ptr<RequestValue> response,
125 base::File::Error error) { 127 base::File::Error error) {
126 RequestMap::iterator request_it = requests_.find(request_id); 128 RequestMap::iterator request_it = requests_.find(request_id);
127 if (request_it == requests_.end()) 129 if (request_it == requests_.end())
128 return false; 130 return false;
(...skipping 23 matching lines...) Expand all
152 observers_.RemoveObserver(observer); 154 observers_.RemoveObserver(observer);
153 } 155 }
154 156
155 RequestManager::Request::Request() {} 157 RequestManager::Request::Request() {}
156 158
157 RequestManager::Request::~Request() {} 159 RequestManager::Request::~Request() {}
158 160
159 void RequestManager::OnRequestTimeout(int request_id) { 161 void RequestManager::OnRequestTimeout(int request_id) {
160 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id)); 162 FOR_EACH_OBSERVER(Observer, observers_, OnRequestTimeouted(request_id));
161 163
164 if (!notification_manager_) {
165 RejectRequest(request_id,
166 scoped_ptr<RequestValue>(new RequestValue()),
167 base::File::FILE_ERROR_ABORT);
168 return;
169 }
170
171 notification_manager_->ShowUnresponsiveNotification(
172 request_id,
173 base::Bind(&RequestManager::OnUnresponsiveNotificationResult,
174 weak_ptr_factory_.GetWeakPtr(),
175 request_id));
176 }
177
178 void RequestManager::OnUnresponsiveNotificationResult(
179 int request_id,
180 NotificationManagerInterface::NotificationResult result) {
181 RequestMap::iterator request_it = requests_.find(request_id);
182 if (request_it == requests_.end())
183 return;
184
185 if (result == NotificationManagerInterface::CONTINUE) {
186 ResetTimer(request_id);
187 return;
188 }
189
162 RejectRequest(request_id, 190 RejectRequest(request_id,
163 scoped_ptr<RequestValue>(new RequestValue()), 191 scoped_ptr<RequestValue>(new RequestValue()),
164 base::File::FILE_ERROR_ABORT); 192 base::File::FILE_ERROR_ABORT);
165 } 193 }
166 194
195 void RequestManager::ResetTimer(int request_id) {
196 RequestMap::iterator request_it = requests_.find(request_id);
197 if (request_it == requests_.end())
198 return;
199
200 request_it->second->timeout_timer.Start(
201 FROM_HERE,
202 timeout_,
203 base::Bind(&RequestManager::OnRequestTimeout,
204 weak_ptr_factory_.GetWeakPtr(),
205 request_id));
206 }
207
167 void RequestManager::DestroyRequest(int request_id) { 208 void RequestManager::DestroyRequest(int request_id) {
168 RequestMap::iterator request_it = requests_.find(request_id); 209 RequestMap::iterator request_it = requests_.find(request_id);
169 if (request_it == requests_.end()) 210 if (request_it == requests_.end())
170 return; 211 return;
171 212
172 delete request_it->second; 213 delete request_it->second;
173 requests_.erase(request_it); 214 requests_.erase(request_it);
174 215
216 if (notification_manager_)
217 notification_manager_->HideUnresponsiveNotification(request_id);
218
175 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id)); 219 FOR_EACH_OBSERVER(Observer, observers_, OnRequestDestroyed(request_id));
176 220
177 TRACE_EVENT_ASYNC_END0( 221 TRACE_EVENT_ASYNC_END0(
178 "file_system_provider", "RequestManager::Request", request_id); 222 "file_system_provider", "RequestManager::Request", request_id);
179 } 223 }
180 224
181 } // namespace file_system_provider 225 } // namespace file_system_provider
182 } // namespace chromeos 226 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698