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

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

Issue 2351823004: [Extensions] Consolidate ExtensionFunction::SendResponse()s (Closed)
Patch Set: ready 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 (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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1323
1324 void FileSystemRequestFileSystemFunction::OnConsentReceived( 1324 void FileSystemRequestFileSystemFunction::OnConsentReceived(
1325 const base::WeakPtr<file_manager::Volume>& volume, 1325 const base::WeakPtr<file_manager::Volume>& volume,
1326 bool writable, 1326 bool writable,
1327 ConsentProvider::Consent result) { 1327 ConsentProvider::Consent result) {
1328 using file_manager::VolumeManager; 1328 using file_manager::VolumeManager;
1329 using file_manager::Volume; 1329 using file_manager::Volume;
1330 1330
1331 switch (result) { 1331 switch (result) {
1332 case ConsentProvider::CONSENT_REJECTED: 1332 case ConsentProvider::CONSENT_REJECTED:
1333 SetError(kSecurityError); 1333 Respond(Error(kSecurityError));
1334 SendResponse(false);
1335 return; 1334 return;
1336 1335
1337 case ConsentProvider::CONSENT_IMPOSSIBLE: 1336 case ConsentProvider::CONSENT_IMPOSSIBLE:
1338 SetError(kConsentImpossible); 1337 Respond(Error(kConsentImpossible));
1339 SendResponse(false);
1340 return; 1338 return;
1341 1339
1342 case ConsentProvider::CONSENT_GRANTED: 1340 case ConsentProvider::CONSENT_GRANTED:
1343 break; 1341 break;
1344 } 1342 }
1345 1343
1346 if (!volume.get()) { 1344 if (!volume.get()) {
1347 SetError(kVolumeNotFoundError); 1345 Respond(Error(kVolumeNotFoundError));
1348 SendResponse(false);
1349 return; 1346 return;
1350 } 1347 }
1351 1348
1352 const GURL site = 1349 const GURL site =
1353 util::GetSiteForExtensionId(extension_id(), chrome_details_.GetProfile()); 1350 util::GetSiteForExtensionId(extension_id(), chrome_details_.GetProfile());
1354 scoped_refptr<storage::FileSystemContext> file_system_context = 1351 scoped_refptr<storage::FileSystemContext> file_system_context =
1355 content::BrowserContext::GetStoragePartitionForSite( 1352 content::BrowserContext::GetStoragePartitionForSite(
1356 chrome_details_.GetProfile(), site)->GetFileSystemContext(); 1353 chrome_details_.GetProfile(), site)->GetFileSystemContext();
1357 storage::ExternalFileSystemBackend* const backend = 1354 storage::ExternalFileSystemBackend* const backend =
1358 file_system_context->external_backend(); 1355 file_system_context->external_backend();
1359 DCHECK(backend); 1356 DCHECK(backend);
1360 1357
1361 base::FilePath virtual_path; 1358 base::FilePath virtual_path;
1362 if (!backend->GetVirtualPath(volume->mount_path(), &virtual_path)) { 1359 if (!backend->GetVirtualPath(volume->mount_path(), &virtual_path)) {
1363 SetError(kSecurityError); 1360 Respond(Error(kSecurityError));
1364 SendResponse(false);
1365 return; 1361 return;
1366 } 1362 }
1367 1363
1368 storage::IsolatedContext* const isolated_context = 1364 storage::IsolatedContext* const isolated_context =
1369 storage::IsolatedContext::GetInstance(); 1365 storage::IsolatedContext::GetInstance();
1370 DCHECK(isolated_context); 1366 DCHECK(isolated_context);
1371 1367
1372 const storage::FileSystemURL original_url = 1368 const storage::FileSystemURL original_url =
1373 file_system_context->CreateCrackedFileSystemURL( 1369 file_system_context->CreateCrackedFileSystemURL(
1374 GURL(std::string(kExtensionScheme) + url::kStandardSchemeSeparator + 1370 GURL(std::string(kExtensionScheme) + url::kStandardSchemeSeparator +
1375 extension_id()), 1371 extension_id()),
1376 storage::kFileSystemTypeExternal, virtual_path); 1372 storage::kFileSystemTypeExternal, virtual_path);
1377 1373
1378 // Set a fixed register name, as the automatic one would leak the mount point 1374 // Set a fixed register name, as the automatic one would leak the mount point
1379 // directory. 1375 // directory.
1380 std::string register_name = "fs"; 1376 std::string register_name = "fs";
1381 const std::string file_system_id = 1377 const std::string file_system_id =
1382 isolated_context->RegisterFileSystemForPath( 1378 isolated_context->RegisterFileSystemForPath(
1383 storage::kFileSystemTypeNativeForPlatformApp, 1379 storage::kFileSystemTypeNativeForPlatformApp,
1384 std::string() /* file_system_id */, original_url.path(), 1380 std::string() /* file_system_id */, original_url.path(),
1385 &register_name); 1381 &register_name);
1386 if (file_system_id.empty()) { 1382 if (file_system_id.empty()) {
1387 SetError(kSecurityError); 1383 Respond(Error(kSecurityError));
1388 SendResponse(false);
1389 return; 1384 return;
1390 } 1385 }
1391 1386
1392 backend->GrantFileAccessToExtension(extension_->id(), virtual_path); 1387 backend->GrantFileAccessToExtension(extension_->id(), virtual_path);
1393 1388
1394 // Grant file permissions to the renderer hosting component. 1389 // Grant file permissions to the renderer hosting component.
1395 content::ChildProcessSecurityPolicy* policy = 1390 content::ChildProcessSecurityPolicy* policy =
1396 content::ChildProcessSecurityPolicy::GetInstance(); 1391 content::ChildProcessSecurityPolicy::GetInstance();
1397 DCHECK(policy); 1392 DCHECK(policy);
1398 1393
(...skipping 14 matching lines...) Expand all
1413 policy->GrantDeleteFromFileSystem( 1408 policy->GrantDeleteFromFileSystem(
1414 render_frame_host()->GetProcess()->GetID(), file_system_id); 1409 render_frame_host()->GetProcess()->GetID(), file_system_id);
1415 policy->GrantCreateFileForFileSystem( 1410 policy->GrantCreateFileForFileSystem(
1416 render_frame_host()->GetProcess()->GetID(), file_system_id); 1411 render_frame_host()->GetProcess()->GetID(), file_system_id);
1417 } 1412 }
1418 1413
1419 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 1414 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
1420 dict->SetString("file_system_id", file_system_id); 1415 dict->SetString("file_system_id", file_system_id);
1421 dict->SetString("file_system_path", register_name); 1416 dict->SetString("file_system_path", register_name);
1422 1417
1423 SetResult(std::move(dict)); 1418 Respond(OneArgument(std::move(dict)));
1424 SendResponse(true);
1425 } 1419 }
1426 1420
1427 FileSystemGetVolumeListFunction::FileSystemGetVolumeListFunction() 1421 FileSystemGetVolumeListFunction::FileSystemGetVolumeListFunction()
1428 : chrome_details_(this) { 1422 : chrome_details_(this) {
1429 } 1423 }
1430 1424
1431 FileSystemGetVolumeListFunction::~FileSystemGetVolumeListFunction() { 1425 FileSystemGetVolumeListFunction::~FileSystemGetVolumeListFunction() {
1432 } 1426 }
1433 1427
1434 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() { 1428 ExtensionFunction::ResponseAction FileSystemGetVolumeListFunction::Run() {
1435 // Only kiosk apps in kiosk sessions can use this API. 1429 // Only kiosk apps in kiosk sessions can use this API.
1436 // Additionally it is enabled for whitelisted component extensions and apps. 1430 // Additionally it is enabled for whitelisted component extensions and apps.
1437 file_system_api::ConsentProviderDelegate consent_provider_delegate( 1431 file_system_api::ConsentProviderDelegate consent_provider_delegate(
1438 chrome_details_.GetProfile(), render_frame_host()); 1432 chrome_details_.GetProfile(), render_frame_host());
1439 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate); 1433 file_system_api::ConsentProvider consent_provider(&consent_provider_delegate);
1440 1434
1441 if (!consent_provider.IsGrantable(*extension())) 1435 if (!consent_provider.IsGrantable(*extension()))
1442 return RespondNow(Error(kNotSupportedOnNonKioskSessionError)); 1436 return RespondNow(Error(kNotSupportedOnNonKioskSessionError));
1443 std::vector<api::file_system::Volume> result_volume_list; 1437 std::vector<api::file_system::Volume> result_volume_list;
1444 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list); 1438 FillVolumeList(chrome_details_.GetProfile(), &result_volume_list);
1445 1439
1446 return RespondNow(ArgumentList( 1440 return RespondNow(ArgumentList(
1447 api::file_system::GetVolumeList::Results::Create(result_volume_list))); 1441 api::file_system::GetVolumeList::Results::Create(result_volume_list)));
1448 } 1442 }
1449 #endif 1443 #endif
1450 1444
1451 } // namespace extensions 1445 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698