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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 | 140 |
141 base::DictionaryValue* CreateValueFromMountPoint(Profile* profile, | 141 base::DictionaryValue* CreateValueFromMountPoint(Profile* profile, |
142 const DiskMountManager::MountPointInfo& mount_point_info, | 142 const DiskMountManager::MountPointInfo& mount_point_info, |
143 const GURL& extension_source_url) { | 143 const GURL& extension_source_url) { |
144 | 144 |
145 base::DictionaryValue *mount_info = new base::DictionaryValue(); | 145 base::DictionaryValue *mount_info = new base::DictionaryValue(); |
146 | 146 |
147 mount_info->SetString("mountType", | 147 mount_info->SetString("mountType", |
148 DiskMountManager::MountTypeToString( | 148 DiskMountManager::MountTypeToString( |
149 mount_point_info.mount_type)); | 149 mount_point_info.mount_type)); |
150 | 150 mount_info->SetString("sourcePath", mount_point_info.source_path); |
151 if (mount_point_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { | |
152 GURL source_url; | |
153 if (file_manager_util::ConvertFileToFileSystemUrl(profile, | |
154 FilePath(mount_point_info.source_path), | |
155 extension_source_url.GetOrigin(), | |
156 &source_url)) { | |
157 mount_info->SetString("sourceUrl", source_url.spec()); | |
158 } | |
159 } else { | |
160 mount_info->SetString("sourceUrl", mount_point_info.source_path); | |
161 } | |
162 | 151 |
163 FilePath relative_mount_path; | 152 FilePath relative_mount_path; |
164 // Convert mount point path to relative path with the external file system | 153 // Convert mount point path to relative path with the external file system |
165 // exposed within File API. | 154 // exposed within File API. |
166 if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile, | 155 if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile, |
167 FilePath(mount_point_info.mount_path), | 156 FilePath(mount_point_info.mount_path), |
168 &relative_mount_path)) { | 157 &relative_mount_path)) { |
169 mount_info->SetString("mountPath", relative_mount_path.value()); | 158 mount_info->SetString("mountPath", relative_mount_path.value()); |
170 } | 159 } |
171 | 160 |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 std::string file_url; | 902 std::string file_url; |
914 if (!args_->GetString(0, &file_url)) { | 903 if (!args_->GetString(0, &file_url)) { |
915 return false; | 904 return false; |
916 } | 905 } |
917 | 906 |
918 std::string mount_type_str; | 907 std::string mount_type_str; |
919 if (!args_->GetString(1, &mount_type_str)) { | 908 if (!args_->GetString(1, &mount_type_str)) { |
920 return false; | 909 return false; |
921 } | 910 } |
922 | 911 |
912 // Set default return source path to the empty string. | |
913 result_.reset(Value::CreateStringValue("")); | |
914 | |
923 #if defined(OS_CHROMEOS) | 915 #if defined(OS_CHROMEOS) |
924 chromeos::MountType mount_type = | 916 chromeos::MountType mount_type = |
925 DiskMountManager::MountTypeFromString(mount_type_str); | 917 DiskMountManager::MountTypeFromString(mount_type_str); |
926 switch (mount_type) { | 918 switch (mount_type) { |
927 case chromeos::MOUNT_TYPE_INVALID: { | 919 case chromeos::MOUNT_TYPE_INVALID: { |
928 error_ = "Invalid mount type"; | 920 error_ = "Invalid mount type"; |
929 SendResponse(false); | 921 SendResponse(false); |
930 break; | 922 break; |
931 } | 923 } |
932 case chromeos::MOUNT_TYPE_GDATA: { | 924 case chromeos::MOUNT_TYPE_GDATA: { |
(...skipping 24 matching lines...) Expand all Loading... | |
957 } | 949 } |
958 | 950 |
959 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { | 951 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { |
960 chromeos::MountError error_code = chromeos::MOUNT_ERROR_NONE; | 952 chromeos::MountError error_code = chromeos::MOUNT_ERROR_NONE; |
961 // For the file manager to work offline, GDATA_NO_CONNECTION is allowed. | 953 // For the file manager to work offline, GDATA_NO_CONNECTION is allowed. |
962 if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION) { | 954 if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION) { |
963 error_code = chromeos::MOUNT_ERROR_NONE; | 955 error_code = chromeos::MOUNT_ERROR_NONE; |
964 } else { | 956 } else { |
965 error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; | 957 error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; |
966 } | 958 } |
967 | 959 // Pass back the gdata mount point path as source path. |
960 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); | |
961 result_.reset(Value::CreateStringValue(gdata_path)); | |
968 DiskMountManager::MountPointInfo mount_info( | 962 DiskMountManager::MountPointInfo mount_info( |
969 gdata::util::GetGDataMountPointPathAsString(), | 963 gdata_path, |
970 gdata::util::GetGDataMountPointPathAsString(), | 964 gdata_path, |
971 chromeos::MOUNT_TYPE_GDATA, | 965 chromeos::MOUNT_TYPE_GDATA, |
972 chromeos::disks::MOUNT_CONDITION_NONE); | 966 chromeos::disks::MOUNT_CONDITION_NONE); |
973 // Raise mount event | 967 // Raise mount event |
974 FileBrowserEventRouterFactory::GetForProfile(profile_)-> | 968 FileBrowserEventRouterFactory::GetForProfile(profile_)-> |
975 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); | 969 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); |
976 } | 970 } |
977 | 971 |
978 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, | 972 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, |
979 const std::string& token) { | 973 const std::string& token) { |
980 RaiseGDataMountEvent(error); | 974 RaiseGDataMountEvent(error); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 #endif // defined(OS_CHROMEOS) | 1008 #endif // defined(OS_CHROMEOS) |
1015 } | 1009 } |
1016 | 1010 |
1017 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, | 1011 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, |
1018 const FilePath::StringType& file_name, | 1012 const FilePath::StringType& file_name, |
1019 base::PlatformFileError error, | 1013 base::PlatformFileError error, |
1020 const FilePath& file_path) { | 1014 const FilePath& file_path) { |
1021 #if defined(OS_CHROMEOS) | 1015 #if defined(OS_CHROMEOS) |
1022 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1016 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1023 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 1017 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
1018 // Pass back the actual source path of the mount point. | |
1019 result_.reset(Value::CreateStringValue(file_path.value())); | |
1024 // MountPath() takes a std::string. | 1020 // MountPath() takes a std::string. |
1025 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), | 1021 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), |
1026 FilePath(file_name).Extension(), | 1022 FilePath(file_name).Extension(), file_name, |
1027 DiskMountManager::MountTypeFromString( | 1023 DiskMountManager::MountTypeFromString( |
1028 mount_type)); | 1024 mount_type)); |
tbarzic
2012/04/30 17:20:41
send response before you try mounting
hshi
2012/04/30 18:49:03
Done.
| |
1029 SendResponse(true); | 1025 SendResponse(true); |
1030 #endif // defined(OS_CHROMEOS) | 1026 #endif // defined(OS_CHROMEOS) |
1031 } | 1027 } |
1032 | 1028 |
1033 RemoveMountFunction::RemoveMountFunction() { | 1029 RemoveMountFunction::RemoveMountFunction() { |
1034 } | 1030 } |
1035 | 1031 |
1036 RemoveMountFunction::~RemoveMountFunction() { | 1032 RemoveMountFunction::~RemoveMountFunction() { |
1037 } | 1033 } |
1038 | 1034 |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2010 if (value->GetBoolean("cellularDisabled", &tmp)) { | 2006 if (value->GetBoolean("cellularDisabled", &tmp)) { |
2011 service->SetBoolean(prefs::kDisableGDataOverCellular, tmp); | 2007 service->SetBoolean(prefs::kDisableGDataOverCellular, tmp); |
2012 } | 2008 } |
2013 | 2009 |
2014 if (value->GetBoolean("hostedFilesDisabled", &tmp)) { | 2010 if (value->GetBoolean("hostedFilesDisabled", &tmp)) { |
2015 service->SetBoolean(prefs::kDisableGDataHostedFiles, tmp); | 2011 service->SetBoolean(prefs::kDisableGDataHostedFiles, tmp); |
2016 } | 2012 } |
2017 | 2013 |
2018 return true; | 2014 return true; |
2019 } | 2015 } |
OLD | NEW |