| 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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 | 846 |
| 847 GURL origin_url = source_url().GetOrigin(); | 847 GURL origin_url = source_url().GetOrigin(); |
| 848 size_t len = file_urls.size(); | 848 size_t len = file_urls.size(); |
| 849 selected_files.reserve(len); | 849 selected_files.reserve(len); |
| 850 for (size_t i = 0; i < len; ++i) { | 850 for (size_t i = 0; i < len; ++i) { |
| 851 FilePath local_path; | 851 FilePath local_path; |
| 852 const GURL& file_url = file_urls[i]; | 852 const GURL& file_url = file_urls[i]; |
| 853 | 853 |
| 854 // If "localPath" parameter is set, use it as the real path. | 854 // If "localPath" parameter is set, use it as the real path. |
| 855 // TODO(satorux): Eventually, we should be able to get the real path | 855 // TODO(satorux): Eventually, we should be able to get the real path |
| 856 // from GDataFileSystem instead of passing through with filesystem | 856 // from DriveFileSystem instead of passing through with filesystem |
| 857 // URLs. crosbug.com/27510. | 857 // URLs. crosbug.com/27510. |
| 858 // | 858 // |
| 859 // TODO(satorux): GURL::query() is not yet supported for filesystem: | 859 // TODO(satorux): GURL::query() is not yet supported for filesystem: |
| 860 // URLs. For now, use GURL::spec() to get the query portion. Should | 860 // URLs. For now, use GURL::spec() to get the query portion. Should |
| 861 // get rid of the hack once query() is supported: crbug.com/114484. | 861 // get rid of the hack once query() is supported: crbug.com/114484. |
| 862 const std::string::size_type query_start = file_url.spec().find('?'); | 862 const std::string::size_type query_start = file_url.spec().find('?'); |
| 863 if (query_start != std::string::npos) { | 863 if (query_start != std::string::npos) { |
| 864 const std::string query = file_url.spec().substr(query_start + 1); | 864 const std::string query = file_url.spec().substr(query_start + 1); |
| 865 std::vector<std::pair<std::string, std::string> > parameters; | 865 std::vector<std::pair<std::string, std::string> > parameters; |
| 866 if (base::SplitStringIntoKeyValuePairs( | 866 if (base::SplitStringIntoKeyValuePairs( |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 | 1222 |
| 1223 if (files.size() != 1) { | 1223 if (files.size() != 1) { |
| 1224 SendResponse(false); | 1224 SendResponse(false); |
| 1225 return; | 1225 return; |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 if (files[0].file_path == gdata::util::GetGDataMountPointPath()) { | 1228 if (files[0].file_path == gdata::util::GetGDataMountPointPath()) { |
| 1229 gdata::GDataSystemService* system_service = | 1229 gdata::GDataSystemService* system_service = |
| 1230 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 1230 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 1231 | 1231 |
| 1232 gdata::GDataFileSystemInterface* file_system = | 1232 gdata::DriveFileSystemInterface* file_system = |
| 1233 system_service->file_system(); | 1233 system_service->file_system(); |
| 1234 | 1234 |
| 1235 file_system->GetAvailableSpace( | 1235 file_system->GetAvailableSpace( |
| 1236 base::Bind(&GetSizeStatsFunction::GetGDataAvailableSpaceCallback, | 1236 base::Bind(&GetSizeStatsFunction::GetGDataAvailableSpaceCallback, |
| 1237 this)); | 1237 this)); |
| 1238 | 1238 |
| 1239 } else { | 1239 } else { |
| 1240 BrowserThread::PostTask( | 1240 BrowserThread::PostTask( |
| 1241 BrowserThread::FILE, FROM_HERE, | 1241 BrowserThread::FILE, FROM_HERE, |
| 1242 base::Bind( | 1242 base::Bind( |
| (...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2223 gdata::util::IsUnderGDataMountPoint(destination_file); | 2223 gdata::util::IsUnderGDataMountPoint(destination_file); |
| 2224 | 2224 |
| 2225 if (source_file_under_gdata && !destination_file_under_gdata) { | 2225 if (source_file_under_gdata && !destination_file_under_gdata) { |
| 2226 // Transfer a file from gdata to local file system. | 2226 // Transfer a file from gdata to local file system. |
| 2227 source_file = gdata::util::ExtractGDataPath(source_file); | 2227 source_file = gdata::util::ExtractGDataPath(source_file); |
| 2228 system_service->file_system()->TransferFileFromRemoteToLocal( | 2228 system_service->file_system()->TransferFileFromRemoteToLocal( |
| 2229 source_file, | 2229 source_file, |
| 2230 destination_file, | 2230 destination_file, |
| 2231 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); | 2231 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); |
| 2232 } else if (!source_file_under_gdata && destination_file_under_gdata) { | 2232 } else if (!source_file_under_gdata && destination_file_under_gdata) { |
| 2233 // Transfer a file from local to gdata file system | 2233 // Transfer a file from local to Drive file system |
| 2234 destination_file = gdata::util::ExtractGDataPath(destination_file); | 2234 destination_file = gdata::util::ExtractGDataPath(destination_file); |
| 2235 system_service->file_system()->TransferFileFromLocalToRemote( | 2235 system_service->file_system()->TransferFileFromLocalToRemote( |
| 2236 source_file, | 2236 source_file, |
| 2237 destination_file, | 2237 destination_file, |
| 2238 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); | 2238 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); |
| 2239 } else { | 2239 } else { |
| 2240 // Local-to-local or gdata-to-gdata file transfers should be done via | 2240 // Local-to-local or Drive-to-Drive file transfers should be done via |
| 2241 // FileEntry.copyTo in the File API and are thus not supported here. | 2241 // FileEntry.copyTo in the File API and are thus not supported here. |
| 2242 NOTREACHED(); | 2242 NOTREACHED(); |
| 2243 SendResponse(false); | 2243 SendResponse(false); |
| 2244 } | 2244 } |
| 2245 } | 2245 } |
| 2246 | 2246 |
| 2247 void TransferFileFunction::OnTransferCompleted(gdata::DriveFileError error) { | 2247 void TransferFileFunction::OnTransferCompleted(gdata::DriveFileError error) { |
| 2248 if (error == gdata::DRIVE_FILE_OK) { | 2248 if (error == gdata::DRIVE_FILE_OK) { |
| 2249 SendResponse(true); | 2249 SendResponse(true); |
| 2250 } else { | 2250 } else { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 const GURL& next_feed, | 2346 const GURL& next_feed, |
| 2347 scoped_ptr<std::vector<gdata::SearchResultInfo> > results) { | 2347 scoped_ptr<std::vector<gdata::SearchResultInfo> > results) { |
| 2348 if (error != gdata::DRIVE_FILE_OK) { | 2348 if (error != gdata::DRIVE_FILE_OK) { |
| 2349 SendResponse(false); | 2349 SendResponse(false); |
| 2350 return; | 2350 return; |
| 2351 } | 2351 } |
| 2352 | 2352 |
| 2353 DCHECK(results.get()); | 2353 DCHECK(results.get()); |
| 2354 | 2354 |
| 2355 base::ListValue* entries = new ListValue(); | 2355 base::ListValue* entries = new ListValue(); |
| 2356 // Convert gdata files to something File API stack can understand. | 2356 // Convert Drive files to something File API stack can understand. |
| 2357 for (size_t i = 0; i < results->size(); ++i) { | 2357 for (size_t i = 0; i < results->size(); ++i) { |
| 2358 DictionaryValue* entry = new DictionaryValue(); | 2358 DictionaryValue* entry = new DictionaryValue(); |
| 2359 entry->SetString("fileSystemName", file_system_name_); | 2359 entry->SetString("fileSystemName", file_system_name_); |
| 2360 entry->SetString("fileSystemRoot", file_system_url_.spec()); | 2360 entry->SetString("fileSystemRoot", file_system_url_.spec()); |
| 2361 entry->SetString("fileFullPath", "/" + results->at(i).path.value()); | 2361 entry->SetString("fileFullPath", "/" + results->at(i).path.value()); |
| 2362 entry->SetBoolean("fileIsDirectory", results->at(i).is_directory); | 2362 entry->SetBoolean("fileIsDirectory", results->at(i).is_directory); |
| 2363 | 2363 |
| 2364 entries->Append(entry); | 2364 entries->Append(entry); |
| 2365 } | 2365 } |
| 2366 | 2366 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 gdata::GDataSystemService* system_service = | 2420 gdata::GDataSystemService* system_service = |
| 2421 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 2421 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
| 2422 if (!system_service || !system_service->file_system()) | 2422 if (!system_service || !system_service->file_system()) |
| 2423 return false; | 2423 return false; |
| 2424 | 2424 |
| 2425 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); | 2425 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); |
| 2426 system_service->file_system()->RequestDirectoryRefresh(directory_path); | 2426 system_service->file_system()->RequestDirectoryRefresh(directory_path); |
| 2427 | 2427 |
| 2428 return true; | 2428 return true; |
| 2429 } | 2429 } |
| OLD | NEW |