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 #include <vector> | |
8 | 9 |
9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/memory/linked_ptr.h" | |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/values.h" | 13 #include "base/values.h" |
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" | 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" |
13 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" | 15 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" |
14 #include "chrome/browser/chromeos/file_system_provider/request_value.h" | 16 #include "chrome/browser/chromeos/file_system_provider/request_value.h" |
15 #include "chrome/browser/chromeos/file_system_provider/service.h" | 17 #include "chrome/browser/chromeos/file_system_provider/service.h" |
16 #include "chrome/common/extensions/api/file_system_provider.h" | 18 #include "chrome/common/extensions/api/file_system_provider.h" |
17 #include "chrome/common/extensions/api/file_system_provider_internal.h" | 19 #include "chrome/common/extensions/api/file_system_provider_internal.h" |
18 | 20 |
21 using chromeos::file_system_provider::ProvidedFileSystemInfo; | |
19 using chromeos::file_system_provider::ProvidedFileSystemInterface; | 22 using chromeos::file_system_provider::ProvidedFileSystemInterface; |
20 using chromeos::file_system_provider::RequestValue; | 23 using chromeos::file_system_provider::RequestValue; |
21 using chromeos::file_system_provider::Service; | 24 using chromeos::file_system_provider::Service; |
22 | 25 |
23 namespace extensions { | 26 namespace extensions { |
24 | 27 |
25 bool FileSystemProviderMountFunction::RunSync() { | 28 bool FileSystemProviderMountFunction::RunSync() { |
26 using api::file_system_provider::Mount::Params; | 29 using api::file_system_provider::Mount::Params; |
27 const scoped_ptr<Params> params(Params::Create(*args_)); | 30 const scoped_ptr<Params> params(Params::Create(*args_)); |
28 EXTENSION_FUNCTION_VALIDATE(params); | 31 EXTENSION_FUNCTION_VALIDATE(params); |
29 | 32 |
30 // It's an error if the file system Id is empty. | 33 // It's an error if the file system Id is empty. |
31 if (params->options.file_system_id.empty()) { | 34 if (params->options.file_system_id.empty()) { |
32 base::ListValue* result = new base::ListValue(); | 35 base::ListValue* const result = new base::ListValue(); |
33 result->Append(CreateError(kSecurityErrorName, kEmptyIdErrorMessage)); | 36 result->Append(CreateError(kSecurityErrorName, kEmptyIdErrorMessage)); |
34 SetResult(result); | 37 SetResult(result); |
35 return true; | 38 return true; |
36 } | 39 } |
37 | 40 |
38 // It's an error if the display name is empty. | 41 // It's an error if the display name is empty. |
39 if (params->options.display_name.empty()) { | 42 if (params->options.display_name.empty()) { |
40 base::ListValue* result = new base::ListValue(); | 43 base::ListValue* const result = new base::ListValue(); |
41 result->Append(CreateError(kSecurityErrorName, | 44 result->Append(CreateError(kSecurityErrorName, |
42 kEmptyNameErrorMessage)); | 45 kEmptyNameErrorMessage)); |
43 SetResult(result); | 46 SetResult(result); |
44 return true; | 47 return true; |
45 } | 48 } |
46 | 49 |
47 Service* service = Service::Get(GetProfile()); | 50 Service* const service = Service::Get(GetProfile()); |
48 DCHECK(service); | 51 DCHECK(service); |
49 if (!service) | 52 if (!service) |
50 return false; | 53 return false; |
51 | 54 |
52 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 55 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
53 if (!service->MountFileSystem(extension_id(), | 56 if (!service->MountFileSystem(extension_id(), |
54 params->options.file_system_id, | 57 params->options.file_system_id, |
55 params->options.display_name, | 58 params->options.display_name, |
56 params->options.writable)) { | 59 params->options.writable)) { |
57 base::ListValue* result = new base::ListValue(); | 60 base::ListValue* const result = new base::ListValue(); |
58 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); | 61 result->Append(CreateError(kSecurityErrorName, kMountFailedErrorMessage)); |
59 SetResult(result); | 62 SetResult(result); |
60 return true; | 63 return true; |
61 } | 64 } |
62 | 65 |
63 base::ListValue* result = new base::ListValue(); | 66 base::ListValue* result = new base::ListValue(); |
64 SetResult(result); | 67 SetResult(result); |
65 return true; | 68 return true; |
66 } | 69 } |
67 | 70 |
68 bool FileSystemProviderUnmountFunction::RunSync() { | 71 bool FileSystemProviderUnmountFunction::RunSync() { |
69 using api::file_system_provider::Unmount::Params; | 72 using api::file_system_provider::Unmount::Params; |
70 scoped_ptr<Params> params(Params::Create(*args_)); | 73 scoped_ptr<Params> params(Params::Create(*args_)); |
71 EXTENSION_FUNCTION_VALIDATE(params); | 74 EXTENSION_FUNCTION_VALIDATE(params); |
72 | 75 |
73 Service* service = Service::Get(GetProfile()); | 76 Service* const service = Service::Get(GetProfile()); |
74 DCHECK(service); | 77 DCHECK(service); |
75 if (!service) | 78 if (!service) |
76 return false; | 79 return false; |
77 | 80 |
78 if (!service->UnmountFileSystem(extension_id(), | 81 if (!service->UnmountFileSystem(extension_id(), |
79 params->options.file_system_id, | 82 params->options.file_system_id, |
80 Service::UNMOUNT_REASON_USER)) { | 83 Service::UNMOUNT_REASON_USER)) { |
81 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. | 84 // TODO(mtomasz): Pass more detailed errors, rather than just a bool. |
82 base::ListValue* result = new base::ListValue(); | 85 base::ListValue* result = new base::ListValue(); |
83 result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage)); | 86 result->Append(CreateError(kSecurityErrorName, kUnmountFailedErrorMessage)); |
84 SetResult(result); | 87 SetResult(result); |
85 return true; | 88 return true; |
86 } | 89 } |
87 | 90 |
88 base::ListValue* result = new base::ListValue(); | 91 base::ListValue* const result = new base::ListValue(); |
89 SetResult(result); | 92 SetResult(result); |
90 return true; | 93 return true; |
91 } | 94 } |
92 | 95 |
96 bool FileSystemProviderGetAllFunction::RunSync() { | |
97 using api::file_system_provider::FileSystemInfo; | |
98 Service* const service = Service::Get(GetProfile()); | |
99 DCHECK(service); | |
100 if (!service) | |
101 return false; | |
102 | |
103 const std::vector<ProvidedFileSystemInfo> file_systems = | |
104 service->GetProvidedFileSystemInfoList(); | |
105 std::vector<linked_ptr<FileSystemInfo> > items; | |
106 | |
107 for (size_t i = 0; i < file_systems.size(); ++i) { | |
108 scoped_ptr<FileSystemInfo> item(new FileSystemInfo); | |
hirono
2014/08/14 11:45:32
How about turning it to linked_ptr. We can push it
mtomasz
2014/08/15 03:36:03
Done.
| |
109 item->file_system_id = file_systems[i].file_system_id(); | |
110 item->display_name = file_systems[i].display_name(); | |
111 item->writable = file_systems[i].writable(); | |
112 items.push_back(make_linked_ptr(item.release())); | |
113 } | |
114 | |
115 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); | |
116 return true; | |
117 } | |
118 | |
93 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { | 119 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { |
94 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; | 120 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; |
95 scoped_ptr<Params> params(Params::Create(*args_)); | 121 scoped_ptr<Params> params(Params::Create(*args_)); |
96 EXTENSION_FUNCTION_VALIDATE(params); | 122 EXTENSION_FUNCTION_VALIDATE(params); |
97 | 123 |
98 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), | 124 FulfillRequest(RequestValue::CreateForUnmountSuccess(params.Pass()), |
99 false /* has_more */); | 125 false /* has_more */); |
100 return true; | 126 return true; |
101 } | 127 } |
102 | 128 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 using api::file_system_provider_internal::OperationRequestedError::Params; | 180 using api::file_system_provider_internal::OperationRequestedError::Params; |
155 scoped_ptr<Params> params(Params::Create(*args_)); | 181 scoped_ptr<Params> params(Params::Create(*args_)); |
156 EXTENSION_FUNCTION_VALIDATE(params); | 182 EXTENSION_FUNCTION_VALIDATE(params); |
157 | 183 |
158 const base::File::Error error = ProviderErrorToFileError(params->error); | 184 const base::File::Error error = ProviderErrorToFileError(params->error); |
159 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); | 185 RejectRequest(RequestValue::CreateForOperationError(params.Pass()), error); |
160 return true; | 186 return true; |
161 } | 187 } |
162 | 188 |
163 } // namespace extensions | 189 } // namespace extensions |
OLD | NEW |