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

Side by Side Diff: chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.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
« no previous file with comments | « no previous file | chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/file_system_provider/file_system_pr ovider_api.h" 5 #include "chrome/browser/chromeos/extensions/file_system_provider/file_system_pr ovider_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
11 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
10 #include "chrome/browser/chromeos/file_system_provider/service.h" 12 #include "chrome/browser/chromeos/file_system_provider/service.h"
11 #include "chrome/common/extensions/api/file_system_provider.h" 13 #include "chrome/common/extensions/api/file_system_provider.h"
12 #include "chrome/common/extensions/api/file_system_provider_internal.h" 14 #include "chrome/common/extensions/api/file_system_provider_internal.h"
13 15
16 using chromeos::file_system_provider::ProvidedFileSystemInterface;
17 using chromeos::file_system_provider::RequestManager;
18 using chromeos::file_system_provider::Service;
19
14 namespace extensions { 20 namespace extensions {
15 namespace { 21 namespace {
16 22
17 // Error names from 23 // Error names from
18 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions 24 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions
25 const char kNotFoundErrorName[] = "NotFoundError";
19 const char kSecurityErrorName[] = "SecurityError"; 26 const char kSecurityErrorName[] = "SecurityError";
20 27
21 // Error messages. 28 // Error messages.
22 const char kEmptyNameErrorMessage[] = "Empty display name is not allowed."; 29 const char kEmptyNameErrorMessage[] = "Empty display name is not allowed.";
23 const char kMountFailedErrorMessage[] = "Mounting the file system failed."; 30 const char kMountFailedErrorMessage[] = "Mounting the file system failed.";
24 const char kUnmountFailedErrorMessage[] = "Unmounting the file system failed."; 31 const char kUnmountFailedErrorMessage[] = "Unmounting the file system failed.";
25 const char kResponseFailedErrorMessage[] = 32 const char kResponseFailedErrorMessage[] =
26 "Sending a response for the request failed."; 33 "Sending a response for the request failed.";
27 34
28 // Creates a dictionary, which looks like a DOMError. The returned dictionary 35 // Creates a dictionary, which looks like a DOMError. The returned dictionary
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // It's an error if the display name is empty. 96 // It's an error if the display name is empty.
90 if (params->display_name.empty()) { 97 if (params->display_name.empty()) {
91 base::ListValue* result = new base::ListValue(); 98 base::ListValue* result = new base::ListValue();
92 result->Append(new base::StringValue("")); 99 result->Append(new base::StringValue(""));
93 result->Append(CreateError(kSecurityErrorName, 100 result->Append(CreateError(kSecurityErrorName,
94 kEmptyNameErrorMessage)); 101 kEmptyNameErrorMessage));
95 SetResult(result); 102 SetResult(result);
96 return false; 103 return false;
97 } 104 }
98 105
99 chromeos::file_system_provider::Service* service = 106 Service* service = Service::Get(GetProfile());
100 chromeos::file_system_provider::Service::Get(GetProfile());
101 DCHECK(service); 107 DCHECK(service);
102 108
103 int file_system_id = 109 int file_system_id =
104 service->MountFileSystem(extension_id(), params->display_name); 110 service->MountFileSystem(extension_id(), params->display_name);
105 111
106 // If the |file_system_id| is zero, then it means that registering the file 112 // If the |file_system_id| is zero, then it means that registering the file
107 // system failed. 113 // system failed.
108 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. 114 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
109 if (!file_system_id) { 115 if (!file_system_id) {
110 base::ListValue* result = new base::ListValue(); 116 base::ListValue* result = new base::ListValue();
111 result->Append(new base::FundamentalValue(0)); 117 result->Append(new base::FundamentalValue(0));
112 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); 118 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage));
113 SetResult(result); 119 SetResult(result);
114 return false; 120 return false;
115 } 121 }
116 122
117 base::ListValue* result = new base::ListValue(); 123 base::ListValue* result = new base::ListValue();
118 result->Append(new base::FundamentalValue(file_system_id)); 124 result->Append(new base::FundamentalValue(file_system_id));
119 // Don't append an error on success. 125 // Don't append an error on success.
120 126
121 SetResult(result); 127 SetResult(result);
122 return true; 128 return true;
123 } 129 }
124 130
125 bool FileSystemProviderUnmountFunction::RunImpl() { 131 bool FileSystemProviderUnmountFunction::RunImpl() {
126 using api::file_system_provider::Unmount::Params; 132 using api::file_system_provider::Unmount::Params;
127 const scoped_ptr<Params> params(Params::Create(*args_)); 133 const scoped_ptr<Params> params(Params::Create(*args_));
128 EXTENSION_FUNCTION_VALIDATE(params); 134 EXTENSION_FUNCTION_VALIDATE(params);
129 135
130 chromeos::file_system_provider::Service* service = 136 Service* service = Service::Get(GetProfile());
131 chromeos::file_system_provider::Service::Get(GetProfile());
132 DCHECK(service); 137 DCHECK(service);
133 138
134 if (!service->UnmountFileSystem(extension_id(), params->file_system_id)) { 139 if (!service->UnmountFileSystem(extension_id(), params->file_system_id)) {
135 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. 140 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
136 base::ListValue* result = new base::ListValue(); 141 base::ListValue* result = new base::ListValue();
137 result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage)); 142 result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage));
138 SetResult(result); 143 SetResult(result);
139 return false; 144 return false;
140 } 145 }
141 146
142 base::ListValue* result = new base::ListValue(); 147 base::ListValue* result = new base::ListValue();
143 SetResult(result); 148 SetResult(result);
144 return true; 149 return true;
145 } 150 }
146 151
147 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunImpl() { 152 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunImpl() {
148 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; 153 using api::file_system_provider_internal::UnmountRequestedSuccess::Params;
149 const scoped_ptr<Params> params(Params::Create(*args_)); 154 const scoped_ptr<Params> params(Params::Create(*args_));
150 EXTENSION_FUNCTION_VALIDATE(params); 155 EXTENSION_FUNCTION_VALIDATE(params);
151 156
152 chromeos::file_system_provider::Service* service = 157 Service* service = Service::Get(GetProfile());
153 chromeos::file_system_provider::Service::Get(GetProfile());
154 DCHECK(service); 158 DCHECK(service);
155 159
156 if (!service->request_manager()->FulfillRequest( 160 ProvidedFileSystemInterface* file_system =
157 extension_id(), 161 service->GetProvidedFileSystem(extension_id(), params->file_system_id);
158 params->file_system_id, 162 if (!file_system) {
159 params->request_id, 163 base::ListValue* result = new base::ListValue();
160 scoped_ptr<base::DictionaryValue>(), 164 result->Append(
161 false /* has_more */)) { 165 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage));
166 SetResult(result);
167 return false;
168 }
169
170 RequestManager* request_manager = file_system->GetRequestManager();
171 DCHECK(request_manager);
172
173 if (!request_manager->FulfillRequest(params->request_id,
174 scoped_ptr<base::DictionaryValue>(),
175 false /* has_more */)) {
162 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. 176 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
163 base::ListValue* result = new base::ListValue(); 177 base::ListValue* result = new base::ListValue();
164 result->Append( 178 result->Append(
165 CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); 179 CreateError(kSecurityErrorName, kResponseFailedErrorMessage));
166 SetResult(result); 180 SetResult(result);
167 return false; 181 return false;
168 } 182 }
169 183
170 base::ListValue* result = new base::ListValue(); 184 base::ListValue* result = new base::ListValue();
171 SetResult(result); 185 SetResult(result);
172 return true; 186 return true;
173 } 187 }
174 188
175 bool FileSystemProviderInternalUnmountRequestedErrorFunction::RunImpl() { 189 bool FileSystemProviderInternalUnmountRequestedErrorFunction::RunImpl() {
176 using api::file_system_provider_internal::UnmountRequestedError::Params; 190 using api::file_system_provider_internal::UnmountRequestedError::Params;
177 const scoped_ptr<Params> params(Params::Create(*args_)); 191 const scoped_ptr<Params> params(Params::Create(*args_));
178 EXTENSION_FUNCTION_VALIDATE(params); 192 EXTENSION_FUNCTION_VALIDATE(params);
179 193
180 chromeos::file_system_provider::Service* service = 194 Service* service = Service::Get(GetProfile());
181 chromeos::file_system_provider::Service::Get(GetProfile());
182 DCHECK(service); 195 DCHECK(service);
183 196
184 if (!service->request_manager()->RejectRequest( 197 ProvidedFileSystemInterface* file_system =
185 extension_id(), 198 service->GetProvidedFileSystem(extension_id(), params->file_system_id);
186 params->file_system_id, 199 if (!file_system) {
187 params->request_id, 200 base::ListValue* result = new base::ListValue();
188 ProviderErrorToFileError(params->error))) { 201 result->Append(
202 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage));
203 SetResult(result);
204 return false;
205 }
206
207 RequestManager* request_manager = file_system->GetRequestManager();
208 DCHECK(request_manager);
209
210 if (!request_manager->RejectRequest(
211 params->request_id, ProviderErrorToFileError(params->error))) {
212 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
189 base::ListValue* result = new base::ListValue(); 213 base::ListValue* result = new base::ListValue();
190 result->Append( 214 result->Append(
191 CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); 215 CreateError(kSecurityErrorName, kResponseFailedErrorMessage));
192 SetResult(result); 216 SetResult(result);
193 return false; 217 return false;
194 } 218 }
195 219
196 base::ListValue* result = new base::ListValue(); 220 base::ListValue* result = new base::ListValue();
197 SetResult(result); 221 SetResult(result);
198 return true; 222 return true;
199 } 223 }
200 224
201 } // namespace extensions 225 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698