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

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

Issue 10877006: Rename GDataErrorCode to DriveErrorCode, GDataFileError to DriveFileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. 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 | Annotate | Revision Log
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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
483 // Add gdata mount point immediately when we kick of first instance of file 483 // Add gdata mount point immediately when we kick of first instance of file
484 // manager. The actual mount event will be sent to UI only when we perform 484 // manager. The actual mount event will be sent to UI only when we perform
485 // proper authentication. 485 // proper authentication.
486 if (gdata::util::IsGDataAvailable(profile_)) 486 if (gdata::util::IsGDataAvailable(profile_))
487 AddGDataMountPoint(profile_, extension_id(), render_view_host()); 487 AddGDataMountPoint(profile_, extension_id(), render_view_host());
488 DictionaryValue* dict = new DictionaryValue(); 488 DictionaryValue* dict = new DictionaryValue();
489 SetResult(dict); 489 SetResult(dict);
490 dict->SetString("name", name); 490 dict->SetString("name", name);
491 dict->SetString("path", root_path.spec()); 491 dict->SetString("path", root_path.spec());
492 dict->SetInteger("error", gdata::GDATA_FILE_OK); 492 dict->SetInteger("error", gdata::DRIVE_FILE_OK);
493 SendResponse(true); 493 SendResponse(true);
494 } 494 }
495 495
496 void RequestLocalFileSystemFunction::RespondFailedOnUIThread( 496 void RequestLocalFileSystemFunction::RespondFailedOnUIThread(
497 base::PlatformFileError error_code) { 497 base::PlatformFileError error_code) {
498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
499 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code)); 499 error_ = base::StringPrintf(kFileError, static_cast<int>(error_code));
500 SendResponse(false); 500 SendResponse(false);
501 } 501 }
502 502
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 1079 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
1080 gdata::DriveCache* cache = system_service ? system_service->cache() : NULL; 1080 gdata::DriveCache* cache = system_service ? system_service->cache() : NULL;
1081 if (cache && cache->IsUnderDriveCacheDirectory(source_path)) { 1081 if (cache && cache->IsUnderDriveCacheDirectory(source_path)) {
1082 cache->SetMountedStateOnUIThread( 1082 cache->SetMountedStateOnUIThread(
1083 source_path, 1083 source_path,
1084 true, 1084 true,
1085 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str, 1085 base::Bind(&AddMountFunction::OnMountedStateSet, this, mount_type_str,
1086 display_name)); 1086 display_name));
1087 } else { 1087 } else {
1088 OnMountedStateSet(mount_type_str, display_name, 1088 OnMountedStateSet(mount_type_str, display_name,
1089 gdata::GDATA_FILE_OK, source_path); 1089 gdata::DRIVE_FILE_OK, source_path);
1090 } 1090 }
1091 } 1091 }
1092 1092
1093 void AddMountFunction::OnMountedStateSet(const std::string& mount_type, 1093 void AddMountFunction::OnMountedStateSet(const std::string& mount_type,
1094 const FilePath::StringType& file_name, 1094 const FilePath::StringType& file_name,
1095 gdata::GDataFileError error, 1095 gdata::DriveFileError error,
1096 const FilePath& file_path) { 1096 const FilePath& file_path) {
1097 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1097 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1098 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 1098 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
1099 // Pass back the actual source path of the mount point. 1099 // Pass back the actual source path of the mount point.
1100 SetResult(Value::CreateStringValue(file_path.value())); 1100 SetResult(Value::CreateStringValue(file_path.value()));
1101 SendResponse(true); 1101 SendResponse(true);
1102 // MountPath() takes a std::string. 1102 // MountPath() takes a std::string.
1103 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(), 1103 disk_mount_manager->MountPath(file_path.AsUTF8Unsafe(),
1104 FilePath(file_name).Extension(), file_name, 1104 FilePath(file_name).Extension(), file_name,
1105 DiskMountManager::MountTypeFromString( 1105 DiskMountManager::MountTypeFromString(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 BrowserThread::PostTask( 1219 BrowserThread::PostTask(
1220 BrowserThread::FILE, FROM_HERE, 1220 BrowserThread::FILE, FROM_HERE,
1221 base::Bind( 1221 base::Bind(
1222 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread, 1222 &GetSizeStatsFunction::CallGetSizeStatsOnFileThread,
1223 this, 1223 this,
1224 files[0].file_path.value())); 1224 files[0].file_path.value()));
1225 } 1225 }
1226 } 1226 }
1227 1227
1228 void GetSizeStatsFunction::GetGDataAvailableSpaceCallback( 1228 void GetSizeStatsFunction::GetGDataAvailableSpaceCallback(
1229 gdata::GDataFileError error, 1229 gdata::DriveFileError error,
1230 int64 bytes_total, 1230 int64 bytes_total,
1231 int64 bytes_used) { 1231 int64 bytes_used) {
1232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1233 1233
1234 if (error == gdata::GDATA_FILE_OK) { 1234 if (error == gdata::DRIVE_FILE_OK) {
1235 int64 bytes_remaining = bytes_total - bytes_used; 1235 int64 bytes_remaining = bytes_total - bytes_used;
1236 GetSizeStatsCallbackOnUIThread(static_cast<size_t>(bytes_total/1024), 1236 GetSizeStatsCallbackOnUIThread(static_cast<size_t>(bytes_total/1024),
1237 static_cast<size_t>(bytes_remaining/1024)); 1237 static_cast<size_t>(bytes_remaining/1024));
1238 } else { 1238 } else {
1239 error_ = base::StringPrintf(kFileError, static_cast<int>(error)); 1239 error_ = base::StringPrintf(kFileError, static_cast<int>(error));
1240 SendResponse(false); 1240 SendResponse(false);
1241 } 1241 }
1242 } 1242 }
1243 1243
1244 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread( 1244 void GetSizeStatsFunction::CallGetSizeStatsOnFileThread(
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 1699
1700 void GetGDataFilePropertiesFunction::DoOperation( 1700 void GetGDataFilePropertiesFunction::DoOperation(
1701 const FilePath& file_path, 1701 const FilePath& file_path,
1702 base::DictionaryValue* property_dict, 1702 base::DictionaryValue* property_dict,
1703 scoped_ptr<gdata::DriveEntryProto> entry_proto) { 1703 scoped_ptr<gdata::DriveEntryProto> entry_proto) {
1704 DCHECK(property_dict); 1704 DCHECK(property_dict);
1705 1705
1706 // Nothing to do here so simply call OnOperationComplete(). 1706 // Nothing to do here so simply call OnOperationComplete().
1707 OnOperationComplete(file_path, 1707 OnOperationComplete(file_path,
1708 property_dict, 1708 property_dict,
1709 gdata::GDATA_FILE_OK, 1709 gdata::DRIVE_FILE_OK,
1710 entry_proto.Pass()); 1710 entry_proto.Pass());
1711 } 1711 }
1712 1712
1713 bool GetGDataFilePropertiesFunction::RunImpl() { 1713 bool GetGDataFilePropertiesFunction::RunImpl() {
1714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1715 if (args_->GetSize() != 1) 1715 if (args_->GetSize() != 1)
1716 return false; 1716 return false;
1717 1717
1718 PrepareResults(); 1718 PrepareResults();
1719 return true; 1719 return true;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 current_index_++; 1761 current_index_++;
1762 1762
1763 // Could be called from callback. Let finish operation. 1763 // Could be called from callback. Let finish operation.
1764 MessageLoop::current()->PostTask(FROM_HERE, 1764 MessageLoop::current()->PostTask(FROM_HERE,
1765 Bind(&GetGDataFilePropertiesFunction::GetNextFileProperties, this)); 1765 Bind(&GetGDataFilePropertiesFunction::GetNextFileProperties, this));
1766 } 1766 }
1767 1767
1768 void GetGDataFilePropertiesFunction::OnGetFileInfo( 1768 void GetGDataFilePropertiesFunction::OnGetFileInfo(
1769 const FilePath& file_path, 1769 const FilePath& file_path,
1770 base::DictionaryValue* property_dict, 1770 base::DictionaryValue* property_dict,
1771 gdata::GDataFileError error, 1771 gdata::DriveFileError error,
1772 scoped_ptr<gdata::DriveEntryProto> entry_proto) { 1772 scoped_ptr<gdata::DriveEntryProto> entry_proto) {
1773 DCHECK(property_dict); 1773 DCHECK(property_dict);
1774 1774
1775 if (entry_proto.get() && !entry_proto->has_file_specific_info()) 1775 if (entry_proto.get() && !entry_proto->has_file_specific_info())
1776 error = gdata::GDATA_FILE_ERROR_NOT_FOUND; 1776 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND;
1777 1777
1778 if (error == gdata::GDATA_FILE_OK) 1778 if (error == gdata::DRIVE_FILE_OK)
1779 DoOperation(file_path, property_dict, entry_proto.Pass()); 1779 DoOperation(file_path, property_dict, entry_proto.Pass());
1780 else 1780 else
1781 OnOperationComplete(file_path, property_dict, error, entry_proto.Pass()); 1781 OnOperationComplete(file_path, property_dict, error, entry_proto.Pass());
1782 } 1782 }
1783 1783
1784 void GetGDataFilePropertiesFunction::OnOperationComplete( 1784 void GetGDataFilePropertiesFunction::OnOperationComplete(
1785 const FilePath& file_path, 1785 const FilePath& file_path,
1786 base::DictionaryValue* property_dict, 1786 base::DictionaryValue* property_dict,
1787 gdata::GDataFileError error, 1787 gdata::DriveFileError error,
1788 scoped_ptr<gdata::DriveEntryProto> entry_proto) { 1788 scoped_ptr<gdata::DriveEntryProto> entry_proto) {
1789 if (entry_proto.get() && !entry_proto->has_file_specific_info()) 1789 if (entry_proto.get() && !entry_proto->has_file_specific_info())
1790 error = gdata::GDATA_FILE_ERROR_NOT_FOUND; 1790 error = gdata::DRIVE_FILE_ERROR_NOT_FOUND;
1791 1791
1792 if (error != gdata::GDATA_FILE_OK) { 1792 if (error != gdata::DRIVE_FILE_OK) {
1793 property_dict->SetInteger("errorCode", error); 1793 property_dict->SetInteger("errorCode", error);
1794 CompleteGetFileProperties(); 1794 CompleteGetFileProperties();
1795 return; 1795 return;
1796 } 1796 }
1797 DCHECK(entry_proto.get()); 1797 DCHECK(entry_proto.get());
1798 1798
1799 const gdata::DriveFileSpecificInfo& file_specific_info = 1799 const gdata::DriveFileSpecificInfo& file_specific_info =
1800 entry_proto->file_specific_info(); 1800 entry_proto->file_specific_info();
1801 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url()); 1801 property_dict->SetString("thumbnailUrl", file_specific_info.thumbnail_url());
1802 if (!file_specific_info.alternate_url().empty()) 1802 if (!file_specific_info.alternate_url().empty())
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 if (set_pin_) 1900 if (set_pin_)
1901 system_service->cache()->PinOnUIThread(resource_id, md5, callback); 1901 system_service->cache()->PinOnUIThread(resource_id, md5, callback);
1902 else 1902 else
1903 system_service->cache()->UnpinOnUIThread(resource_id, md5, callback); 1903 system_service->cache()->UnpinOnUIThread(resource_id, md5, callback);
1904 } 1904 }
1905 1905
1906 void PinGDataFileFunction::OnPinStateSet( 1906 void PinGDataFileFunction::OnPinStateSet(
1907 const FilePath& path, 1907 const FilePath& path,
1908 base::DictionaryValue* properties, 1908 base::DictionaryValue* properties,
1909 scoped_ptr<gdata::DriveEntryProto> entry_proto, 1909 scoped_ptr<gdata::DriveEntryProto> entry_proto,
1910 gdata::GDataFileError error, 1910 gdata::DriveFileError error,
1911 const std::string& /* resource_id */, 1911 const std::string& /* resource_id */,
1912 const std::string& /* md5 */) { 1912 const std::string& /* md5 */) {
1913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1914 1914
1915 OnOperationComplete(path, properties, error, entry_proto.Pass()); 1915 OnOperationComplete(path, properties, error, entry_proto.Pass());
1916 } 1916 }
1917 1917
1918 GetFileLocationsFunction::GetFileLocationsFunction() { 1918 GetFileLocationsFunction::GetFileLocationsFunction() {
1919 } 1919 }
1920 1920
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 // Get the file on the top of the queue. 2016 // Get the file on the top of the queue.
2017 FilePath gdata_path = remaining_gdata_paths_.front(); 2017 FilePath gdata_path = remaining_gdata_paths_.front();
2018 system_service->file_system()->GetFileByPath( 2018 system_service->file_system()->GetFileByPath(
2019 gdata_path, 2019 gdata_path,
2020 base::Bind(&GetGDataFilesFunction::OnFileReady, this), 2020 base::Bind(&GetGDataFilesFunction::OnFileReady, this),
2021 gdata::GetContentCallback()); 2021 gdata::GetContentCallback());
2022 } 2022 }
2023 2023
2024 2024
2025 void GetGDataFilesFunction::OnFileReady( 2025 void GetGDataFilesFunction::OnFileReady(
2026 gdata::GDataFileError error, 2026 gdata::DriveFileError error,
2027 const FilePath& local_path, 2027 const FilePath& local_path,
2028 const std::string& unused_mime_type, 2028 const std::string& unused_mime_type,
2029 gdata::DriveFileType file_type) { 2029 gdata::DriveFileType file_type) {
2030 FilePath gdata_path = remaining_gdata_paths_.front(); 2030 FilePath gdata_path = remaining_gdata_paths_.front();
2031 2031
2032 if (error == gdata::GDATA_FILE_OK) { 2032 if (error == gdata::DRIVE_FILE_OK) {
2033 local_paths_->Append(Value::CreateStringValue(local_path.value())); 2033 local_paths_->Append(Value::CreateStringValue(local_path.value()));
2034 DVLOG(1) << "Got " << gdata_path.value() << " as " << local_path.value(); 2034 DVLOG(1) << "Got " << gdata_path.value() << " as " << local_path.value();
2035 2035
2036 // TODO(benchan): If the file is a hosted document, a temporary JSON file 2036 // TODO(benchan): If the file is a hosted document, a temporary JSON file
2037 // is created to represent the document. The JSON file is not cached and 2037 // is created to represent the document. The JSON file is not cached and
2038 // should be deleted after use. We need to somehow communicate with 2038 // should be deleted after use. We need to somehow communicate with
2039 // file_manager.js to manage the lifetime of the temporary file. 2039 // file_manager.js to manage the lifetime of the temporary file.
2040 // See crosbug.com/28058. 2040 // See crosbug.com/28058.
2041 } else { 2041 } else {
2042 local_paths_->Append(Value::CreateStringValue("")); 2042 local_paths_->Append(Value::CreateStringValue(""));
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2203 destination_file, 2203 destination_file,
2204 base::Bind(&TransferFileFunction::OnTransferCompleted, this)); 2204 base::Bind(&TransferFileFunction::OnTransferCompleted, this));
2205 } else { 2205 } else {
2206 // Local-to-local or gdata-to-gdata file transfers should be done via 2206 // Local-to-local or gdata-to-gdata file transfers should be done via
2207 // FileEntry.copyTo in the File API and are thus not supported here. 2207 // FileEntry.copyTo in the File API and are thus not supported here.
2208 NOTREACHED(); 2208 NOTREACHED();
2209 SendResponse(false); 2209 SendResponse(false);
2210 } 2210 }
2211 } 2211 }
2212 2212
2213 void TransferFileFunction::OnTransferCompleted(gdata::GDataFileError error) { 2213 void TransferFileFunction::OnTransferCompleted(gdata::DriveFileError error) {
2214 if (error == gdata::GDATA_FILE_OK) { 2214 if (error == gdata::DRIVE_FILE_OK) {
2215 SendResponse(true); 2215 SendResponse(true);
2216 } else { 2216 } else {
2217 error_ = base::StringPrintf("%d", static_cast<int>( 2217 error_ = base::StringPrintf("%d", static_cast<int>(
2218 fileapi::PlatformFileErrorToWebFileError( 2218 fileapi::PlatformFileErrorToWebFileError(
2219 gdata::util::GDataFileErrorToPlatformError(error)))); 2219 gdata::util::DriveFileErrorToPlatformError(error))));
2220 SendResponse(false); 2220 SendResponse(false);
2221 } 2221 }
2222 } 2222 }
2223 2223
2224 // Read GData-related preferences. 2224 // Read GData-related preferences.
2225 bool GetGDataPreferencesFunction::RunImpl() { 2225 bool GetGDataPreferencesFunction::RunImpl() {
2226 scoped_ptr<DictionaryValue> value(new DictionaryValue()); 2226 scoped_ptr<DictionaryValue> value(new DictionaryValue());
2227 2227
2228 const PrefService* service = profile_->GetPrefs(); 2228 const PrefService* service = profile_->GetPrefs();
2229 2229
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2301 SendResponse(false); 2301 SendResponse(false);
2302 return; 2302 return;
2303 } 2303 }
2304 2304
2305 system_service->file_system()->Search( 2305 system_service->file_system()->Search(
2306 query_, GURL(next_feed_), 2306 query_, GURL(next_feed_),
2307 base::Bind(&SearchDriveFunction::OnSearch, this)); 2307 base::Bind(&SearchDriveFunction::OnSearch, this));
2308 } 2308 }
2309 2309
2310 void SearchDriveFunction::OnSearch( 2310 void SearchDriveFunction::OnSearch(
2311 gdata::GDataFileError error, 2311 gdata::DriveFileError error,
2312 const GURL& next_feed, 2312 const GURL& next_feed,
2313 scoped_ptr<std::vector<gdata::SearchResultInfo> > results) { 2313 scoped_ptr<std::vector<gdata::SearchResultInfo> > results) {
2314 if (error != gdata::GDATA_FILE_OK) { 2314 if (error != gdata::DRIVE_FILE_OK) {
2315 SendResponse(false); 2315 SendResponse(false);
2316 return; 2316 return;
2317 } 2317 }
2318 2318
2319 DCHECK(results.get()); 2319 DCHECK(results.get());
2320 2320
2321 base::ListValue* entries = new ListValue(); 2321 base::ListValue* entries = new ListValue();
2322 // Convert gdata files to something File API stack can understand. 2322 // Convert gdata files to something File API stack can understand.
2323 for (size_t i = 0; i < results->size(); ++i) { 2323 for (size_t i = 0; i < results->size(); ++i) {
2324 DictionaryValue* entry = new DictionaryValue(); 2324 DictionaryValue* entry = new DictionaryValue();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 gdata::GDataSystemService* system_service = 2386 gdata::GDataSystemService* system_service =
2387 gdata::GDataSystemServiceFactory::GetForProfile(profile_); 2387 gdata::GDataSystemServiceFactory::GetForProfile(profile_);
2388 if (!system_service || !system_service->file_system()) 2388 if (!system_service || !system_service->file_system())
2389 return false; 2389 return false;
2390 2390
2391 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string)); 2391 FilePath directory_path = GetVirtualPathFromURL(GURL(file_url_as_string));
2392 system_service->file_system()->RequestDirectoryRefresh(directory_path); 2392 system_service->file_system()->RequestDirectoryRefresh(directory_path);
2393 2393
2394 return true; 2394 return true;
2395 } 2395 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698