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 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 | 1082 |
1083 chromeos::MountType mount_type = | 1083 chromeos::MountType mount_type = |
1084 DiskMountManager::MountTypeFromString(mount_type_str); | 1084 DiskMountManager::MountTypeFromString(mount_type_str); |
1085 switch (mount_type) { | 1085 switch (mount_type) { |
1086 case chromeos::MOUNT_TYPE_INVALID: { | 1086 case chromeos::MOUNT_TYPE_INVALID: { |
1087 error_ = "Invalid mount type"; | 1087 error_ = "Invalid mount type"; |
1088 SendResponse(false); | 1088 SendResponse(false); |
1089 break; | 1089 break; |
1090 } | 1090 } |
1091 case chromeos::MOUNT_TYPE_GDATA: { | 1091 case chromeos::MOUNT_TYPE_GDATA: { |
1092 gdata::GDataSystemService* system_service = | 1092 FileBrowserEventRouterFactory::GetForProfile(profile_)-> |
1093 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 1093 MountGData(base::Bind(&AddMountFunction::SendResponse, this)); |
1094 if (system_service) { | |
1095 system_service->docs_service()->Authenticate( | |
1096 base::Bind(&AddMountFunction::OnGDataAuthentication, | |
1097 this)); | |
1098 } | |
1099 break; | 1094 break; |
1100 } | 1095 } |
1101 default: { | 1096 default: { |
1102 UrlList file_paths; | 1097 UrlList file_paths; |
1103 file_paths.push_back(GURL(file_url)); | 1098 file_paths.push_back(GURL(file_url)); |
1104 | 1099 |
1105 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( | 1100 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( |
1106 file_paths, | 1101 file_paths, |
1107 base::Bind(&AddMountFunction::GetLocalPathsResponseOnUIThread, | 1102 base::Bind(&AddMountFunction::GetLocalPathsResponseOnUIThread, |
1108 this, | 1103 this, |
1109 mount_type_str)); | 1104 mount_type_str)); |
1110 break; | 1105 break; |
1111 } | 1106 } |
1112 } | 1107 } |
1113 | 1108 |
1114 return true; | 1109 return true; |
1115 } | 1110 } |
1116 | 1111 |
1117 void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) { | |
1118 chromeos::MountError error_code = chromeos::MOUNT_ERROR_NONE; | |
1119 // For the file manager to work offline, GDATA_NO_CONNECTION is allowed. | |
1120 if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION) { | |
1121 error_code = chromeos::MOUNT_ERROR_NONE; | |
1122 } else { | |
1123 error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED; | |
1124 } | |
1125 // Pass back the gdata mount point path as source path. | |
1126 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); | |
1127 SetResult(Value::CreateStringValue(gdata_path)); | |
1128 DiskMountManager::MountPointInfo mount_info( | |
1129 gdata_path, | |
1130 gdata_path, | |
1131 chromeos::MOUNT_TYPE_GDATA, | |
1132 chromeos::disks::MOUNT_CONDITION_NONE); | |
1133 // Raise mount event | |
1134 FileBrowserEventRouterFactory::GetForProfile(profile_)-> | |
1135 MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info); | |
1136 } | |
1137 | |
1138 void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error, | |
1139 const std::string& token) { | |
1140 RaiseGDataMountEvent(error); | |
1141 SendResponse(true); | |
1142 } | |
1143 | |
1144 void AddMountFunction::GetLocalPathsResponseOnUIThread( | 1112 void AddMountFunction::GetLocalPathsResponseOnUIThread( |
1145 const std::string& mount_type_str, | 1113 const std::string& mount_type_str, |
1146 const SelectedFileInfoList& files) { | 1114 const SelectedFileInfoList& files) { |
1147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1115 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1148 | 1116 |
1149 if (!files.size()) { | 1117 if (!files.size()) { |
1150 SendResponse(false); | 1118 SendResponse(false); |
1151 return; | 1119 return; |
1152 } | 1120 } |
1153 | 1121 |
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2413 gdata::GDataSystemService* system_service = | 2381 gdata::GDataSystemService* system_service = |
2414 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 2382 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
2415 if (!system_service || !system_service->file_system()) | 2383 if (!system_service || !system_service->file_system()) |
2416 return false; | 2384 return false; |
2417 | 2385 |
2418 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2386 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
2419 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2387 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
2420 | 2388 |
2421 return true; | 2389 return true; |
2422 } | 2390 } |
OLD | NEW |