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

Side by Side Diff: chrome/browser/extensions/api/file_system/file_system_api.cc

Issue 23629033: Fix a crash in the FileSystem API when the app window closes during a call. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
6 6
7 #include "apps/saved_files_service.h" 7 #include "apps/saved_files_service.h"
8 #include "apps/shell_window.h" 8 #include "apps/shell_window.h"
9 #include "apps/shell_window_registry.h" 9 #include "apps/shell_window_registry.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 std::string filesystem_id; 157 std::string filesystem_id;
158 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { 158 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) {
159 *error = kInvalidParameters; 159 *error = kInvalidParameters;
160 return false; 160 return false;
161 } 161 }
162 162
163 // Only return the display path if the process has read access to the 163 // Only return the display path if the process has read access to the
164 // filesystem. 164 // filesystem.
165 content::ChildProcessSecurityPolicy* policy = 165 content::ChildProcessSecurityPolicy* policy =
166 content::ChildProcessSecurityPolicy::GetInstance(); 166 content::ChildProcessSecurityPolicy::GetInstance();
167 DCHECK(render_view_host);
benwells 2013/09/10 00:47:14 Why add all these DCHECKs?
Sam McNally 2013/09/10 01:04:13 No real reason.
167 if (!policy->CanReadFileSystem(render_view_host->GetProcess()->GetID(), 168 if (!policy->CanReadFileSystem(render_view_host->GetProcess()->GetID(),
168 filesystem_id)) { 169 filesystem_id)) {
169 *error = kSecurityError; 170 *error = kSecurityError;
170 return false; 171 return false;
171 } 172 }
172 173
173 IsolatedContext* context = IsolatedContext::GetInstance(); 174 IsolatedContext* context = IsolatedContext::GetInstance();
174 base::FilePath relative_path = 175 base::FilePath relative_path =
175 base::FilePath::FromUTF8Unsafe(filesystem_path); 176 base::FilePath::FromUTF8Unsafe(filesystem_path);
176 base::FilePath virtual_path = context->CreateVirtualRootPath(filesystem_id) 177 base::FilePath virtual_path = context->CreateVirtualRootPath(filesystem_id)
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 is_directory_, 333 is_directory_,
333 base::Bind(&FileSystemEntryFunction::RegisterFileSystemsAndSendResponse, 334 base::Bind(&FileSystemEntryFunction::RegisterFileSystemsAndSendResponse,
334 this, 335 this,
335 paths), 336 paths),
336 base::Bind(&FileSystemEntryFunction::HandleWritableFileError, this)); 337 base::Bind(&FileSystemEntryFunction::HandleWritableFileError, this));
337 } 338 }
338 339
339 void FileSystemEntryFunction::RegisterFileSystemsAndSendResponse( 340 void FileSystemEntryFunction::RegisterFileSystemsAndSendResponse(
340 const std::vector<base::FilePath>& paths) { 341 const std::vector<base::FilePath>& paths) {
341 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 342 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
343 if (!render_view_host_)
344 return;
342 345
343 CreateResponse(); 346 CreateResponse();
344 for (std::vector<base::FilePath>::const_iterator it = paths.begin(); 347 for (std::vector<base::FilePath>::const_iterator it = paths.begin();
345 it != paths.end(); ++it) { 348 it != paths.end(); ++it) {
346 AddEntryToResponse(*it, ""); 349 AddEntryToResponse(*it, "");
347 } 350 }
348 SendResponse(true); 351 SendResponse(true);
349 } 352 }
350 353
351 void FileSystemEntryFunction::CreateResponse() { 354 void FileSystemEntryFunction::CreateResponse() {
352 DCHECK(!response_); 355 DCHECK(!response_);
353 response_ = new base::DictionaryValue(); 356 response_ = new base::DictionaryValue();
354 base::ListValue* list = new base::ListValue(); 357 base::ListValue* list = new base::ListValue();
355 response_->Set("entries", list); 358 response_->Set("entries", list);
356 response_->SetBoolean("multiple", multiple_); 359 response_->SetBoolean("multiple", multiple_);
357 SetResult(response_); 360 SetResult(response_);
358 } 361 }
359 362
360 void FileSystemEntryFunction::AddEntryToResponse( 363 void FileSystemEntryFunction::AddEntryToResponse(
361 const base::FilePath& path, 364 const base::FilePath& path,
362 const std::string& id_override) { 365 const std::string& id_override) {
363 DCHECK(response_); 366 DCHECK(response_);
367 DCHECK(render_view_host_);
364 extensions::app_file_handler_util::GrantedFileEntry file_entry = 368 extensions::app_file_handler_util::GrantedFileEntry file_entry =
365 extensions::app_file_handler_util::CreateFileEntry( 369 extensions::app_file_handler_util::CreateFileEntry(
366 profile(), 370 profile(),
367 GetExtension(), 371 GetExtension(),
368 render_view_host_->GetProcess()->GetID(), 372 render_view_host_->GetProcess()->GetID(),
369 path, 373 path,
370 is_directory_); 374 is_directory_);
371 base::ListValue* entries; 375 base::ListValue* entries;
372 bool success = response_->GetList("entries", &entries); 376 bool success = response_->GetList("entries", &entries);
373 DCHECK(success); 377 DCHECK(success);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); 448 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path));
445 449
446 std::string filesystem_id; 450 std::string filesystem_id;
447 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { 451 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) {
448 error_ = kInvalidParameters; 452 error_ = kInvalidParameters;
449 return false; 453 return false;
450 } 454 }
451 455
452 content::ChildProcessSecurityPolicy* policy = 456 content::ChildProcessSecurityPolicy* policy =
453 content::ChildProcessSecurityPolicy::GetInstance(); 457 content::ChildProcessSecurityPolicy::GetInstance();
458 DCHECK(render_view_host_);
454 int renderer_id = render_view_host_->GetProcess()->GetID(); 459 int renderer_id = render_view_host_->GetProcess()->GetID();
455 bool is_writable = policy->CanReadWriteFileSystem(renderer_id, 460 bool is_writable = policy->CanReadWriteFileSystem(renderer_id,
456 filesystem_id); 461 filesystem_id);
457 462
458 SetResult(new base::FundamentalValue(is_writable)); 463 SetResult(new base::FundamentalValue(is_writable));
459 return true; 464 return true;
460 } 465 }
461 466
462 // Handles showing a dialog to the user to ask for the filename for a file to 467 // Handles showing a dialog to the user to ask for the filename for a file to
463 // save or open. 468 // save or open.
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 if (needs_new_entry) { 1010 if (needs_new_entry) {
1006 is_directory_ = file_entry->is_directory; 1011 is_directory_ = file_entry->is_directory;
1007 CreateResponse(); 1012 CreateResponse();
1008 AddEntryToResponse(file_entry->path, file_entry->id); 1013 AddEntryToResponse(file_entry->path, file_entry->id);
1009 } 1014 }
1010 SendResponse(true); 1015 SendResponse(true);
1011 return true; 1016 return true;
1012 } 1017 }
1013 1018
1014 } // namespace extensions 1019 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698