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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_private_api.cc

Issue 10834115: Drive: Mount/Unmount GoogleDrive on Files App when the file system is mounted/unmounted. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add a comment. Created 8 years, 4 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/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 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 SendResponse(true); 1047 SendResponse(true);
1048 } 1048 }
1049 1049
1050 bool CancelFileDialogFunction::RunImpl() { 1050 bool CancelFileDialogFunction::RunImpl() {
1051 int32 tab_id = GetTabId(); 1051 int32 tab_id = GetTabId();
1052 SelectFileDialogExtension::OnFileSelectionCanceled(tab_id); 1052 SelectFileDialogExtension::OnFileSelectionCanceled(tab_id);
1053 SendResponse(true); 1053 SendResponse(true);
1054 return true; 1054 return true;
1055 } 1055 }
1056 1056
1057 AddMountFunction::AddMountFunction() { 1057 AddMountFunction::AddMountFunction()
1058 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
satorux1 2012/08/02 01:13:05 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(t
yoshiki 2012/08/02 05:53:42 The example usage in base/compiler_specific.h sugg
1058 } 1059 }
1059 1060
1060 AddMountFunction::~AddMountFunction() { 1061 AddMountFunction::~AddMountFunction() {
1061 } 1062 }
1062 1063
1063 bool AddMountFunction::RunImpl() { 1064 bool AddMountFunction::RunImpl() {
1064 // The third argument is simply ignored. 1065 // The third argument is simply ignored.
1065 if (args_->GetSize() != 2 && args_->GetSize() != 3) { 1066 if (args_->GetSize() != 2 && args_->GetSize() != 3) {
1066 error_ = "Invalid argument count"; 1067 error_ = "Invalid argument count";
1067 return false; 1068 return false;
(...skipping 14 matching lines...) Expand all
1082 1083
1083 chromeos::MountType mount_type = 1084 chromeos::MountType mount_type =
1084 DiskMountManager::MountTypeFromString(mount_type_str); 1085 DiskMountManager::MountTypeFromString(mount_type_str);
1085 switch (mount_type) { 1086 switch (mount_type) {
1086 case chromeos::MOUNT_TYPE_INVALID: { 1087 case chromeos::MOUNT_TYPE_INVALID: {
1087 error_ = "Invalid mount type"; 1088 error_ = "Invalid mount type";
1088 SendResponse(false); 1089 SendResponse(false);
1089 break; 1090 break;
1090 } 1091 }
1091 case chromeos::MOUNT_TYPE_GDATA: { 1092 case chromeos::MOUNT_TYPE_GDATA: {
1092 gdata::GDataSystemService* system_service = 1093 const bool success = true;
1093 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 1094 FileBrowserEventRouterFactory::GetForProfile(profile_)->
1094 if (system_service) { 1095 MountDrive(base::Bind(&AddMountFunction::SendResponse,
1095 system_service->docs_service()->Authenticate( 1096 weak_ptr_factory_.GetWeakPtr(),
1096 base::Bind(&AddMountFunction::OnGDataAuthentication, 1097 success));
1097 this));
1098 }
1099 break; 1098 break;
1100 } 1099 }
1101 default: { 1100 default: {
1102 UrlList file_paths; 1101 UrlList file_paths;
1103 file_paths.push_back(GURL(file_url)); 1102 file_paths.push_back(GURL(file_url));
1104 1103
1105 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread( 1104 GetLocalPathsOnFileThreadAndRunCallbackOnUIThread(
1106 file_paths, 1105 file_paths,
1107 base::Bind(&AddMountFunction::GetLocalPathsResponseOnUIThread, 1106 base::Bind(&AddMountFunction::GetLocalPathsResponseOnUIThread,
1108 this, 1107 weak_ptr_factory_.GetWeakPtr(),
1109 mount_type_str)); 1108 mount_type_str));
1110 break; 1109 break;
1111 } 1110 }
1112 } 1111 }
1113 1112
1114 return true; 1113 return true;
1115 } 1114 }
1116 1115
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( 1116 void AddMountFunction::GetLocalPathsResponseOnUIThread(
1145 const std::string& mount_type_str, 1117 const std::string& mount_type_str,
1146 const SelectedFileInfoList& files) { 1118 const SelectedFileInfoList& files) {
1147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1119 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1148 1120
1149 if (!files.size()) { 1121 if (!files.size()) {
1150 SendResponse(false); 1122 SendResponse(false);
1151 return; 1123 return;
1152 } 1124 }
1153 1125
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2413 gdata::GDataSystemService* system_service = 2385 gdata::GDataSystemService* system_service =
2414 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 2386 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
2415 if (!system_service || !system_service->file_system()) 2387 if (!system_service || !system_service->file_system())
2416 return false; 2388 return false;
2417 2389
2418 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); 2390 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string));
2419 system_service->file_system()->RequestDirectoryRefresh(directory_path); 2391 system_service->file_system()->RequestDirectoryRefresh(directory_path);
2420 2392
2421 return true; 2393 return true;
2422 } 2394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698