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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/file_browser_handler_api.cc

Issue 242443004: Remove thread restriction of fileapi::FileSystemContext::ResolveURL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Return non-error for absent entry Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // The file contains the implementation of 5 // The file contains the implementation of
6 // fileBrowserHandlerInternal.selectFile extension function. 6 // fileBrowserHandlerInternal.selectFile extension function.
7 // When invoked, the function does the following: 7 // When invoked, the function does the following:
8 // - Verifies that the extension function was invoked as a result of user 8 // - Verifies that the extension function was invoked as a result of user
9 // gesture. 9 // gesture.
10 // - Display 'save as' dialog using FileSelectorImpl which waits for the user 10 // - Display 'save as' dialog using FileSelectorImpl which waits for the user
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 file_manager::util::GetFileSystemContextForRenderViewHost( 319 file_manager::util::GetFileSystemContextForRenderViewHost(
320 GetProfile(), render_view_host())->external_backend(); 320 GetProfile(), render_view_host())->external_backend();
321 DCHECK(external_backend); 321 DCHECK(external_backend);
322 322
323 FileDefinition file_definition; 323 FileDefinition file_definition;
324 file_definition.is_directory = false; 324 file_definition.is_directory = false;
325 325
326 external_backend->GetVirtualPath(full_path, &file_definition.virtual_path); 326 external_backend->GetVirtualPath(full_path, &file_definition.virtual_path);
327 DCHECK(!file_definition.virtual_path.empty()); 327 DCHECK(!file_definition.virtual_path.empty());
328 328
329 file_manager::util::ConvertFileDefinitionToEntryDefinition(
330 GetProfile(),
331 extension_id(),
332 file_definition,
333 base::Bind(
334 &FileBrowserHandlerInternalSelectFileFunction::GrantPermissions,
335 this,
336 full_path,
337 file_definition));
338 }
339
340 void FileBrowserHandlerInternalSelectFileFunction::GrantPermissions(
341 const base::FilePath& full_path,
342 const FileDefinition& file_definition,
343 const EntryDefinition& entry_definition) {
344 fileapi::ExternalFileSystemBackend* external_backend =
345 file_manager::util::GetFileSystemContextForRenderViewHost(
346 GetProfile(), render_view_host())->external_backend();
347 DCHECK(external_backend);
348
349 // Grant access to this particular file to target extension. This will 329 // Grant access to this particular file to target extension. This will
350 // ensure that the target extension can access only this FS entry and 330 // ensure that the target extension can access only this FS entry and
351 // prevent from traversing FS hierarchy upward. 331 // prevent from traversing FS hierarchy upward.
352 external_backend->GrantFileAccessToExtension(extension_id(), 332 external_backend->GrantFileAccessToExtension(extension_id(),
353 file_definition.virtual_path); 333 file_definition.virtual_path);
354 334
355 // Grant access to the selected file to target extensions render view process. 335 // Grant access to the selected file to target extensions render view process.
356 content::ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile( 336 content::ChildProcessSecurityPolicy::GetInstance()->GrantCreateReadWriteFile(
357 render_view_host()->GetProcess()->GetID(), full_path); 337 render_view_host()->GetProcess()->GetID(), full_path);
358 338
339 file_manager::util::ConvertFileDefinitionToEntryDefinition(
340 GetProfile(),
341 extension_id(),
342 file_definition,
343 base::Bind(
344 &FileBrowserHandlerInternalSelectFileFunction::RespondEntryDefinition,
345 this));
346 }
347
348 void FileBrowserHandlerInternalSelectFileFunction::RespondEntryDefinition(
349 const EntryDefinition& entry_definition) {
359 Respond(entry_definition, true); 350 Respond(entry_definition, true);
360 } 351 }
361 352
362 void FileBrowserHandlerInternalSelectFileFunction::Respond( 353 void FileBrowserHandlerInternalSelectFileFunction::Respond(
363 const EntryDefinition& entry_definition, 354 const EntryDefinition& entry_definition,
364 bool success) { 355 bool success) {
365 scoped_ptr<SelectFile::Results::Result> result( 356 scoped_ptr<SelectFile::Results::Result> result(
366 new SelectFile::Results::Result()); 357 new SelectFile::Results::Result());
367 result->success = success; 358 result->success = success;
368 359
369 // If the file was selected, add 'entry' object which will be later used to 360 // If the file was selected, add 'entry' object which will be later used to
370 // create a FileEntry instance for the selected file. 361 // create a FileEntry instance for the selected file.
371 if (success && entry_definition.error == base::File::FILE_OK) { 362 if (success && entry_definition.error == base::File::FILE_OK) {
372 result->entry.reset(new FileEntryInfo()); 363 result->entry.reset(new FileEntryInfo());
373 // TODO(mtomasz): Make the response fields consistent with other files. 364 // TODO(mtomasz): Make the response fields consistent with other files.
374 result->entry->file_system_name = entry_definition.file_system_name; 365 result->entry->file_system_name = entry_definition.file_system_name;
375 result->entry->file_system_root = entry_definition.file_system_root_url; 366 result->entry->file_system_root = entry_definition.file_system_root_url;
376 result->entry->file_full_path = 367 result->entry->file_full_path =
377 "/" + entry_definition.full_path.AsUTF8Unsafe(); 368 "/" + entry_definition.full_path.AsUTF8Unsafe();
378 result->entry->file_is_directory = entry_definition.is_directory; 369 result->entry->file_is_directory = entry_definition.is_directory;
379 } 370 }
380 371
381 results_ = SelectFile::Results::Create(*result); 372 results_ = SelectFile::Results::Create(*result);
382 SendResponse(true); 373 SendResponse(true);
383 } 374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698