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

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

Issue 2335213004: [Extensions] Convert some ChromeSyncExtensionFunctions (Closed)
Patch Set: Created 4 years, 3 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
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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 opened_file_item.mode = 107 opened_file_item.mode =
108 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE; 108 extensions::api::file_system_provider::OPEN_FILE_MODE_WRITE;
109 break; 109 break;
110 } 110 }
111 output->opened_files.push_back(std::move(opened_file_item)); 111 output->opened_files.push_back(std::move(opened_file_item));
112 } 112 }
113 } 113 }
114 114
115 } // namespace 115 } // namespace
116 116
117 bool FileSystemProviderMountFunction::RunSync() { 117 ExtensionFunction::ResponseAction FileSystemProviderMountFunction::Run() {
118 using api::file_system_provider::Mount::Params; 118 using api::file_system_provider::Mount::Params;
119 const std::unique_ptr<Params> params(Params::Create(*args_)); 119 const std::unique_ptr<Params> params(Params::Create(*args_));
120 EXTENSION_FUNCTION_VALIDATE(params); 120 EXTENSION_FUNCTION_VALIDATE(params);
121 121
122 // It's an error if the file system Id is empty. 122 // It's an error if the file system Id is empty.
123 if (params->options.file_system_id.empty()) { 123 if (params->options.file_system_id.empty()) {
124 SetError(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)); 124 return RespondNow(
125 return false; 125 Error(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)));
126 } 126 }
127 127
128 // It's an error if the display name is empty. 128 // It's an error if the display name is empty.
129 if (params->options.display_name.empty()) { 129 if (params->options.display_name.empty()) {
130 SetError(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)); 130 return RespondNow(
131 return false; 131 Error(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)));
132 } 132 }
133 133
134 // If the opened files limit is set, then it must be larger or equal than 0. 134 // If the opened files limit is set, then it must be larger or equal than 0.
135 if (params->options.opened_files_limit.get() && 135 if (params->options.opened_files_limit.get() &&
136 *params->options.opened_files_limit.get() < 0) { 136 *params->options.opened_files_limit.get() < 0) {
137 SetError(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)); 137 return RespondNow(
138 return false; 138 Error(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)));
139 } 139 }
140 140
141 Service* const service = Service::Get(GetProfile()); 141 Service* const service =
142 Service::Get(Profile::FromBrowserContext(browser_context()));
142 DCHECK(service); 143 DCHECK(service);
143 144
144 MountOptions options; 145 MountOptions options;
145 options.file_system_id = params->options.file_system_id; 146 options.file_system_id = params->options.file_system_id;
146 options.display_name = params->options.display_name; 147 options.display_name = params->options.display_name;
147 options.writable = params->options.writable != nullptr; 148 options.writable = params->options.writable != nullptr;
148 options.opened_files_limit = params->options.opened_files_limit.get() 149 options.opened_files_limit = params->options.opened_files_limit.get()
149 ? *params->options.opened_files_limit.get() 150 ? *params->options.opened_files_limit.get()
150 : 0; 151 : 0;
151 options.supports_notify_tag = params->options.supports_notify_tag != nullptr; 152 options.supports_notify_tag = params->options.supports_notify_tag != nullptr;
152 153
153 const base::File::Error result = 154 const base::File::Error result =
154 service->MountFileSystem(extension_id(), options); 155 service->MountFileSystem(extension_id(), options);
155 if (result != base::File::FILE_OK) { 156 if (result != base::File::FILE_OK)
156 SetError(FileErrorToString(result)); 157 return RespondNow(Error(FileErrorToString(result)));
157 return false;
158 }
159 158
160 return true; 159 return RespondNow(NoArguments());
161 } 160 }
162 161
163 bool FileSystemProviderUnmountFunction::RunSync() { 162 ExtensionFunction::ResponseAction FileSystemProviderUnmountFunction::Run() {
164 using api::file_system_provider::Unmount::Params; 163 using api::file_system_provider::Unmount::Params;
165 std::unique_ptr<Params> params(Params::Create(*args_)); 164 std::unique_ptr<Params> params(Params::Create(*args_));
166 EXTENSION_FUNCTION_VALIDATE(params); 165 EXTENSION_FUNCTION_VALIDATE(params);
167 166
168 Service* const service = Service::Get(GetProfile()); 167 Service* const service =
168 Service::Get(Profile::FromBrowserContext(browser_context()));
169 DCHECK(service); 169 DCHECK(service);
170 170
171 const base::File::Error result = 171 const base::File::Error result =
172 service->UnmountFileSystem(extension_id(), params->options.file_system_id, 172 service->UnmountFileSystem(extension_id(), params->options.file_system_id,
173 Service::UNMOUNT_REASON_USER); 173 Service::UNMOUNT_REASON_USER);
174 if (result != base::File::FILE_OK) { 174 if (result != base::File::FILE_OK)
175 SetError(FileErrorToString(result)); 175 return RespondNow(Error(FileErrorToString(result)));
176 return false;
177 }
178 176
179 return true; 177 return RespondNow(NoArguments());
180 } 178 }
181 179
182 bool FileSystemProviderGetAllFunction::RunSync() { 180 ExtensionFunction::ResponseAction FileSystemProviderGetAllFunction::Run() {
183 using api::file_system_provider::FileSystemInfo; 181 using api::file_system_provider::FileSystemInfo;
184 Service* const service = Service::Get(GetProfile()); 182 Service* const service =
183 Service::Get(Profile::FromBrowserContext(browser_context()));
185 DCHECK(service); 184 DCHECK(service);
186 185
187 const std::vector<ProvidedFileSystemInfo> file_systems = 186 const std::vector<ProvidedFileSystemInfo> file_systems =
188 service->GetProvidedFileSystemInfoList(); 187 service->GetProvidedFileSystemInfoList();
189 std::vector<FileSystemInfo> items; 188 std::vector<FileSystemInfo> items;
190 189
191 for (const auto& file_system_info : file_systems) { 190 for (const auto& file_system_info : file_systems) {
192 if (file_system_info.extension_id() == extension_id()) { 191 if (file_system_info.extension_id() == extension_id()) {
193 FileSystemInfo item; 192 FileSystemInfo item;
194 193
195 chromeos::file_system_provider::ProvidedFileSystemInterface* const 194 chromeos::file_system_provider::ProvidedFileSystemInterface* const
196 file_system = 195 file_system =
197 service->GetProvidedFileSystem(file_system_info.extension_id(), 196 service->GetProvidedFileSystem(file_system_info.extension_id(),
198 file_system_info.file_system_id()); 197 file_system_info.file_system_id());
199 DCHECK(file_system); 198 DCHECK(file_system);
200 199
201 FillFileSystemInfo(file_system_info, *file_system->GetWatchers(), 200 FillFileSystemInfo(file_system_info, *file_system->GetWatchers(),
202 file_system->GetOpenedFiles(), &item); 201 file_system->GetOpenedFiles(), &item);
203 items.push_back(std::move(item)); 202 items.push_back(std::move(item));
204 } 203 }
205 } 204 }
206 205
207 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); 206 return RespondNow(
208 return true; 207 ArgumentList(api::file_system_provider::GetAll::Results::Create(items)));
209 } 208 }
210 209
211 bool FileSystemProviderGetFunction::RunSync() { 210 ExtensionFunction::ResponseAction FileSystemProviderGetFunction::Run() {
212 using api::file_system_provider::Get::Params; 211 using api::file_system_provider::Get::Params;
213 std::unique_ptr<Params> params(Params::Create(*args_)); 212 std::unique_ptr<Params> params(Params::Create(*args_));
214 EXTENSION_FUNCTION_VALIDATE(params); 213 EXTENSION_FUNCTION_VALIDATE(params);
215 214
216 using api::file_system_provider::FileSystemInfo; 215 using api::file_system_provider::FileSystemInfo;
217 Service* const service = Service::Get(GetProfile()); 216 Service* const service =
217 Service::Get(Profile::FromBrowserContext(browser_context()));
218 DCHECK(service); 218 DCHECK(service);
219 219
220 chromeos::file_system_provider::ProvidedFileSystemInterface* const 220 chromeos::file_system_provider::ProvidedFileSystemInterface* const
221 file_system = service->GetProvidedFileSystem(extension_id(), 221 file_system = service->GetProvidedFileSystem(extension_id(),
222 params->file_system_id); 222 params->file_system_id);
223 223
224 if (!file_system) { 224 if (!file_system) {
225 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND)); 225 return RespondNow(
226 return false; 226 Error(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND)));
227 } 227 }
228 228
229 FileSystemInfo file_system_info; 229 FileSystemInfo file_system_info;
230 FillFileSystemInfo(file_system->GetFileSystemInfo(), 230 FillFileSystemInfo(file_system->GetFileSystemInfo(),
231 *file_system->GetWatchers(), file_system->GetOpenedFiles(), 231 *file_system->GetWatchers(), file_system->GetOpenedFiles(),
232 &file_system_info); 232 &file_system_info);
233 SetResultList( 233 return RespondNow(ArgumentList(
234 api::file_system_provider::Get::Results::Create(file_system_info)); 234 api::file_system_provider::Get::Results::Create(file_system_info)));
235 return true;
236 } 235 }
237 236
238 bool FileSystemProviderNotifyFunction::RunAsync() { 237 bool FileSystemProviderNotifyFunction::RunAsync() {
239 using api::file_system_provider::Notify::Params; 238 using api::file_system_provider::Notify::Params;
240 std::unique_ptr<Params> params(Params::Create(*args_)); 239 std::unique_ptr<Params> params(Params::Create(*args_));
241 EXTENSION_FUNCTION_VALIDATE(params); 240 EXTENSION_FUNCTION_VALIDATE(params);
242 241
243 Service* const service = Service::Get(GetProfile()); 242 Service* const service = Service::Get(GetProfile());
244 DCHECK(service); 243 DCHECK(service);
245 244
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 using api::file_system_provider_internal::OperationRequestedError::Params; 346 using api::file_system_provider_internal::OperationRequestedError::Params;
348 std::unique_ptr<Params> params(Params::Create(*args_)); 347 std::unique_ptr<Params> params(Params::Create(*args_));
349 EXTENSION_FUNCTION_VALIDATE(params); 348 EXTENSION_FUNCTION_VALIDATE(params);
350 349
351 const base::File::Error error = ProviderErrorToFileError(params->error); 350 const base::File::Error error = ProviderErrorToFileError(params->error);
352 return RejectRequest(RequestValue::CreateForOperationError(std::move(params)), 351 return RejectRequest(RequestValue::CreateForOperationError(std::move(params)),
353 error); 352 error);
354 } 353 }
355 354
356 } // namespace extensions 355 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698