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 "chrome/browser/chromeos/file_system_provider/service.h" |
7 #include "chrome/common/extensions/api/file_system_provider.h" | 8 #include "chrome/common/extensions/api/file_system_provider.h" |
8 | 9 |
9 namespace extensions { | 10 namespace extensions { |
10 | |
11 namespace { | 11 namespace { |
12 | 12 |
13 // Error names from | 13 // Error names from |
14 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions | 14 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions |
15 const char kSecurityErrorName[] = "SecurityError"; | 15 const char kSecurityErrorName[] = "SecurityError"; |
16 | 16 |
17 // Error messages. | 17 // Error messages. |
18 const char kEmptyNameErrorMessage[] = "Empty display name is not allowed"; | 18 const char kEmptyNameErrorMessage[] = "Empty display name is not allowed."; |
| 19 const char kRegisteringFailedErrorMessage[] = |
| 20 "Registering the file system failed."; |
19 | 21 |
20 // Creates a dictionary, which looks like a DOMError. The returned dictionary | 22 // Creates a dictionary, which looks like a DOMError. The returned dictionary |
21 // will be converted to a real DOMError object in | 23 // will be converted to a real DOMError object in |
22 // file_system_provier_custom_bindings.js. | 24 // file_system_provier_custom_bindings.js. |
23 base::DictionaryValue* CreateError(const std::string& name, | 25 base::DictionaryValue* CreateError(const std::string& name, |
24 const std::string& message) { | 26 const std::string& message) { |
25 base::DictionaryValue* error = new base::DictionaryValue(); | 27 base::DictionaryValue* error = new base::DictionaryValue(); |
26 error->SetString("name", name); | 28 error->SetString("name", name); |
27 error->SetString("message", message); | 29 error->SetString("message", message); |
28 return error; | 30 return error; |
29 } | 31 } |
30 | 32 |
31 } // namespace | 33 } // namespace |
32 | 34 |
33 bool FileSystemProviderMountFunction::RunImpl() { | 35 bool FileSystemProviderMountFunction::RunImpl() { |
34 using extensions::api::file_system_provider::Mount::Params; | 36 using extensions::api::file_system_provider::Mount::Params; |
35 const scoped_ptr<Params> params(Params::Create(*args_)); | 37 const scoped_ptr<Params> params(Params::Create(*args_)); |
36 EXTENSION_FUNCTION_VALIDATE(params); | 38 EXTENSION_FUNCTION_VALIDATE(params); |
37 | 39 |
38 // It's an error if the display name is empty. | 40 // It's an error if the display name is empty. |
39 if (params->display_name.empty()) { | 41 if (params->display_name.empty()) { |
40 const std::string file_system_id = ""; | |
41 | |
42 base::ListValue* result = new base::ListValue(); | 42 base::ListValue* result = new base::ListValue(); |
43 result->Append(new base::StringValue(file_system_id)); | 43 result->Append(new base::StringValue("")); |
44 result->Append(CreateError(kSecurityErrorName, | 44 result->Append(CreateError(kSecurityErrorName, |
45 kEmptyNameErrorMessage)); | 45 kEmptyNameErrorMessage)); |
46 SetResult(result); | 46 SetResult(result); |
47 SendResponse(true); | 47 return false; |
48 return true; | |
49 } | 48 } |
50 | 49 |
51 // TODO(satorux): Implement the real logic. | 50 chromeos::file_system_provider::Service* service = |
52 const std::string file_system_id = params->display_name; | 51 chromeos::file_system_provider::Service::Get(GetProfile()); |
| 52 DCHECK(service); |
| 53 |
| 54 const std::string file_system_id = |
| 55 service->RegisterFileSystem(extension_id(), params->display_name); |
| 56 |
| 57 // If the |file_system_id| is empty, then it means that registering the file |
| 58 // system failed. |
| 59 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
| 60 if (file_system_id.empty()) { |
| 61 base::ListValue* result = new base::ListValue(); |
| 62 result->Append(new base::StringValue("")); |
| 63 result->Append( |
| 64 CreateError(kSecurityErrorName, kRegisteringFailedErrorMessage)); |
| 65 SetResult(result); |
| 66 return false; |
| 67 } |
53 | 68 |
54 base::ListValue* result = new base::ListValue(); | 69 base::ListValue* result = new base::ListValue(); |
55 result->Append(new base::StringValue(file_system_id)); | 70 result->Append(new base::StringValue(file_system_id)); |
56 // Don't append an error on success. | 71 // Don't append an error on success. |
57 | 72 |
58 SetResult(result); | 73 SetResult(result); |
59 SendResponse(true); | 74 SendResponse(true); |
60 return true; | 75 return true; |
61 } | 76 } |
62 | 77 |
63 } // namespace extensions | 78 } // namespace extensions |
OLD | NEW |