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

Side by Side Diff: chrome/browser/extensions/extension_file_browser_private_api.cc

Issue 8386031: Move chromeos_mount.cc from libcros to Chrome tree (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix for review comments Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_file_browser_private_api.h" 5 #include "chrome/browser/extensions/extension_file_browser_private_api.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "webkit/fileapi/file_system_context.h" 43 #include "webkit/fileapi/file_system_context.h"
44 #include "webkit/fileapi/file_system_file_util.h" 44 #include "webkit/fileapi/file_system_file_util.h"
45 #include "webkit/fileapi/file_system_mount_point_provider.h" 45 #include "webkit/fileapi/file_system_mount_point_provider.h"
46 #include "webkit/fileapi/file_system_operation.h" 46 #include "webkit/fileapi/file_system_operation.h"
47 #include "webkit/fileapi/file_system_operation_context.h" 47 #include "webkit/fileapi/file_system_operation_context.h"
48 #include "webkit/fileapi/file_system_path_manager.h" 48 #include "webkit/fileapi/file_system_path_manager.h"
49 #include "webkit/fileapi/file_system_types.h" 49 #include "webkit/fileapi/file_system_types.h"
50 #include "webkit/fileapi/file_system_util.h" 50 #include "webkit/fileapi/file_system_util.h"
51 51
52 #ifdef OS_CHROMEOS 52 #ifdef OS_CHROMEOS
53 #include "chrome/browser/chromeos/cros/cros_library.h" 53 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
54 #endif 54 #endif
55 55
56 using content::BrowserThread; 56 using content::BrowserThread;
57 57
58 // Error messages. 58 // Error messages.
59 const char kFileError[] = "File error %d"; 59 const char kFileError[] = "File error %d";
60 const char kInvalidFileUrl[] = "Invalid file URL"; 60 const char kInvalidFileUrl[] = "Invalid file URL";
61 const char kVolumeDevicePathNotFound[] = "Device path not found"; 61 const char kVolumeDevicePathNotFound[] = "Device path not found";
62 62
63 #ifdef OS_CHROMEOS 63 #ifdef OS_CHROMEOS
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(), 259 DictionaryPrefUpdate prefs_usage_update(profile->GetPrefs(),
260 prefs::kLastUsedFileBrowserHandlers); 260 prefs::kLastUsedFileBrowserHandlers);
261 prefs_usage_update->SetWithoutPathExpansion(task_id, 261 prefs_usage_update->SetWithoutPathExpansion(task_id,
262 new base::FundamentalValue( 262 new base::FundamentalValue(
263 static_cast<int>(base::Time::Now().ToInternalValue()/ 263 static_cast<int>(base::Time::Now().ToInternalValue()/
264 base::Time::kMicrosecondsPerSecond))); 264 base::Time::kMicrosecondsPerSecond)));
265 } 265 }
266 266
267 #ifdef OS_CHROMEOS 267 #ifdef OS_CHROMEOS
268 base::DictionaryValue* MountPointToValue(Profile* profile, 268 base::DictionaryValue* MountPointToValue(Profile* profile,
269 const chromeos::MountLibrary::MountPointInfo& mount_point_info) { 269 const chromeos::CrosDisksClient::MountPointInfo& mount_point_info) {
270 270
271 base::DictionaryValue *mount_info = new base::DictionaryValue(); 271 base::DictionaryValue *mount_info = new base::DictionaryValue();
272 272
273 mount_info->SetString("mountType", 273 mount_info->SetString("mountType",
274 chromeos::MountLibrary::MountTypeToString(mount_point_info.mount_type)); 274 chromeos::CrosDisksClient::MountTypeToString(
275 mount_point_info.mount_type));
275 276
276 if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { 277 if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
277 GURL source_url; 278 GURL source_url;
278 if (FileManagerUtil::ConvertFileToFileSystemUrl(profile, 279 if (FileManagerUtil::ConvertFileToFileSystemUrl(profile,
279 FilePath(mount_point_info.source_path), 280 FilePath(mount_point_info.source_path),
280 FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(), 281 FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(),
281 &source_url)) { 282 &source_url)) {
282 mount_info->SetString("sourceUrl", source_url.spec()); 283 mount_info->SetString("sourceUrl", source_url.spec());
283 } 284 }
284 } else { 285 } else {
285 mount_info->SetString("sourceUrl", mount_point_info.source_path); 286 mount_info->SetString("sourceUrl", mount_point_info.source_path);
286 } 287 }
287 288
288 FilePath relative_mount_path; 289 FilePath relative_mount_path;
289 // Convert mount point path to relative path with the external file system 290 // Convert mount point path to relative path with the external file system
290 // exposed within File API. 291 // exposed within File API.
291 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile, 292 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile,
292 FilePath(mount_point_info.mount_path), 293 FilePath(mount_point_info.mount_path),
293 &relative_mount_path)) { 294 &relative_mount_path)) {
294 mount_info->SetString("mountPath", relative_mount_path.value()); 295 mount_info->SetString("mountPath", relative_mount_path.value());
295 } 296 }
296 297
297 mount_info->SetString("mountCondition", 298 mount_info->SetString("mountCondition",
298 chromeos::MountLibrary::MountConditionToString( 299 chromeos::CrosDisksClient::MountConditionToString(
299 mount_point_info.mount_condition)); 300 mount_point_info.mount_condition));
300 301
301 return mount_info; 302 return mount_info;
302 } 303 }
303 #endif 304 #endif
304 305
305 306
306 class LocalFileSystemCallbackDispatcher 307 class LocalFileSystemCallbackDispatcher
307 : public fileapi::FileSystemCallbackDispatcher { 308 : public fileapi::FileSystemCallbackDispatcher {
308 public: 309 public:
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 return; 1240 return;
1240 } 1241 }
1241 1242
1242 #ifdef OS_CHROMEOS 1243 #ifdef OS_CHROMEOS
1243 scoped_ptr<MountParamaters> params( 1244 scoped_ptr<MountParamaters> params(
1244 reinterpret_cast<MountParamaters*>(context)); 1245 reinterpret_cast<MountParamaters*>(context));
1245 const std::string& mount_type_str = params->mount_type; 1246 const std::string& mount_type_str = params->mount_type;
1246 const chromeos::MountPathOptions& options = params->mount_options; 1247 const chromeos::MountPathOptions& options = params->mount_options;
1247 FilePath::StringType source_file = files[0].value(); 1248 FilePath::StringType source_file = files[0].value();
1248 1249
1249 chromeos::MountLibrary *mount_lib = 1250 chromeos::CrosDisksClient *cros_disks_client =
1250 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1251 chromeos::DBusThreadManager::Get()->GetCrosDisksClient();
1251 1252
1252 chromeos::MountType mount_type = 1253 chromeos::MountType mount_type =
1253 mount_lib->MountTypeFromString(mount_type_str); 1254 cros_disks_client->MountTypeFromString(mount_type_str);
1254 if (mount_type == chromeos::MOUNT_TYPE_INVALID) { 1255 if (mount_type == chromeos::MOUNT_TYPE_INVALID) {
1255 error_ = "Invalid mount type"; 1256 error_ = "Invalid mount type";
1256 SendResponse(false); 1257 SendResponse(false);
1257 return; 1258 return;
1258 } 1259 }
1259 1260
1260 mount_lib->MountPath(source_file.data(), mount_type, options); 1261 cros_disks_client->MountPath(source_file.data(), mount_type, options);
1261 #endif 1262 #endif
1262 1263
1263 SendResponse(true); 1264 SendResponse(true);
1264 } 1265 }
1265 1266
1266 RemoveMountFunction::RemoveMountFunction() { 1267 RemoveMountFunction::RemoveMountFunction() {
1267 } 1268 }
1268 1269
1269 RemoveMountFunction::~RemoveMountFunction() { 1270 RemoveMountFunction::~RemoveMountFunction() {
1270 } 1271 }
(...skipping 22 matching lines...) Expand all
1293 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( 1294 void RemoveMountFunction::GetLocalPathsResponseOnUIThread(
1294 const FilePathList& files, void* context) { 1295 const FilePathList& files, void* context) {
1295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1296 DCHECK(!context); 1297 DCHECK(!context);
1297 1298
1298 if (files.size() != 1) { 1299 if (files.size() != 1) {
1299 SendResponse(false); 1300 SendResponse(false);
1300 return; 1301 return;
1301 } 1302 }
1302 #ifdef OS_CHROMEOS 1303 #ifdef OS_CHROMEOS
1303 chromeos::CrosLibrary::Get()->GetMountLibrary()->UnmountPath( 1304 chromeos::DBusThreadManager::Get()->GetCrosDisksClient()->UnmountPath(
1304 files[0].value().c_str()); 1305 files[0].value().c_str());
1305 #endif 1306 #endif
1306 1307
1307 SendResponse(true); 1308 SendResponse(true);
1308 } 1309 }
1309 1310
1310 GetMountPointsFunction::GetMountPointsFunction() { 1311 GetMountPointsFunction::GetMountPointsFunction() {
1311 } 1312 }
1312 1313
1313 GetMountPointsFunction::~GetMountPointsFunction() { 1314 GetMountPointsFunction::~GetMountPointsFunction() {
1314 } 1315 }
1315 1316
1316 bool GetMountPointsFunction::RunImpl() { 1317 bool GetMountPointsFunction::RunImpl() {
1317 if (args_->GetSize()) 1318 if (args_->GetSize())
1318 return false; 1319 return false;
1319 1320
1320 base::ListValue *mounts = new base::ListValue(); 1321 base::ListValue *mounts = new base::ListValue();
1321 result_.reset(mounts); 1322 result_.reset(mounts);
1322 1323
1323 #ifdef OS_CHROMEOS 1324 #ifdef OS_CHROMEOS
1324 chromeos::MountLibrary *mount_lib = 1325 chromeos::CrosDisksClient *cros_disks_client =
1325 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1326 chromeos::DBusThreadManager::Get()->GetCrosDisksClient();
1326 chromeos::MountLibrary::MountPointMap mount_points = 1327 chromeos::CrosDisksClient::MountPointMap mount_points =
1327 mount_lib->mount_points(); 1328 cros_disks_client->mount_points();
1328 1329
1329 for (chromeos::MountLibrary::MountPointMap::const_iterator it = 1330 for (chromeos::CrosDisksClient::MountPointMap::const_iterator it =
1330 mount_points.begin(); 1331 mount_points.begin();
1331 it != mount_points.end(); 1332 it != mount_points.end();
1332 ++it) { 1333 ++it) {
1333 mounts->Append(MountPointToValue(profile_, it->second)); 1334 mounts->Append(MountPointToValue(profile_, it->second));
1334 } 1335 }
1335 #endif 1336 #endif
1336 1337
1337 SendResponse(true); 1338 SendResponse(true);
1338 return true; 1339 return true;
1339 } 1340 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 files[0].value().c_str())); 1383 files[0].value().c_str()));
1383 } 1384 }
1384 1385
1385 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( 1386 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread(
1386 const char* mount_path) { 1387 const char* mount_path) {
1387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 1388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
1388 1389
1389 size_t total_size_kb = 0; 1390 size_t total_size_kb = 0;
1390 size_t remaining_size_kb = 0; 1391 size_t remaining_size_kb = 0;
1391 #ifdef OS_CHROMEOS 1392 #ifdef OS_CHROMEOS
1392 chromeos::CrosLibrary::Get()->GetMountLibrary()->GetSizeStatsOnFileThread( 1393 chromeos::DBusThreadManager::Get()->GetCrosDisksClient()->
1393 mount_path, &total_size_kb, &remaining_size_kb); 1394 GetSizeStatsOnFileThread(mount_path, &total_size_kb, &remaining_size_kb);
1394 #endif 1395 #endif
1395 1396
1396 BrowserThread::PostTask( 1397 BrowserThread::PostTask(
1397 BrowserThread::UI, FROM_HERE, 1398 BrowserThread::UI, FROM_HERE,
1398 base::Bind( 1399 base::Bind(
1399 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread, 1400 &GetSizeStatsFunction::GetSizeStatsCallbackOnUIThread,
1400 this, 1401 this,
1401 mount_path, total_size_kb, remaining_size_kb)); 1402 mount_path, total_size_kb, remaining_size_kb));
1402 } 1403 }
1403 1404
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread( 1447 void FormatDeviceFunction::GetLocalPathsResponseOnUIThread(
1447 const FilePathList& files, void* context) { 1448 const FilePathList& files, void* context) {
1448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1449 1450
1450 if (files.size() != 1) { 1451 if (files.size() != 1) {
1451 SendResponse(false); 1452 SendResponse(false);
1452 return; 1453 return;
1453 } 1454 }
1454 1455
1455 #ifdef OS_CHROMEOS 1456 #ifdef OS_CHROMEOS
1456 chromeos::CrosLibrary::Get()->GetMountLibrary()->FormatMountedDevice( 1457 chromeos::DBusThreadManager::Get()->GetCrosDisksClient()->FormatMountedDevice(
1457 files[0].value().c_str()); 1458 files[0].value().c_str());
1458 #endif 1459 #endif
1459 1460
1460 SendResponse(true); 1461 SendResponse(true);
1461 } 1462 }
1462 1463
1463 GetVolumeMetadataFunction::GetVolumeMetadataFunction() { 1464 GetVolumeMetadataFunction::GetVolumeMetadataFunction() {
1464 } 1465 }
1465 1466
1466 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() { 1467 GetVolumeMetadataFunction::~GetVolumeMetadataFunction() {
1467 } 1468 }
1468 1469
1469 bool GetVolumeMetadataFunction::RunImpl() { 1470 bool GetVolumeMetadataFunction::RunImpl() {
1470 if (args_->GetSize() != 1) { 1471 if (args_->GetSize() != 1) {
1471 error_ = "Invalid argument count"; 1472 error_ = "Invalid argument count";
1472 return false; 1473 return false;
1473 } 1474 }
1474 1475
1475 std::string volume_device_path; 1476 std::string volume_device_path;
1476 if (!args_->GetString(0, &volume_device_path)) { 1477 if (!args_->GetString(0, &volume_device_path)) {
1477 NOTREACHED(); 1478 NOTREACHED();
1478 } 1479 }
1479 1480
1480 #ifdef OS_CHROMEOS 1481 #ifdef OS_CHROMEOS
1481 chromeos::MountLibrary* mount_lib = 1482 chromeos::CrosDisksClient* cros_disks_client =
1482 chromeos::CrosLibrary::Get()->GetMountLibrary(); 1483 chromeos::DBusThreadManager::Get()->GetCrosDisksClient();
1483 chromeos::MountLibrary::DiskMap::const_iterator volume_it = 1484 chromeos::CrosDisksClient::DiskMap::const_iterator volume_it =
1484 mount_lib->disks().find(volume_device_path); 1485 cros_disks_client->disks().find(volume_device_path);
1485 1486
1486 if (volume_it != mount_lib->disks().end() && 1487 if (volume_it != cros_disks_client->disks().end() &&
1487 !volume_it->second->is_hidden()) { 1488 !volume_it->second->is_hidden()) {
1488 chromeos::MountLibrary::Disk* volume = volume_it->second; 1489 chromeos::CrosDisksClient::Disk* volume = volume_it->second;
1489 DictionaryValue* volume_info = new DictionaryValue(); 1490 DictionaryValue* volume_info = new DictionaryValue();
1490 result_.reset(volume_info); 1491 result_.reset(volume_info);
1491 // Localising mount path. 1492 // Localising mount path.
1492 std::string mount_path; 1493 std::string mount_path;
1493 if (!volume->mount_path().empty()) { 1494 if (!volume->mount_path().empty()) {
1494 FilePath relative_mount_path; 1495 FilePath relative_mount_path;
1495 FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, 1496 FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_,
1496 FilePath(volume->mount_path()), &relative_mount_path); 1497 FilePath(volume->mount_path()), &relative_mount_path);
1497 mount_path = relative_mount_path.value(); 1498 mount_path = relative_mount_path.value();
1498 } 1499 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1702 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON)); 1703 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_VIEW_CERT_BUTTON));
1703 dict->SetString("PLAY_MEDIA", 1704 dict->SetString("PLAY_MEDIA",
1704 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY)); 1705 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_PLAY));
1705 #if defined(OS_CHROMEOS) 1706 #if defined(OS_CHROMEOS)
1706 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePhotoEditor)) 1707 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePhotoEditor))
1707 dict->SetString("ENABLE_PHOTO_EDITOR", "true"); 1708 dict->SetString("ENABLE_PHOTO_EDITOR", "true");
1708 #endif 1709 #endif
1709 1710
1710 return true; 1711 return true;
1711 } 1712 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698