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

Side by Side Diff: chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc

Issue 194693002: [fsp] Add requestUnmount() method together with the request manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 9 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 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 "base/values.h"
7 #include "chrome/browser/chromeos/file_system_provider/service.h" 8 #include "chrome/browser/chromeos/file_system_provider/service.h"
8 #include "chrome/common/extensions/api/file_system_provider.h" 9 #include "chrome/common/extensions/api/file_system_provider.h"
10 #include "chrome/common/extensions/api/file_system_provider_internal.h"
9 11
10 namespace extensions { 12 namespace extensions {
11 namespace { 13 namespace {
12 14
13 // Error names from 15 // Error names from
14 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions 16 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions
15 const char kSecurityErrorName[] = "SecurityError"; 17 const char kSecurityErrorName[] = "SecurityError";
16 18
17 // Error messages. 19 // Error messages.
18 const char kEmptyNameErrorMessage[] = "Empty display name is not allowed."; 20 const char kEmptyNameErrorMessage[] = "Empty display name is not allowed.";
19 const char kRegisteringFailedErrorMessage[] = 21 const char kMountFailedErrorMessage[] = "Mounting the file system failed.";
20 "Registering the file system failed."; 22 const char kUnmountFailedErrorMessage[] = "Unmounting the file system failed.";
23 const char kResponseFailedErrorMessage[] =
24 "Sending a response for the request failed.";
21 25
22 // Creates a dictionary, which looks like a DOMError. The returned dictionary 26 // Creates a dictionary, which looks like a DOMError. The returned dictionary
23 // will be converted to a real DOMError object in 27 // will be converted to a real DOMError object in
24 // file_system_provier_custom_bindings.js. 28 // file_system_provier_custom_bindings.js.
25 base::DictionaryValue* CreateError(const std::string& name, 29 base::DictionaryValue* CreateError(const std::string& name,
26 const std::string& message) { 30 const std::string& message) {
27 base::DictionaryValue* error = new base::DictionaryValue(); 31 base::DictionaryValue* error = new base::DictionaryValue();
28 error->SetString("name", name); 32 error->SetString("name", name);
29 error->SetString("message", message); 33 error->SetString("message", message);
30 return error; 34 return error;
31 } 35 }
32 36
37 // Converts ProviderError to base::File::Error. This could be redundant, if it
38 // was possible to create DOMError instances in Javascript easily.
39 base::File::Error ProviderErrorToFileError(
40 api::file_system_provider::ProviderError error) {
41 switch (error) {
42 case api::file_system_provider::PROVIDER_ERROR_OK:
43 return base::File::FILE_OK;
44 case api::file_system_provider::PROVIDER_ERROR_IN_USE:
45 return base::File::FILE_ERROR_IN_USE;
46 case api::file_system_provider::PROVIDER_ERROR_EXISTS:
47 return base::File::FILE_ERROR_EXISTS;
48 case api::file_system_provider::PROVIDER_ERROR_NOT_FOUND:
49 return base::File::FILE_ERROR_NOT_FOUND;
50 case api::file_system_provider::PROVIDER_ERROR_ACCESS_DENIED:
51 return base::File::FILE_ERROR_ACCESS_DENIED;
52 case api::file_system_provider::PROVIDER_ERROR_TOO_MANY_OPENED:
53 return base::File::FILE_ERROR_TOO_MANY_OPENED;
54 case api::file_system_provider::PROVIDER_ERROR_NO_MEMORY:
55 return base::File::FILE_ERROR_NO_MEMORY;
56 case api::file_system_provider::PROVIDER_ERROR_NO_SPACE:
57 return base::File::FILE_ERROR_NO_SPACE;
58 case api::file_system_provider::PROVIDER_ERROR_NOT_A_DIRECTORY:
59 return base::File::FILE_ERROR_NOT_A_DIRECTORY;
60 case api::file_system_provider::PROVIDER_ERROR_INVALID_OPERATION:
61 return base::File::FILE_ERROR_INVALID_OPERATION;
62 case api::file_system_provider::PROVIDER_ERROR_SECURITY:
63 return base::File::FILE_ERROR_SECURITY;
64 case api::file_system_provider::PROVIDER_ERROR_ABORT:
65 return base::File::FILE_ERROR_ABORT;
66 case api::file_system_provider::PROVIDER_ERROR_NOT_A_FILE:
67 return base::File::FILE_ERROR_NOT_A_FILE;
68 case api::file_system_provider::PROVIDER_ERROR_NOT_EMPTY:
69 return base::File::FILE_ERROR_NOT_EMPTY;
70 case api::file_system_provider::PROVIDER_ERROR_INVALID_URL:
71 return base::File::FILE_ERROR_INVALID_URL;
72 case api::file_system_provider::PROVIDER_ERROR_IO:
73 return base::File::FILE_ERROR_IO;
74 default:
75 NOTREACHED();
76 }
77 return base::File::FILE_ERROR_FAILED;
78 }
79
33 } // namespace 80 } // namespace
34 81
35 bool FileSystemProviderMountFunction::RunImpl() { 82 bool FileSystemProviderMountFunction::RunImpl() {
36 using extensions::api::file_system_provider::Mount::Params; 83 using api::file_system_provider::Mount::Params;
37 const scoped_ptr<Params> params(Params::Create(*args_)); 84 const scoped_ptr<Params> params(Params::Create(*args_));
38 EXTENSION_FUNCTION_VALIDATE(params); 85 EXTENSION_FUNCTION_VALIDATE(params);
39 86
40 // It's an error if the display name is empty. 87 // It's an error if the display name is empty.
41 if (params->display_name.empty()) { 88 if (params->display_name.empty()) {
42 base::ListValue* result = new base::ListValue(); 89 base::ListValue* result = new base::ListValue();
43 result->Append(new base::StringValue("")); 90 result->Append(new base::StringValue(""));
44 result->Append(CreateError(kSecurityErrorName, 91 result->Append(CreateError(kSecurityErrorName,
45 kEmptyNameErrorMessage)); 92 kEmptyNameErrorMessage));
46 SetResult(result); 93 SetResult(result);
47 return false; 94 return false;
48 } 95 }
49 96
50 chromeos::file_system_provider::Service* service = 97 chromeos::file_system_provider::Service* service =
51 chromeos::file_system_provider::Service::Get(GetProfile()); 98 chromeos::file_system_provider::Service::Get(GetProfile());
52 DCHECK(service); 99 DCHECK(service);
53 100
54 int file_system_id = 101 int file_system_id =
55 service->RegisterFileSystem(extension_id(), params->display_name); 102 service->MountFileSystem(extension_id(), params->display_name);
56 103
57 // If the |file_system_id| is empty, then it means that registering the file 104 // If the |file_system_id| is empty, then it means that mounting the file
58 // system failed. 105 // system failed.
59 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. 106 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
60 if (!file_system_id) { 107 if (!file_system_id) {
61 base::ListValue* result = new base::ListValue(); 108 base::ListValue* result = new base::ListValue();
62 result->Append(new base::FundamentalValue(0)); 109 result->Append(new base::FundamentalValue(0));
63 result->Append( 110 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage));
64 CreateError(kSecurityErrorName, kRegisteringFailedErrorMessage));
65 SetResult(result); 111 SetResult(result);
66 return false; 112 return false;
67 } 113 }
68 114
69 base::ListValue* result = new base::ListValue(); 115 base::ListValue* result = new base::ListValue();
70 result->Append(new base::FundamentalValue(file_system_id)); 116 result->Append(new base::FundamentalValue(file_system_id));
71 // Don't append an error on success. 117 // Don't append an error on success.
72 118
73 SetResult(result); 119 SetResult(result);
74 SendResponse(true); 120 SendResponse(true);
75 return true; 121 return true;
76 } 122 }
77 123
124 bool FileSystemProviderUnmountFunction::RunImpl() {
125 using api::file_system_provider::Unmount::Params;
126 const scoped_ptr<Params> params(Params::Create(*args_));
127 EXTENSION_FUNCTION_VALIDATE(params);
128
129 chromeos::file_system_provider::Service* service =
130 chromeos::file_system_provider::Service::Get(GetProfile());
131 DCHECK(service);
132
133 if (!service->UnmountFileSystem(extension_id(), params->file_system_id)) {
134 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
135 base::ListValue* result = new base::ListValue();
136 result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage));
137 SetResult(result);
138 return false;
139 }
140
141 base::ListValue* result = new base::ListValue();
142 SetResult(result);
143 SendResponse(true);
144 return true;
145 }
146
147 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunImpl() {
148 using api::file_system_provider_internal::UnmountRequestedSuccess::Params;
149 const scoped_ptr<Params> params(Params::Create(*args_));
150 EXTENSION_FUNCTION_VALIDATE(params);
151
152 chromeos::file_system_provider::Service* service =
153 chromeos::file_system_provider::Service::Get(GetProfile());
154 DCHECK(service);
155
156 if (!service->FulfillRequest(extension_id(),
157 params->file_system_id,
158 params->request_id,
159 scoped_ptr<base::DictionaryValue>(),
160 false /* has_more */)) {
161 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
162 base::ListValue* result = new base::ListValue();
163 result->Append(
164 CreateError(kSecurityErrorName, kResponseFailedErrorMessage));
165 SetResult(result);
166 return false;
167 }
168
169 base::ListValue* result = new base::ListValue();
170 SetResult(result);
171 SendResponse(true);
172 return true;
173 }
174
175 bool FileSystemProviderInternalUnmountRequestedErrorFunction::RunImpl() {
176 using api::file_system_provider_internal::UnmountRequestedError::Params;
177 const scoped_ptr<Params> params(Params::Create(*args_));
178 EXTENSION_FUNCTION_VALIDATE(params);
179
180 chromeos::file_system_provider::Service* service =
181 chromeos::file_system_provider::Service::Get(GetProfile());
182 DCHECK(service);
183
184 // Currently it is not possible to refer to types/enums defined in a different
185 // IDL file. Therefore we need to convert DOMString to ProviderError, since
186 // UnmountRequestedErrorFunction() is defined in a different namespace than
187 // ProvidedError.
188 // TODO(mtomasz): Remove this trick, once IDL supports namespaces correctly.
189 const api::file_system_provider::ProviderError provider_error =
190 api::file_system_provider::ParseProviderError(params->error);
191
192 if (!service->RejectRequest(extension_id(),
193 params->file_system_id,
194 params->request_id,
195 ProviderErrorToFileError(provider_error))) {
196 // TODO(mtomasz): Pass more detailed errors, rather than just a bool.
197 base::ListValue* result = new base::ListValue();
198 result->Append(
199 CreateError(kSecurityErrorName, kResponseFailedErrorMessage));
200 SetResult(result);
201 return false;
202 }
203
204 base::ListValue* result = new base::ListValue();
205 SetResult(result);
206 SendResponse(true);
207 return true;
208 }
209
78 } // namespace extensions 210 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698