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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
392 // Add gdata mount point immediately when we kick of first instance of file | 392 // Add gdata mount point immediately when we kick of first instance of file |
393 // manager. The actual mount event will be sent to UI only when we perform | 393 // manager. The actual mount event will be sent to UI only when we perform |
394 // proper authentication. | 394 // proper authentication. |
395 if (gdata::util::IsGDataAvailable(profile_)) | 395 if (gdata::util::IsGDataAvailable(profile_)) |
396 AddGDataMountPoint(profile_, extension_id(), render_view_host()); | 396 AddGDataMountPoint(profile_, extension_id(), render_view_host()); |
397 DictionaryValue* dict = new DictionaryValue(); | 397 DictionaryValue* dict = new DictionaryValue(); |
398 SetResult(dict); | 398 SetResult(dict); |
399 dict->SetString("name", name); | 399 dict->SetString("name", name); |
400 dict->SetString("path", root_path.spec()); | 400 dict->SetString("path", root_path.spec()); |
401 dict->SetInteger("error", gdata::GDATA_FILE_OK); | 401 dict->SetInteger("error", gdata::DRIVE_FILE_OK); |
402 SendResponse(true); | 402 SendResponse(true); |
403 } | 403 } |
404 | 404 |
405 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( | 405 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( |
406 base::PlatformFileError error_code) { | 406 base::PlatformFileError error_code) { |
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
408 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); | 408 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); |
409 SendResponse(false); | 409 SendResponse(false); |
410 } | 410 } |
411 | 411 |
(...skipping 688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 gdata::GDataSystemServiceFactory::GetForProfile(profile_); | 1100 gdata::GDataSystemServiceFactory::GetForProfile(profile_); |
1101 gdata::DriveCache* cache = system_service ? system_service->cache() : NULL; | 1101 gdata::DriveCache* cache = system_service ? system_service->cache() : NULL; |
1102 if (cache && cache->IsUnderDriveCacheDirectory(source_path)) { | 1102 if (cache && cache->IsUnderDriveCacheDirectory(source_path)) { |
1103 cache->SetMountedStateOnUIThread( | 1103 cache->SetMountedStateOnUIThread( |
1104 source_path, | 1104 source_path, |
1105 true, | 1105 true, |
1106 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, | 1106 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, |
1107 display_name)); | 1107 display_name)); |
1108 } else { | 1108 } else { |
1109 OnMountedStateSet(mount_type_str, display_name, | 1109 OnMountedStateSet(mount_type_str, display_name, |
1110 gdata::GDATA_FILE_OK, source_path); | 1110 gdata::DRIVE_FILE_OK, source_path); |
1111 } | 1111 } |
1112 } | 1112 } |
1113 | 1113 |
1114 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, | 1114 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, |
1115 const FilePath::StringType& file_name, | 1115 const FilePath::StringType& file_name, |
1116 gdata::GDataFileError error, | 1116 gdata::DriveFileError error, |
1117 const FilePath& file_path) { | 1117 const FilePath& file_path) { |
1118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1119 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); | 1119 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); |
1120 // Pass back the actual source path of the mount point. | 1120 // Pass back the actual source path of the mount point. |
1121 SetResult(Value::CreateStringValue(file_path.value())); | 1121 SetResult(Value::CreateStringValue(file_path.value())); |
1122 SendResponse(true); | 1122 SendResponse(true); |
1123 // MountPath() takes a std::string. | 1123 // MountPath() takes a std::string. |
1124 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), | 1124 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), |
1125 FilePath(file_name).Extension(), file_name, | 1125 FilePath(file_name).Extension(), file_name, |
1126 DiskMountManager::MountTypeFromString( | 1126 DiskMountManager::MountTypeFromString( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 BrowserThread::PostTask( | 1240 BrowserThread::PostTask( |
1241 BrowserThread::FILE, FROM_HERE, | 1241 BrowserThread::FILE, FROM_HERE, |
1242 base::Bind( | 1242 base::Bind( |
1243 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, | 1243 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, |
1244 this, | 1244 this, |
1245 files[0].file_path.value())); | 1245 files[0].file_path.value())); |
1246 } | 1246 } |
1247 } | 1247 } |
1248 | 1248 |
1249 void GetSizeStatsFunction::GetGDataAvailableSpaceCallback( | 1249 void GetSizeStatsFunction::GetGDataAvailableSpaceCallback( |
1250 gdata::GDataFileError error, | 1250 gdata::DriveFileError error, |
1251 int64 bytes_total, | 1251 int64 bytes_total, |
1252 int64 bytes_used) { | 1252 int64 bytes_used) { |
1253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1254 | 1254 |
1255 if (error == gdata::GDATA_FILE_OK) { | 1255 if (error == gdata::DRIVE_FILE_OK) { |
1256 int64 bytes_remaining = bytes_total - bytes_used; | 1256 int64 bytes_remaining = bytes_total - bytes_used; |
1257 GetSizeStatsCallbackOnUIThread(static_cast<size_t>(bytes_total/1024), | 1257 GetSizeStatsCallbackOnUIThread(static_cast<size_t>(bytes_total/1024), |
1258 static_cast<size_t>(bytes_remaining/1024)); | 1258 static_cast<size_t>(bytes_remaining/1024)); |
1259 } else { | 1259 } else { |
1260 error_ = base::StringPrintf(kFileError, static_cast<int>(error)); | 1260 error_ = base::StringPrintf(kFileError, static_cast<int>(error)); |
1261 SendResponse(false); | 1261 SendResponse(false); |
1262 } | 1262 } |
1263 } | 1263 } |
1264 | 1264 |
1265 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( | 1265 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1720 | 1720 |
1721 void GetGDataFilePropertiesFunction::DoOperation( | 1721 void GetGDataFilePropertiesFunction::DoOperation( |
1722 const FilePath& file_path, | 1722 const FilePath& file_path, |
1723 base::DictionaryValue* property_dict, | 1723 base::DictionaryValue* property_dict, |
1724 scoped_ptr<gdata::DriveEntryProto> entry_proto) { | 1724 scoped_ptr<gdata::DriveEntryProto> entry_proto) { |
1725 DCHECK(property_dict); | 1725 DCHECK(property_dict); |
1726 | 1726 |
1727 // Nothing to do here so simply call OnOperationComplete(). | 1727 // Nothing to do here so simply call OnOperationComplete(). |
1728 OnOperationComplete(file_path, | 1728 OnOperationComplete(file_path, |
1729 property_dict, | 1729 property_dict, |
1730 gdata::GDATA_FILE_OK, | 1730 gdata::DRIVE_FILE_OK, |
1731 entry_proto.Pass()); | 1731 entry_proto.Pass()); |
1732 } | 1732 } |
1733 | 1733 |
1734 bool GetGDataFilePropertiesFunction::RunImpl() { | 1734 bool GetGDataFilePropertiesFunction::RunImpl() { |
1735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1735 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1736 if (args_->GetSize() != 1) | 1736 if (args_->GetSize() != 1) |
1737 return false; | 1737 return false; |
1738 | 1738 |
1739 PrepareResults(); | 1739 PrepareResults(); |
1740 return true; | 1740 return true; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 current_index_++; | 1782 current_index_++; |
1783 | 1783 |
1784 // Could be called from callback. Let finish operation. | 1784 // Could be called from callback. Let finish operation. |
1785 MessageLoop::current()->PostTask(FROM_HERE, | 1785 MessageLoop::current()->PostTask(FROM_HERE, |
1786 Bind(&GetGDataFilePropertiesFunction::GetNextFileProperties, this)); | 1786 Bind(&GetGDataFilePropertiesFunction::GetNextFileProperties, this)); |
1787 } | 1787 } |
1788 | 1788 |
1789 void GetGDataFilePropertiesFunction::OnGetFileInfo( | 1789 void GetGDataFilePropertiesFunction::OnGetFileInfo( |
1790 const FilePath& file_path, | 1790 const FilePath& file_path, |
1791 base::DictionaryValue* property_dict, | 1791 base::DictionaryValue* property_dict, |
1792 gdata::GDataFileError error, | 1792 gdata::DriveFileError error, |
1793 scoped_ptr<gdata::DriveEntryProto> entry_proto) { | 1793 scoped_ptr<gdata::DriveEntryProto> entry_proto) { |
1794 DCHECK(property_dict); | 1794 DCHECK(property_dict); |
1795 | 1795 |
1796 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 1796 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
1797 error = gdata::GDATA_FILE_ERROR_NOT_FOUND; | 1797 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND; |
1798 | 1798 |
1799 if (error == gdata::GDATA_FILE_OK) | 1799 if (error == gdata::DRIVE_FILE_OK) |
1800 DoOperation(file_path, property_dict, entry_proto.Pass()); | 1800 DoOperation(file_path, property_dict, entry_proto.Pass()); |
1801 else | 1801 else |
1802 OnOperationComplete(file_path, property_dict, error, entry_proto.Pass()); | 1802 OnOperationComplete(file_path, property_dict, error, entry_proto.Pass()); |
1803 } | 1803 } |
1804 | 1804 |
1805 void GetGDataFilePropertiesFunction::OnOperationComplete( | 1805 void GetGDataFilePropertiesFunction::OnOperationComplete( |
1806 const FilePath& file_path, | 1806 const FilePath& file_path, |
1807 base::DictionaryValue* property_dict, | 1807 base::DictionaryValue* property_dict, |
1808 gdata::GDataFileError error, | 1808 gdata::DriveFileError error, |
1809 scoped_ptr<gdata::DriveEntryProto> entry_proto) { | 1809 scoped_ptr<gdata::DriveEntryProto> entry_proto) { |
1810 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 1810 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
1811 error = gdata::GDATA_FILE_ERROR_NOT_FOUND; | 1811 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND; |
1812 | 1812 |
1813 if (error != gdata::GDATA_FILE_OK) { | 1813 if (error != gdata::DRIVE_FILE_OK) { |
1814 property_dict->SetInteger("errorCode", error); | 1814 property_dict->SetInteger("errorCode", error); |
1815 CompleteGetFileProperties(); | 1815 CompleteGetFileProperties(); |
1816 return; | 1816 return; |
1817 } | 1817 } |
1818 DCHECK(entry_proto.get()); | 1818 DCHECK(entry_proto.get()); |
1819 | 1819 |
1820 const gdata::DriveFileSpecificInfo& file_specific_info = | 1820 const gdata::DriveFileSpecificInfo& file_specific_info = |
1821 entry_proto->file_specific_info(); | 1821 entry_proto->file_specific_info(); |
1822 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); | 1822 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); |
1823 if (!file_specific_info.alternate_url().empty()) | 1823 if (!file_specific_info.alternate_url().empty()) |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1934 if (set_pin_) | 1934 if (set_pin_) |
1935 system_service->cache()->PinOnUIThread(resource_id, md5, callback); | 1935 system_service->cache()->PinOnUIThread(resource_id, md5, callback); |
1936 else | 1936 else |
1937 system_service->cache()->UnpinOnUIThread(resource_id, md5, callback); | 1937 system_service->cache()->UnpinOnUIThread(resource_id, md5, callback); |
1938 } | 1938 } |
1939 | 1939 |
1940 void PinGDataFileFunction::OnPinStateSet( | 1940 void PinGDataFileFunction::OnPinStateSet( |
1941 const FilePath& path, | 1941 const FilePath& path, |
1942 base::DictionaryValue* properties, | 1942 base::DictionaryValue* properties, |
1943 scoped_ptr<gdata::DriveEntryProto> entry_proto, | 1943 scoped_ptr<gdata::DriveEntryProto> entry_proto, |
1944 gdata::GDataFileError error, | 1944 gdata::DriveFileError error, |
1945 const std::string& /* resource_id */, | 1945 const std::string& /* resource_id */, |
1946 const std::string& /* md5 */) { | 1946 const std::string& /* md5 */) { |
1947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1947 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1948 | 1948 |
1949 OnOperationComplete(path, properties, error, entry_proto.Pass()); | 1949 OnOperationComplete(path, properties, error, entry_proto.Pass()); |
1950 } | 1950 } |
1951 | 1951 |
1952 GetFileLocationsFunction::GetFileLocationsFunction() { | 1952 GetFileLocationsFunction::GetFileLocationsFunction() { |
1953 } | 1953 } |
1954 | 1954 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 // Get the file on the top of the queue. | 2050 // Get the file on the top of the queue. |
2051 FilePath gdata_path = remaining_gdata_paths_.front(); | 2051 FilePath gdata_path = remaining_gdata_paths_.front(); |
2052 system_service->file_system()->GetFileByPath( | 2052 system_service->file_system()->GetFileByPath( |
2053 gdata_path, | 2053 gdata_path, |
2054 base::Bind(&GetGDataFilesFunction::OnFileReady, this), | 2054 base::Bind(&GetGDataFilesFunction::OnFileReady, this), |
2055 gdata::GetContentCallback()); | 2055 gdata::GetContentCallback()); |
2056 } | 2056 } |
2057 | 2057 |
2058 | 2058 |
2059 void GetGDataFilesFunction::OnFileReady( | 2059 void GetGDataFilesFunction::OnFileReady( |
2060 gdata::GDataFileError error, | 2060 gdata::DriveFileError error, |
2061 const FilePath& local_path, | 2061 const FilePath& local_path, |
2062 const std::string& unused_mime_type, | 2062 const std::string& unused_mime_type, |
2063 gdata::DriveFileType file_type) { | 2063 gdata::DriveFileType file_type) { |
2064 FilePath gdata_path = remaining_gdata_paths_.front(); | 2064 FilePath gdata_path = remaining_gdata_paths_.front(); |
2065 | 2065 |
2066 if (error == gdata::GDATA_FILE_OK) { | 2066 if (error == gdata::DRIVE_FILE_OK) { |
2067 local_paths_->Append(Value::CreateStringValue(local_path.value())); | 2067 local_paths_->Append(Value::CreateStringValue(local_path.value())); |
2068 DVLOG(1) << "Got " << gdata_path.value() << " as " << local_path.value(); | 2068 DVLOG(1) << "Got " << gdata_path.value() << " as " << local_path.value(); |
2069 | 2069 |
2070 // TODO(benchan): If the file is a hosted document, a temporary JSON file | 2070 // TODO(benchan): If the file is a hosted document, a temporary JSON file |
2071 // is created to represent the document. The JSON file is not cached and | 2071 // is created to represent the document. The JSON file is not cached and |
2072 // should be deleted after use. We need to somehow communicate with | 2072 // should be deleted after use. We need to somehow communicate with |
2073 // file_manager.js to manage the lifetime of the temporary file. | 2073 // file_manager.js to manage the lifetime of the temporary file. |
2074 // See crosbug.com/28058. | 2074 // See crosbug.com/28058. |
2075 } else { | 2075 } else { |
2076 local_paths_->Append(Value::CreateStringValue("")); | 2076 local_paths_->Append(Value::CreateStringValue("")); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 gdata-to-gdata 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::GDataFileError error) { | 2247 void TransferFileFunction::OnTransferCompleted(gdata::DriveFileError error) { |
2248 if (error == gdata::GDATA_FILE_OK) { | 2248 if (error == gdata::DRIVE_FILE_OK) { |
2249 SendResponse(true); | 2249 SendResponse(true); |
2250 } else { | 2250 } else { |
2251 error_ = base::StringPrintf("%d", static_cast<int>( | 2251 error_ = base::StringPrintf("%d", static_cast<int>( |
2252 fileapi::PlatformFileErrorToWebFileError( | 2252 fileapi::PlatformFileErrorToWebFileError( |
2253 gdata::util::GDataFileErrorToPlatformError(error)))); | 2253 gdata::util::DriveFileErrorToPlatformError(error)))); |
2254 SendResponse(false); | 2254 SendResponse(false); |
2255 } | 2255 } |
2256 } | 2256 } |
2257 | 2257 |
2258 // Read GData-related preferences. | 2258 // Read GData-related preferences. |
2259 bool GetGDataPreferencesFunction::RunImpl() { | 2259 bool GetGDataPreferencesFunction::RunImpl() { |
2260 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | 2260 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
2261 | 2261 |
2262 const PrefService* service = profile_->GetPrefs(); | 2262 const PrefService* service = profile_->GetPrefs(); |
2263 | 2263 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2335 SendResponse(false); | 2335 SendResponse(false); |
2336 return; | 2336 return; |
2337 } | 2337 } |
2338 | 2338 |
2339 system_service->file_system()->Search( | 2339 system_service->file_system()->Search( |
2340 query_, GURL(next_feed_), | 2340 query_, GURL(next_feed_), |
2341 base::Bind(&SearchDriveFunction::OnSearch, this)); | 2341 base::Bind(&SearchDriveFunction::OnSearch, this)); |
2342 } | 2342 } |
2343 | 2343 |
2344 void SearchDriveFunction::OnSearch( | 2344 void SearchDriveFunction::OnSearch( |
2345 gdata::GDataFileError error, | 2345 gdata::DriveFileError error, |
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::GDATA_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 gdata 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(); |
(...skipping 61 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 |