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

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

Issue 239993002: [fsp] Create a RequestManager per a ProvidedFileSystem instance. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed and rebased. Created 6 years, 8 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/values.h" 7 #include "base/values.h"
8 8
9 namespace chromeos { 9 namespace chromeos {
10 namespace file_system_provider { 10 namespace file_system_provider {
11 11
12 RequestManager::RequestManager() : next_id_(1) {} 12 RequestManager::RequestManager() : next_id_(1) {}
13 13
14 RequestManager::~RequestManager() {} 14 RequestManager::~RequestManager() {
15 // Abort all of the active requests.
16 RequestMap::iterator it = requests_.begin();
17 while (it != requests_.end()) {
18 const int request_id = it->first;
19 ++it;
20 RejectRequest(request_id, base::File::FILE_ERROR_ABORT);
21 }
22 }
15 23
16 int RequestManager::CreateRequest(const std::string& extension_id, 24 int RequestManager::CreateRequest(const SuccessCallback& success_callback,
17 int file_system_id,
18 const SuccessCallback& success_callback,
19 const ErrorCallback& error_callback) { 25 const ErrorCallback& error_callback) {
20 // The request id is unique per request manager, so per service, thereof 26 // The request id is unique per request manager, so per service, thereof
21 // per profile. 27 // per profile.
22 int request_id = next_id_++; 28 int request_id = next_id_++;
23 29
24 // If cycled the int, then signal an error. 30 // If cycled the int, then signal an error.
25 if (requests_.find(request_id) != requests_.end()) 31 if (requests_.find(request_id) != requests_.end())
26 return 0; 32 return 0;
27 33
28 Request request; 34 Request request;
29 request.extension_id = extension_id;
30 request.file_system_id = file_system_id;
31 request.success_callback = success_callback; 35 request.success_callback = success_callback;
32 request.error_callback = error_callback; 36 request.error_callback = error_callback;
33 requests_[request_id] = request; 37 requests_[request_id] = request;
34 38
35 return request_id; 39 return request_id;
36 } 40 }
37 41
38 bool RequestManager::FulfillRequest(const std::string& extension_id, 42 bool RequestManager::FulfillRequest(int request_id,
39 int file_system_id,
40 int request_id,
41 scoped_ptr<base::DictionaryValue> response, 43 scoped_ptr<base::DictionaryValue> response,
42 bool has_next) { 44 bool has_next) {
43 RequestMap::iterator request_it = requests_.find(request_id); 45 RequestMap::iterator request_it = requests_.find(request_id);
44 46
45 if (request_it == requests_.end()) 47 if (request_it == requests_.end())
46 return false; 48 return false;
47 49
48 // Check if the request belongs to the same provided file system.
49 if (request_it->second.file_system_id != file_system_id ||
50 request_it->second.extension_id != extension_id) {
51 return false;
52 }
53
54 if (!request_it->second.success_callback.is_null()) 50 if (!request_it->second.success_callback.is_null())
55 request_it->second.success_callback.Run(response.Pass(), has_next); 51 request_it->second.success_callback.Run(response.Pass(), has_next);
56 if (!has_next) 52 if (!has_next)
57 requests_.erase(request_it); 53 requests_.erase(request_it);
58 54
59 return true; 55 return true;
60 } 56 }
61 57
62 bool RequestManager::RejectRequest(const std::string& extension_id, 58 bool RequestManager::RejectRequest(int request_id, base::File::Error error) {
63 int file_system_id,
64 int request_id,
65 base::File::Error error) {
66 RequestMap::iterator request_it = requests_.find(request_id); 59 RequestMap::iterator request_it = requests_.find(request_id);
67 60
68 if (request_it == requests_.end()) 61 if (request_it == requests_.end())
69 return false; 62 return false;
70 63
71 // Check if the request belongs to the same provided file system.
72 if (request_it->second.file_system_id != file_system_id ||
73 request_it->second.extension_id != extension_id) {
74 return false;
75 }
76
77 if (!request_it->second.error_callback.is_null()) 64 if (!request_it->second.error_callback.is_null())
78 request_it->second.error_callback.Run(error); 65 request_it->second.error_callback.Run(error);
79 requests_.erase(request_it); 66 requests_.erase(request_it);
80 67
81 return true; 68 return true;
82 } 69 }
83 70
84 void RequestManager::OnProvidedFileSystemMount( 71 RequestManager::Request::Request() {}
85 const ProvidedFileSystemInfo& file_system_info,
86 base::File::Error error) {}
87
88 void RequestManager::OnProvidedFileSystemUnmount(
89 const ProvidedFileSystemInfo& file_system_info,
90 base::File::Error error) {
91 // Do not continue on error, since the volume may be still mounted.
92 if (error != base::File::FILE_OK)
93 return;
94
95 // Remove all requests for this provided file system.
96 RequestMap::iterator it = requests_.begin();
97 while (it != requests_.begin()) {
98 if (it->second.file_system_id == file_system_info.file_system_id() &&
99 it->second.extension_id == file_system_info.extension_id()) {
100 RejectRequest(it->second.extension_id,
101 it->second.file_system_id,
102 it->first,
103 base::File::FILE_ERROR_ABORT);
104 requests_.erase(it++);
105 } else {
106 ++it;
107 }
108 }
109 }
110
111 RequestManager::Request::Request() : file_system_id(0) {}
112 72
113 RequestManager::Request::~Request() {} 73 RequestManager::Request::~Request() {}
114 74
115 } // namespace file_system_provider 75 } // namespace file_system_provider
116 } // namespace chromeos 76 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698