OLD | NEW |
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" | 10 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 base::ListValue* result = new base::ListValue(); | 100 base::ListValue* result = new base::ListValue(); |
101 result->Append(new base::StringValue("")); | 101 result->Append(new base::StringValue("")); |
102 result->Append(CreateError(kSecurityErrorName, | 102 result->Append(CreateError(kSecurityErrorName, |
103 kEmptyNameErrorMessage)); | 103 kEmptyNameErrorMessage)); |
104 SetResult(result); | 104 SetResult(result); |
105 return false; | 105 return false; |
106 } | 106 } |
107 | 107 |
108 Service* service = Service::Get(GetProfile()); | 108 Service* service = Service::Get(GetProfile()); |
109 DCHECK(service); | 109 DCHECK(service); |
| 110 if (!service) |
| 111 return false; |
110 | 112 |
111 int file_system_id = | 113 int file_system_id = |
112 service->MountFileSystem(extension_id(), params->display_name); | 114 service->MountFileSystem(extension_id(), params->display_name); |
113 | 115 |
114 // If the |file_system_id| is zero, then it means that registering the file | 116 // If the |file_system_id| is zero, then it means that registering the file |
115 // system failed. | 117 // system failed. |
116 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 118 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
117 if (!file_system_id) { | 119 if (!file_system_id) { |
118 base::ListValue* result = new base::ListValue(); | 120 base::ListValue* result = new base::ListValue(); |
119 result->Append(new base::FundamentalValue(0)); | 121 result->Append(new base::FundamentalValue(0)); |
120 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); | 122 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); |
121 SetResult(result); | 123 SetResult(result); |
122 return false; | 124 return false; |
123 } | 125 } |
124 | 126 |
125 base::ListValue* result = new base::ListValue(); | 127 base::ListValue* result = new base::ListValue(); |
126 result->Append(new base::FundamentalValue(file_system_id)); | 128 result->Append(new base::FundamentalValue(file_system_id)); |
127 // Don't append an error on success. | 129 // Don't append an error on success. |
128 | 130 |
129 SetResult(result); | 131 SetResult(result); |
130 return true; | 132 return true; |
131 } | 133 } |
132 | 134 |
133 bool FileSystemProviderUnmountFunction::RunImpl() { | 135 bool FileSystemProviderUnmountFunction::RunImpl() { |
134 using api::file_system_provider::Unmount::Params; | 136 using api::file_system_provider::Unmount::Params; |
135 const scoped_ptr<Params> params(Params::Create(*args_)); | 137 scoped_ptr<Params> params(Params::Create(*args_)); |
136 EXTENSION_FUNCTION_VALIDATE(params); | 138 EXTENSION_FUNCTION_VALIDATE(params); |
137 | 139 |
138 Service* service = Service::Get(GetProfile()); | 140 Service* service = Service::Get(GetProfile()); |
139 DCHECK(service); | 141 DCHECK(service); |
| 142 if (!service) |
| 143 return false; |
140 | 144 |
141 if (!service->UnmountFileSystem(extension_id(), params->file_system_id)) { | 145 if (!service->UnmountFileSystem(extension_id(), params->file_system_id)) { |
142 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 146 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
143 base::ListValue* result = new base::ListValue(); | 147 base::ListValue* result = new base::ListValue(); |
144 result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage)); | 148 result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage)); |
145 SetResult(result); | 149 SetResult(result); |
146 return false; | 150 return false; |
147 } | 151 } |
148 | 152 |
149 base::ListValue* result = new base::ListValue(); | 153 base::ListValue* result = new base::ListValue(); |
150 SetResult(result); | 154 SetResult(result); |
151 return true; | 155 return true; |
152 } | 156 } |
153 | 157 |
154 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunImpl() { | 158 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunImpl() { |
155 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; | 159 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; |
156 scoped_ptr<Params> params(Params::Create(*args_)); | 160 scoped_ptr<Params> params(Params::Create(*args_)); |
157 EXTENSION_FUNCTION_VALIDATE(params); | 161 EXTENSION_FUNCTION_VALIDATE(params); |
158 | 162 |
159 Service* service = Service::Get(GetProfile()); | 163 Service* service = Service::Get(GetProfile()); |
160 DCHECK(service); | 164 DCHECK(service); |
| 165 if (!service) |
| 166 return false; |
161 | 167 |
162 ProvidedFileSystemInterface* file_system = | 168 ProvidedFileSystemInterface* file_system = |
163 service->GetProvidedFileSystem(extension_id(), params->file_system_id); | 169 service->GetProvidedFileSystem(extension_id(), params->file_system_id); |
164 if (!file_system) { | 170 if (!file_system) { |
165 base::ListValue* result = new base::ListValue(); | 171 base::ListValue* result = new base::ListValue(); |
166 result->Append( | 172 result->Append( |
167 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage)); | 173 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage)); |
168 SetResult(result); | 174 SetResult(result); |
169 return false; | 175 return false; |
170 } | 176 } |
(...skipping 19 matching lines...) Expand all Loading... |
190 return true; | 196 return true; |
191 } | 197 } |
192 | 198 |
193 bool FileSystemProviderInternalUnmountRequestedErrorFunction::RunImpl() { | 199 bool FileSystemProviderInternalUnmountRequestedErrorFunction::RunImpl() { |
194 using api::file_system_provider_internal::UnmountRequestedError::Params; | 200 using api::file_system_provider_internal::UnmountRequestedError::Params; |
195 const scoped_ptr<Params> params(Params::Create(*args_)); | 201 const scoped_ptr<Params> params(Params::Create(*args_)); |
196 EXTENSION_FUNCTION_VALIDATE(params); | 202 EXTENSION_FUNCTION_VALIDATE(params); |
197 | 203 |
198 Service* service = Service::Get(GetProfile()); | 204 Service* service = Service::Get(GetProfile()); |
199 DCHECK(service); | 205 DCHECK(service); |
| 206 if (!service) |
| 207 return false; |
200 | 208 |
201 ProvidedFileSystemInterface* file_system = | 209 ProvidedFileSystemInterface* file_system = |
202 service->GetProvidedFileSystem(extension_id(), params->file_system_id); | 210 service->GetProvidedFileSystem(extension_id(), params->file_system_id); |
| 211 if (!file_system) { |
| 212 base::ListValue* result = new base::ListValue(); |
| 213 result->Append( |
| 214 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage)); |
| 215 SetResult(result); |
| 216 return false; |
| 217 } |
| 218 |
| 219 RequestManager* request_manager = file_system->GetRequestManager(); |
| 220 DCHECK(request_manager); |
| 221 |
| 222 if (!request_manager->RejectRequest( |
| 223 params->request_id, ProviderErrorToFileError(params->error))) { |
| 224 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
| 225 base::ListValue* result = new base::ListValue(); |
| 226 result->Append( |
| 227 CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); |
| 228 SetResult(result); |
| 229 return false; |
| 230 } |
| 231 |
| 232 base::ListValue* result = new base::ListValue(); |
| 233 SetResult(result); |
| 234 return true; |
| 235 } |
| 236 |
| 237 bool FileSystemProviderInternalGetMetadataRequestedSuccessFunction::RunImpl() { |
| 238 // TODO(mtomasz): Create a common class for these internal functions so |
| 239 // most of the code could be easily reused. |
| 240 using api::file_system_provider_internal::GetMetadataRequestedSuccess::Params; |
| 241 scoped_ptr<Params> params(Params::Create(*args_)); |
| 242 EXTENSION_FUNCTION_VALIDATE(params); |
| 243 |
| 244 Service* service = Service::Get(GetProfile()); |
| 245 DCHECK(service); |
| 246 if (!service) |
| 247 return false; |
| 248 |
| 249 ProvidedFileSystemInterface* file_system = |
| 250 service->GetProvidedFileSystem(extension_id(), params->file_system_id); |
| 251 if (!file_system) { |
| 252 base::ListValue* result = new base::ListValue(); |
| 253 result->Append( |
| 254 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage)); |
| 255 SetResult(result); |
| 256 return false; |
| 257 } |
| 258 |
| 259 RequestManager* request_manager = file_system->GetRequestManager(); |
| 260 DCHECK(request_manager); |
| 261 |
| 262 const int request_id = params->request_id; |
| 263 if (!request_manager->FulfillRequest( |
| 264 request_id, |
| 265 RequestValue::CreateForGetMetadataSuccess(params.Pass()), |
| 266 false /* has_more */)) { |
| 267 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
| 268 base::ListValue* result = new base::ListValue(); |
| 269 result->Append( |
| 270 CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); |
| 271 SetResult(result); |
| 272 return false; |
| 273 } |
| 274 |
| 275 base::ListValue* result = new base::ListValue(); |
| 276 SetResult(result); |
| 277 return true; |
| 278 } |
| 279 |
| 280 bool FileSystemProviderInternalGetMetadataRequestedErrorFunction::RunImpl() { |
| 281 using api::file_system_provider_internal::UnmountRequestedError::Params; |
| 282 const scoped_ptr<Params> params(Params::Create(*args_)); |
| 283 EXTENSION_FUNCTION_VALIDATE(params); |
| 284 |
| 285 Service* service = Service::Get(GetProfile()); |
| 286 DCHECK(service); |
| 287 if (!service) |
| 288 return false; |
| 289 |
| 290 ProvidedFileSystemInterface* file_system = |
| 291 service->GetProvidedFileSystem(extension_id(), params->file_system_id); |
203 if (!file_system) { | 292 if (!file_system) { |
204 base::ListValue* result = new base::ListValue(); | 293 base::ListValue* result = new base::ListValue(); |
205 result->Append( | 294 result->Append( |
206 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage)); | 295 CreateError(kNotFoundErrorName, kResponseFailedErrorMessage)); |
207 SetResult(result); | 296 SetResult(result); |
208 return false; | 297 return false; |
209 } | 298 } |
210 | 299 |
211 RequestManager* request_manager = file_system->GetRequestManager(); | 300 RequestManager* request_manager = file_system->GetRequestManager(); |
212 DCHECK(request_manager); | 301 DCHECK(request_manager); |
213 | 302 |
214 if (!request_manager->RejectRequest( | 303 if (!request_manager->RejectRequest( |
215 params->request_id, ProviderErrorToFileError(params->error))) { | 304 params->request_id, ProviderErrorToFileError(params->error))) { |
216 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 305 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
217 base::ListValue* result = new base::ListValue(); | 306 base::ListValue* result = new base::ListValue(); |
218 result->Append( | 307 result->Append( |
219 CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); | 308 CreateError(kSecurityErrorName, kResponseFailedErrorMessage)); |
220 SetResult(result); | 309 SetResult(result); |
221 return false; | 310 return false; |
222 } | 311 } |
223 | 312 |
224 base::ListValue* result = new base::ListValue(); | 313 base::ListValue* result = new base::ListValue(); |
225 SetResult(result); | 314 SetResult(result); |
226 return true; | 315 return true; |
227 } | 316 } |
228 | 317 |
229 } // namespace extensions | 318 } // namespace extensions |
OLD | NEW |