OLD | NEW |
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/chromeos/extensions/file_browser_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 const std::string& mount_type_str, | 1008 const std::string& mount_type_str, |
1009 const SelectedFileInfoList& files) { | 1009 const SelectedFileInfoList& files) { |
1010 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1010 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1011 | 1011 |
1012 if (!files.size()) { | 1012 if (!files.size()) { |
1013 SendResponse(false); | 1013 SendResponse(false); |
1014 return; | 1014 return; |
1015 } | 1015 } |
1016 | 1016 |
1017 #if defined(OS_CHROMEOS) | 1017 #if defined(OS_CHROMEOS) |
1018 FilePath source_file = files[0].path; | 1018 const FilePath& source_path = files[0].path; |
| 1019 const FilePath::StringType& display_name = files[0].display_name; |
| 1020 // Check if the source path is under GData cache directory. |
| 1021 gdata::GDataSystemService* system_service = |
| 1022 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 1023 if (system_service && system_service->file_system() && |
| 1024 system_service->file_system()->IsUnderGDataCacheDirectory(source_path)) { |
| 1025 system_service->file_system()->SetMountedState( |
| 1026 source_path, true, |
| 1027 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, |
| 1028 display_name)); |
| 1029 } else { |
| 1030 OnMountedStateSet(mount_type_str, FilePath::StringType(), |
| 1031 base::PLATFORM_FILE_OK, source_path); |
| 1032 } |
| 1033 #else |
| 1034 SendResponse(true); |
| 1035 #endif // defined(OS_CHROMEOS) |
| 1036 } |
| 1037 |
| 1038 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, |
| 1039 const FilePath::StringType& file_name, |
| 1040 base::PlatformFileError error, |
| 1041 const FilePath& file_path) { |
| 1042 #if defined(OS_CHROMEOS) |
| 1043 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1019 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 1044 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
1020 // MountPath() takes a std::string. | 1045 // MountPath() takes a std::string. |
1021 disk_mount_manager->MountPath(source_file.AsUTF8Unsafe(), | 1046 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), |
1022 DiskMountManager::MountTypeFromString(mount_type_str)); | 1047 FilePath(file_name).Extension(), |
| 1048 DiskMountManager::MountTypeFromString( |
| 1049 mount_type)); |
| 1050 SendResponse(true); |
1023 #endif // defined(OS_CHROMEOS) | 1051 #endif // defined(OS_CHROMEOS) |
1024 | |
1025 SendResponse(true); | |
1026 } | 1052 } |
1027 | 1053 |
1028 RemoveMountFunction::RemoveMountFunction() { | 1054 RemoveMountFunction::RemoveMountFunction() { |
1029 } | 1055 } |
1030 | 1056 |
1031 RemoveMountFunction::~RemoveMountFunction() { | 1057 RemoveMountFunction::~RemoveMountFunction() { |
1032 } | 1058 } |
1033 | 1059 |
1034 bool RemoveMountFunction::RunImpl() { | 1060 bool RemoveMountFunction::RunImpl() { |
1035 if (args_->GetSize() != 1) { | 1061 if (args_->GetSize() != 1) { |
(...skipping 15 matching lines...) Expand all Loading... |
1051 | 1077 |
1052 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( | 1078 void RemoveMountFunction::GetLocalPathsResponseOnUIThread( |
1053 const SelectedFileInfoList& files) { | 1079 const SelectedFileInfoList& files) { |
1054 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1080 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1055 | 1081 |
1056 if (files.size() != 1) { | 1082 if (files.size() != 1) { |
1057 SendResponse(false); | 1083 SendResponse(false); |
1058 return; | 1084 return; |
1059 } | 1085 } |
1060 #if defined(OS_CHROMEOS) | 1086 #if defined(OS_CHROMEOS) |
1061 DiskMountManager::GetInstance()->UnmountPath(files[0].path.value()); | 1087 // Look up source path from mount path. |
1062 #endif | 1088 const std::string& mount_path = files[0].path.value(); |
| 1089 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
| 1090 DiskMountManager::MountPointMap mount_points = |
| 1091 disk_mount_manager->mount_points(); |
| 1092 DiskMountManager::MountPointMap::const_iterator it = |
| 1093 mount_points.find(mount_path); |
| 1094 if (it == mount_points.end()) { |
| 1095 SendResponse(false); |
| 1096 return; |
| 1097 } |
| 1098 DiskMountManager::MountPointInfo mount_point_info = it->second; |
| 1099 FilePath source_path = FilePath(mount_point_info.source_path); |
| 1100 // Unmount archive. |
| 1101 disk_mount_manager->UnmountPath(mount_path); |
| 1102 // Check if the source path is under GData cache directory. |
| 1103 gdata::GDataSystemService* system_service = |
| 1104 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 1105 if (system_service && system_service->file_system() && |
| 1106 system_service->file_system()->IsUnderGDataCacheDirectory(source_path)) { |
| 1107 system_service->file_system()->SetMountedState( |
| 1108 source_path, false, |
| 1109 base::Bind(&RemoveMountFunction::OnMountedStateSet, this)); |
| 1110 } else { |
| 1111 OnMountedStateSet(base::PLATFORM_FILE_OK, source_path); |
| 1112 } |
| 1113 #else |
| 1114 SendResponse(true); |
| 1115 #endif // defined(OS_CHROMEOS) |
| 1116 } |
1063 | 1117 |
| 1118 void RemoveMountFunction::OnMountedStateSet(base::PlatformFileError error, |
| 1119 const FilePath& file_path) { |
| 1120 // Ignore the file_path argument for now. |
1064 SendResponse(true); | 1121 SendResponse(true); |
1065 } | 1122 } |
1066 | 1123 |
1067 GetMountPointsFunction::GetMountPointsFunction() { | 1124 GetMountPointsFunction::GetMountPointsFunction() { |
1068 } | 1125 } |
1069 | 1126 |
1070 GetMountPointsFunction::~GetMountPointsFunction() { | 1127 GetMountPointsFunction::~GetMountPointsFunction() { |
1071 } | 1128 } |
1072 | 1129 |
1073 bool GetMountPointsFunction::RunImpl() { | 1130 bool GetMountPointsFunction::RunImpl() { |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 if (value->GetBoolean("cellularDisabled", &tmp)) { | 2047 if (value->GetBoolean("cellularDisabled", &tmp)) { |
1991 service->SetBoolean(prefs::kDisableGDataOverCellular, tmp); | 2048 service->SetBoolean(prefs::kDisableGDataOverCellular, tmp); |
1992 } | 2049 } |
1993 | 2050 |
1994 if (value->GetBoolean("hostedFilesDisabled", &tmp)) { | 2051 if (value->GetBoolean("hostedFilesDisabled", &tmp)) { |
1995 service->SetBoolean(prefs::kDisableGDataHostedFiles, tmp); | 2052 service->SetBoolean(prefs::kDisableGDataHostedFiles, tmp); |
1996 } | 2053 } |
1997 | 2054 |
1998 return true; | 2055 return true; |
1999 } | 2056 } |
OLD | NEW |