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

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

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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 <string> 8 #include <string>
8 #include <utility> 9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" 16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h"
16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h" 17 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte rface.h"
17 #include "chrome/browser/chromeos/file_system_provider/request_manager.h" 18 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
18 #include "chrome/browser/chromeos/file_system_provider/request_value.h" 19 #include "chrome/browser/chromeos/file_system_provider/request_value.h"
19 #include "chrome/browser/chromeos/file_system_provider/service.h" 20 #include "chrome/browser/chromeos/file_system_provider/service.h"
20 #include "chrome/common/extensions/api/file_system_provider.h" 21 #include "chrome/common/extensions/api/file_system_provider.h"
21 #include "chrome/common/extensions/api/file_system_provider_internal.h" 22 #include "chrome/common/extensions/api/file_system_provider_internal.h"
22 #include "storage/browser/fileapi/watcher_manager.h" 23 #include "storage/browser/fileapi/watcher_manager.h"
(...skipping 30 matching lines...) Expand all
53 // are not used is since they are imperfect, eg. paths are stored as strings. 54 // are not used is since they are imperfect, eg. paths are stored as strings.
54 ProvidedFileSystemObserver::Change ParseChange( 55 ProvidedFileSystemObserver::Change ParseChange(
55 const api::file_system_provider::Change& change) { 56 const api::file_system_provider::Change& change) {
56 ProvidedFileSystemObserver::Change result; 57 ProvidedFileSystemObserver::Change result;
57 result.entry_path = base::FilePath::FromUTF8Unsafe(change.entry_path); 58 result.entry_path = base::FilePath::FromUTF8Unsafe(change.entry_path);
58 result.change_type = ParseChangeType(change.change_type); 59 result.change_type = ParseChangeType(change.change_type);
59 return result; 60 return result;
60 } 61 }
61 62
62 // Converts a list of child changes from the IDL type to a native type. 63 // Converts a list of child changes from the IDL type to a native type.
63 scoped_ptr<ProvidedFileSystemObserver::Changes> ParseChanges( 64 std::unique_ptr<ProvidedFileSystemObserver::Changes> ParseChanges(
64 const std::vector<api::file_system_provider::Change>& changes) { 65 const std::vector<api::file_system_provider::Change>& changes) {
65 scoped_ptr<ProvidedFileSystemObserver::Changes> results( 66 std::unique_ptr<ProvidedFileSystemObserver::Changes> results(
66 new ProvidedFileSystemObserver::Changes); 67 new ProvidedFileSystemObserver::Changes);
67 for (const auto& change : changes) { 68 for (const auto& change : changes) {
68 results->push_back(ParseChange(change)); 69 results->push_back(ParseChange(change));
69 } 70 }
70 return results; 71 return results;
71 } 72 }
72 73
73 // Fills the IDL's FileSystemInfo with FSP's ProvidedFileSystemInfo and 74 // Fills the IDL's FileSystemInfo with FSP's ProvidedFileSystemInfo and
74 // Watchers. 75 // Watchers.
75 void FillFileSystemInfo(const ProvidedFileSystemInfo& file_system_info, 76 void FillFileSystemInfo(const ProvidedFileSystemInfo& file_system_info,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 break; 109 break;
109 } 110 }
110 output->opened_files.push_back(std::move(opened_file_item)); 111 output->opened_files.push_back(std::move(opened_file_item));
111 } 112 }
112 } 113 }
113 114
114 } // namespace 115 } // namespace
115 116
116 bool FileSystemProviderMountFunction::RunSync() { 117 bool FileSystemProviderMountFunction::RunSync() {
117 using api::file_system_provider::Mount::Params; 118 using api::file_system_provider::Mount::Params;
118 const scoped_ptr<Params> params(Params::Create(*args_)); 119 const std::unique_ptr<Params> params(Params::Create(*args_));
119 EXTENSION_FUNCTION_VALIDATE(params); 120 EXTENSION_FUNCTION_VALIDATE(params);
120 121
121 // It's an error if the file system Id is empty. 122 // It's an error if the file system Id is empty.
122 if (params->options.file_system_id.empty()) { 123 if (params->options.file_system_id.empty()) {
123 SetError(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION)); 124 SetError(FileErrorToString(base::File::FILE_ERROR_INVALID_OPERATION));
124 return false; 125 return false;
125 } 126 }
126 127
127 // It's an error if the display name is empty. 128 // It's an error if the display name is empty.
128 if (params->options.display_name.empty()) { 129 if (params->options.display_name.empty()) {
(...skipping 25 matching lines...) Expand all
154 if (result != base::File::FILE_OK) { 155 if (result != base::File::FILE_OK) {
155 SetError(FileErrorToString(result)); 156 SetError(FileErrorToString(result));
156 return false; 157 return false;
157 } 158 }
158 159
159 return true; 160 return true;
160 } 161 }
161 162
162 bool FileSystemProviderUnmountFunction::RunSync() { 163 bool FileSystemProviderUnmountFunction::RunSync() {
163 using api::file_system_provider::Unmount::Params; 164 using api::file_system_provider::Unmount::Params;
164 scoped_ptr<Params> params(Params::Create(*args_)); 165 std::unique_ptr<Params> params(Params::Create(*args_));
165 EXTENSION_FUNCTION_VALIDATE(params); 166 EXTENSION_FUNCTION_VALIDATE(params);
166 167
167 Service* const service = Service::Get(GetProfile()); 168 Service* const service = Service::Get(GetProfile());
168 DCHECK(service); 169 DCHECK(service);
169 170
170 const base::File::Error result = 171 const base::File::Error result =
171 service->UnmountFileSystem(extension_id(), params->options.file_system_id, 172 service->UnmountFileSystem(extension_id(), params->options.file_system_id,
172 Service::UNMOUNT_REASON_USER); 173 Service::UNMOUNT_REASON_USER);
173 if (result != base::File::FILE_OK) { 174 if (result != base::File::FILE_OK) {
174 SetError(FileErrorToString(result)); 175 SetError(FileErrorToString(result));
(...skipping 27 matching lines...) Expand all
202 items.push_back(std::move(item)); 203 items.push_back(std::move(item));
203 } 204 }
204 } 205 }
205 206
206 SetResultList(api::file_system_provider::GetAll::Results::Create(items)); 207 SetResultList(api::file_system_provider::GetAll::Results::Create(items));
207 return true; 208 return true;
208 } 209 }
209 210
210 bool FileSystemProviderGetFunction::RunSync() { 211 bool FileSystemProviderGetFunction::RunSync() {
211 using api::file_system_provider::Get::Params; 212 using api::file_system_provider::Get::Params;
212 scoped_ptr<Params> params(Params::Create(*args_)); 213 std::unique_ptr<Params> params(Params::Create(*args_));
213 EXTENSION_FUNCTION_VALIDATE(params); 214 EXTENSION_FUNCTION_VALIDATE(params);
214 215
215 using api::file_system_provider::FileSystemInfo; 216 using api::file_system_provider::FileSystemInfo;
216 Service* const service = Service::Get(GetProfile()); 217 Service* const service = Service::Get(GetProfile());
217 DCHECK(service); 218 DCHECK(service);
218 219
219 chromeos::file_system_provider::ProvidedFileSystemInterface* const 220 chromeos::file_system_provider::ProvidedFileSystemInterface* const
220 file_system = service->GetProvidedFileSystem(extension_id(), 221 file_system = service->GetProvidedFileSystem(extension_id(),
221 params->file_system_id); 222 params->file_system_id);
222 223
223 if (!file_system) { 224 if (!file_system) {
224 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND)); 225 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND));
225 return false; 226 return false;
226 } 227 }
227 228
228 FileSystemInfo file_system_info; 229 FileSystemInfo file_system_info;
229 FillFileSystemInfo(file_system->GetFileSystemInfo(), 230 FillFileSystemInfo(file_system->GetFileSystemInfo(),
230 *file_system->GetWatchers(), file_system->GetOpenedFiles(), 231 *file_system->GetWatchers(), file_system->GetOpenedFiles(),
231 &file_system_info); 232 &file_system_info);
232 SetResultList( 233 SetResultList(
233 api::file_system_provider::Get::Results::Create(file_system_info)); 234 api::file_system_provider::Get::Results::Create(file_system_info));
234 return true; 235 return true;
235 } 236 }
236 237
237 bool FileSystemProviderNotifyFunction::RunAsync() { 238 bool FileSystemProviderNotifyFunction::RunAsync() {
238 using api::file_system_provider::Notify::Params; 239 using api::file_system_provider::Notify::Params;
239 scoped_ptr<Params> params(Params::Create(*args_)); 240 std::unique_ptr<Params> params(Params::Create(*args_));
240 EXTENSION_FUNCTION_VALIDATE(params); 241 EXTENSION_FUNCTION_VALIDATE(params);
241 242
242 Service* const service = Service::Get(GetProfile()); 243 Service* const service = Service::Get(GetProfile());
243 DCHECK(service); 244 DCHECK(service);
244 245
245 ProvidedFileSystemInterface* const file_system = 246 ProvidedFileSystemInterface* const file_system =
246 service->GetProvidedFileSystem(extension_id(), 247 service->GetProvidedFileSystem(extension_id(),
247 params->options.file_system_id); 248 params->options.file_system_id);
248 if (!file_system) { 249 if (!file_system) {
249 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND)); 250 SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND));
250 return false; 251 return false;
251 } 252 }
252 253
253 file_system->Notify( 254 file_system->Notify(
254 base::FilePath::FromUTF8Unsafe(params->options.observed_path), 255 base::FilePath::FromUTF8Unsafe(params->options.observed_path),
255 params->options.recursive, ParseChangeType(params->options.change_type), 256 params->options.recursive, ParseChangeType(params->options.change_type),
256 params->options.changes.get() 257 params->options.changes.get()
257 ? ParseChanges(*params->options.changes.get()) 258 ? ParseChanges(*params->options.changes.get())
258 : make_scoped_ptr(new ProvidedFileSystemObserver::Changes), 259 : base::WrapUnique(new ProvidedFileSystemObserver::Changes),
259 params->options.tag.get() ? *params->options.tag.get() : "", 260 params->options.tag.get() ? *params->options.tag.get() : "",
260 base::Bind(&FileSystemProviderNotifyFunction::OnNotifyCompleted, this)); 261 base::Bind(&FileSystemProviderNotifyFunction::OnNotifyCompleted, this));
261 262
262 return true; 263 return true;
263 } 264 }
264 265
265 void FileSystemProviderNotifyFunction::OnNotifyCompleted( 266 void FileSystemProviderNotifyFunction::OnNotifyCompleted(
266 base::File::Error result) { 267 base::File::Error result) {
267 if (result != base::File::FILE_OK) { 268 if (result != base::File::FILE_OK) {
268 SetError(FileErrorToString(result)); 269 SetError(FileErrorToString(result));
269 SendResponse(false); 270 SendResponse(false);
270 return; 271 return;
271 } 272 }
272 273
273 SendResponse(true); 274 SendResponse(true);
274 } 275 }
275 276
276 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() { 277 bool FileSystemProviderInternalUnmountRequestedSuccessFunction::RunWhenValid() {
277 using api::file_system_provider_internal::UnmountRequestedSuccess::Params; 278 using api::file_system_provider_internal::UnmountRequestedSuccess::Params;
278 scoped_ptr<Params> params(Params::Create(*args_)); 279 std::unique_ptr<Params> params(Params::Create(*args_));
279 EXTENSION_FUNCTION_VALIDATE(params); 280 EXTENSION_FUNCTION_VALIDATE(params);
280 281
281 return FulfillRequest( 282 return FulfillRequest(
282 RequestValue::CreateForUnmountSuccess(std::move(params)), 283 RequestValue::CreateForUnmountSuccess(std::move(params)),
283 false /* has_more */); 284 false /* has_more */);
284 } 285 }
285 286
286 bool 287 bool
287 FileSystemProviderInternalGetMetadataRequestedSuccessFunction::RunWhenValid() { 288 FileSystemProviderInternalGetMetadataRequestedSuccessFunction::RunWhenValid() {
288 using api::file_system_provider_internal::GetMetadataRequestedSuccess::Params; 289 using api::file_system_provider_internal::GetMetadataRequestedSuccess::Params;
289 scoped_ptr<Params> params(Params::Create(*args_)); 290 std::unique_ptr<Params> params(Params::Create(*args_));
290 EXTENSION_FUNCTION_VALIDATE(params); 291 EXTENSION_FUNCTION_VALIDATE(params);
291 292
292 return FulfillRequest( 293 return FulfillRequest(
293 RequestValue::CreateForGetMetadataSuccess(std::move(params)), 294 RequestValue::CreateForGetMetadataSuccess(std::move(params)),
294 false /* has_more */); 295 false /* has_more */);
295 } 296 }
296 297
297 bool FileSystemProviderInternalGetActionsRequestedSuccessFunction:: 298 bool FileSystemProviderInternalGetActionsRequestedSuccessFunction::
298 RunWhenValid() { 299 RunWhenValid() {
299 using api::file_system_provider_internal::GetActionsRequestedSuccess::Params; 300 using api::file_system_provider_internal::GetActionsRequestedSuccess::Params;
300 scoped_ptr<Params> params(Params::Create(*args_)); 301 std::unique_ptr<Params> params(Params::Create(*args_));
301 EXTENSION_FUNCTION_VALIDATE(params); 302 EXTENSION_FUNCTION_VALIDATE(params);
302 303
303 return FulfillRequest( 304 return FulfillRequest(
304 RequestValue::CreateForGetActionsSuccess(std::move(params)), 305 RequestValue::CreateForGetActionsSuccess(std::move(params)),
305 false /* has_more */); 306 false /* has_more */);
306 } 307 }
307 308
308 bool FileSystemProviderInternalReadDirectoryRequestedSuccessFunction:: 309 bool FileSystemProviderInternalReadDirectoryRequestedSuccessFunction::
309 RunWhenValid() { 310 RunWhenValid() {
310 using api::file_system_provider_internal::ReadDirectoryRequestedSuccess:: 311 using api::file_system_provider_internal::ReadDirectoryRequestedSuccess::
311 Params; 312 Params;
312 scoped_ptr<Params> params(Params::Create(*args_)); 313 std::unique_ptr<Params> params(Params::Create(*args_));
313 EXTENSION_FUNCTION_VALIDATE(params); 314 EXTENSION_FUNCTION_VALIDATE(params);
314 315
315 const bool has_more = params->has_more; 316 const bool has_more = params->has_more;
316 return FulfillRequest( 317 return FulfillRequest(
317 RequestValue::CreateForReadDirectorySuccess(std::move(params)), has_more); 318 RequestValue::CreateForReadDirectorySuccess(std::move(params)), has_more);
318 } 319 }
319 320
320 bool 321 bool
321 FileSystemProviderInternalReadFileRequestedSuccessFunction::RunWhenValid() { 322 FileSystemProviderInternalReadFileRequestedSuccessFunction::RunWhenValid() {
322 TRACE_EVENT0("file_system_provider", "ReadFileRequestedSuccess"); 323 TRACE_EVENT0("file_system_provider", "ReadFileRequestedSuccess");
323 using api::file_system_provider_internal::ReadFileRequestedSuccess::Params; 324 using api::file_system_provider_internal::ReadFileRequestedSuccess::Params;
324 325
325 scoped_ptr<Params> params(Params::Create(*args_)); 326 std::unique_ptr<Params> params(Params::Create(*args_));
326 EXTENSION_FUNCTION_VALIDATE(params); 327 EXTENSION_FUNCTION_VALIDATE(params);
327 328
328 const bool has_more = params->has_more; 329 const bool has_more = params->has_more;
329 return FulfillRequest( 330 return FulfillRequest(
330 RequestValue::CreateForReadFileSuccess(std::move(params)), has_more); 331 RequestValue::CreateForReadFileSuccess(std::move(params)), has_more);
331 } 332 }
332 333
333 bool 334 bool
334 FileSystemProviderInternalOperationRequestedSuccessFunction::RunWhenValid() { 335 FileSystemProviderInternalOperationRequestedSuccessFunction::RunWhenValid() {
335 using api::file_system_provider_internal::OperationRequestedSuccess::Params; 336 using api::file_system_provider_internal::OperationRequestedSuccess::Params;
336 scoped_ptr<Params> params(Params::Create(*args_)); 337 std::unique_ptr<Params> params(Params::Create(*args_));
337 EXTENSION_FUNCTION_VALIDATE(params); 338 EXTENSION_FUNCTION_VALIDATE(params);
338 339
339 return FulfillRequest( 340 return FulfillRequest(
340 scoped_ptr<RequestValue>( 341 std::unique_ptr<RequestValue>(
341 RequestValue::CreateForOperationSuccess(std::move(params))), 342 RequestValue::CreateForOperationSuccess(std::move(params))),
342 false /* has_more */); 343 false /* has_more */);
343 } 344 }
344 345
345 bool FileSystemProviderInternalOperationRequestedErrorFunction::RunWhenValid() { 346 bool FileSystemProviderInternalOperationRequestedErrorFunction::RunWhenValid() {
346 using api::file_system_provider_internal::OperationRequestedError::Params; 347 using api::file_system_provider_internal::OperationRequestedError::Params;
347 scoped_ptr<Params> params(Params::Create(*args_)); 348 std::unique_ptr<Params> params(Params::Create(*args_));
348 EXTENSION_FUNCTION_VALIDATE(params); 349 EXTENSION_FUNCTION_VALIDATE(params);
349 350
350 const base::File::Error error = ProviderErrorToFileError(params->error); 351 const base::File::Error error = ProviderErrorToFileError(params->error);
351 return RejectRequest(RequestValue::CreateForOperationError(std::move(params)), 352 return RejectRequest(RequestValue::CreateForOperationError(std::move(params)),
352 error); 353 error);
353 } 354 }
354 355
355 } // namespace extensions 356 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698