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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10219006: gdata: Move some static functions to anonymous namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 9
10 #include <set> 10 #include <set>
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 upload_file_info->all_bytes_present = true; 679 upload_file_info->all_bytes_present = true;
680 std::string mime_type; 680 std::string mime_type;
681 if (!net::GetMimeTypeFromExtension(local_file.Extension(), 681 if (!net::GetMimeTypeFromExtension(local_file.Extension(),
682 &upload_file_info->content_type)) { 682 &upload_file_info->content_type)) {
683 upload_file_info->content_type= kMimeTypeOctetStream; 683 upload_file_info->content_type= kMimeTypeOctetStream;
684 } 684 }
685 685
686 *error = base::PLATFORM_FILE_OK; 686 *error = base::PLATFORM_FILE_OK;
687 } 687 }
688 688
689 // Checks if a local file at |local_file_path| is a JSON file referencing a
690 // hosted document on IO thread poll, and if so, gets the resource ID of the
691 // document.
692 void GetDocumentResourceIdOnIOThreadPool(
693 const FilePath& local_file_path,
694 std::string* resource_id) {
695 DCHECK(resource_id);
696
697 if (DocumentEntry::HasHostedDocumentExtension(local_file_path)) {
698 std::string error;
699 DictionaryValue* dict_value = NULL;
700 JSONFileValueSerializer serializer(local_file_path);
701 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error));
702 if (value.get() && value->GetAsDictionary(&dict_value))
703 dict_value->GetString("resource_id", resource_id);
704 }
705 }
706
707 // Creates a temporary JSON file representing a document with |edit_url|
708 // and |resource_id| under |document_dir| on IO thread pool.
709 void CreateDocumentJsonFileOnIOThreadPool(
710 const FilePath& document_dir,
711 const GURL& edit_url,
712 const std::string& resource_id,
713 base::PlatformFileError* error,
714 FilePath* temp_file_path,
715 std::string* mime_type,
716 GDataFileType* file_type) {
717 DCHECK(error);
718 DCHECK(temp_file_path);
719 DCHECK(mime_type);
720 DCHECK(file_type);
721
722 *error = base::PLATFORM_FILE_ERROR_FAILED;
723
724 if (file_util::CreateTemporaryFileInDir(document_dir, temp_file_path)) {
725 std::string document_content = base::StringPrintf(
726 "{\"url\": \"%s\", \"resource_id\": \"%s\"}",
727 edit_url.spec().c_str(), resource_id.c_str());
728 int document_size = static_cast<int>(document_content.size());
729 if (file_util::WriteFile(*temp_file_path, document_content.data(),
730 document_size) == document_size) {
731 *error = base::PLATFORM_FILE_OK;
732 }
733 }
734
735 *mime_type = kMimeTypeJson;
736 *file_type = HOSTED_DOCUMENT;
737 if (*error != base::PLATFORM_FILE_OK)
738 temp_file_path->clear();
739 }
740
689 } // namespace 741 } // namespace
690 742
691 // FindEntryDelegate class implementation. 743 // FindEntryDelegate class implementation.
692 744
693 FindEntryDelegate::~FindEntryDelegate() { 745 FindEntryDelegate::~FindEntryDelegate() {
694 } 746 }
695 747
696 // FindEntryCallbackRelayDelegate class implementation. 748 // FindEntryCallbackRelayDelegate class implementation.
697 // This class is used to relay calls between sync and async versions 749 // This class is used to relay calls between sync and async versions
698 // of FindFileByPath(Sync|Async) calls. 750 // of FindFileByPath(Sync|Async) calls.
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 1178 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
1127 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); 1179 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND));
1128 NOTREACHED(); 1180 NOTREACHED();
1129 return; 1181 return;
1130 } 1182 }
1131 1183
1132 std::string* resource_id = new std::string; 1184 std::string* resource_id = new std::string;
1133 PostBlockingPoolSequencedTaskAndReply( 1185 PostBlockingPoolSequencedTaskAndReply(
1134 kGDataFileSystemToken, 1186 kGDataFileSystemToken,
1135 FROM_HERE, 1187 FROM_HERE,
1136 base::Bind(&GDataFileSystem::GetDocumentResourceIdOnIOThreadPool, 1188 base::Bind(&GetDocumentResourceIdOnIOThreadPool,
1137 local_file_path, 1189 local_file_path,
1138 resource_id), 1190 resource_id),
1139 base::Bind(&GDataFileSystem::TransferFileForResourceId, 1191 base::Bind(&GDataFileSystem::TransferFileForResourceId,
1140 GetWeakPtrForCurrentThread(), 1192 GetWeakPtrForCurrentThread(),
1141 local_file_path, 1193 local_file_path,
1142 remote_dest_file_path, 1194 remote_dest_file_path,
1143 callback, 1195 callback,
1144 base::Owned(resource_id))); 1196 base::Owned(resource_id)));
1145 } 1197 }
1146 1198
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 remote_dest_file_path, 1238 remote_dest_file_path,
1187 error, 1239 error,
1188 upload_file_info), 1240 upload_file_info),
1189 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread, 1241 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread,
1190 GetWeakPtrForCurrentThread(), 1242 GetWeakPtrForCurrentThread(),
1191 callback, 1243 callback,
1192 error, 1244 error,
1193 upload_file_info)); 1245 upload_file_info));
1194 } 1246 }
1195 1247
1196 // static
1197 void GDataFileSystem::GetDocumentResourceIdOnIOThreadPool(
1198 const FilePath& local_file_path,
1199 std::string* resource_id) {
1200 DCHECK(resource_id);
1201
1202 if (DocumentEntry::HasHostedDocumentExtension(local_file_path)) {
1203 std::string error;
1204 DictionaryValue* dict_value = NULL;
1205 JSONFileValueSerializer serializer(local_file_path);
1206 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error));
1207 if (value.get() && value->GetAsDictionary(&dict_value))
1208 dict_value->GetString("resource_id", resource_id);
1209 }
1210 }
1211
1212 void GDataFileSystem::StartFileUploadOnUIThread( 1248 void GDataFileSystem::StartFileUploadOnUIThread(
1213 const FileOperationCallback& callback, 1249 const FileOperationCallback& callback,
1214 base::PlatformFileError* error, 1250 base::PlatformFileError* error,
1215 UploadFileInfo* upload_file_info) { 1251 UploadFileInfo* upload_file_info) {
1216 // This method needs to run on the UI thread as required by 1252 // This method needs to run on the UI thread as required by
1217 // GDataUploader::UploadFile(). 1253 // GDataUploader::UploadFile().
1218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1219 DCHECK(error); 1255 DCHECK(error);
1220 DCHECK(upload_file_info); 1256 DCHECK(upload_file_info);
1221 1257
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 base::Bind(&GDataFileSystem::OnCreateDirectoryCompleted, 1664 base::Bind(&GDataFileSystem::OnCreateDirectoryCompleted,
1629 GetWeakPtrForCurrentThread(), 1665 GetWeakPtrForCurrentThread(),
1630 CreateDirectoryParams( 1666 CreateDirectoryParams(
1631 first_missing_path, 1667 first_missing_path,
1632 directory_path, 1668 directory_path,
1633 is_exclusive, 1669 is_exclusive,
1634 is_recursive, 1670 is_recursive,
1635 callback))); 1671 callback)));
1636 } 1672 }
1637 1673
1638 // static
1639 void GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool(
1640 const FilePath& document_dir,
1641 const GURL& edit_url,
1642 const std::string& resource_id,
1643 base::PlatformFileError* error,
1644 FilePath* temp_file_path,
1645 std::string* mime_type,
1646 GDataFileType* file_type) {
1647 DCHECK(error);
1648 DCHECK(temp_file_path);
1649 DCHECK(mime_type);
1650 DCHECK(file_type);
1651
1652 *error = base::PLATFORM_FILE_ERROR_FAILED;
1653
1654 if (file_util::CreateTemporaryFileInDir(document_dir, temp_file_path)) {
1655 std::string document_content = base::StringPrintf(
1656 "{\"url\": \"%s\", \"resource_id\": \"%s\"}",
1657 edit_url.spec().c_str(), resource_id.c_str());
1658 int document_size = static_cast<int>(document_content.size());
1659 if (file_util::WriteFile(*temp_file_path, document_content.data(),
1660 document_size) == document_size) {
1661 *error = base::PLATFORM_FILE_OK;
1662 }
1663 }
1664
1665 *mime_type = kMimeTypeJson;
1666 *file_type = HOSTED_DOCUMENT;
1667 if (*error != base::PLATFORM_FILE_OK)
1668 temp_file_path->clear();
1669 }
1670
1671 void GDataFileSystem::GetFileByPath(const FilePath& file_path, 1674 void GDataFileSystem::GetFileByPath(const FilePath& file_path,
1672 const GetFileCallback& callback) { 1675 const GetFileCallback& callback) {
1673 GDataFileProperties file_properties; 1676 GDataFileProperties file_properties;
1674 if (!GetFileInfoByPath(file_path, &file_properties)) { 1677 if (!GetFileInfoByPath(file_path, &file_properties)) {
1675 if (!callback.is_null()) { 1678 if (!callback.is_null()) {
1676 MessageLoop::current()->PostTask( 1679 MessageLoop::current()->PostTask(
1677 FROM_HERE, 1680 FROM_HERE,
1678 base::Bind(callback, 1681 base::Bind(callback,
1679 base::PLATFORM_FILE_ERROR_NOT_FOUND, 1682 base::PLATFORM_FILE_ERROR_NOT_FOUND,
1680 FilePath(), 1683 FilePath(),
(...skipping 11 matching lines...) Expand all
1692 InitializeCacheIfNecessary(); 1695 InitializeCacheIfNecessary();
1693 1696
1694 base::PlatformFileError* error = 1697 base::PlatformFileError* error =
1695 new base::PlatformFileError(base::PLATFORM_FILE_OK); 1698 new base::PlatformFileError(base::PLATFORM_FILE_OK);
1696 FilePath* temp_file_path = new FilePath; 1699 FilePath* temp_file_path = new FilePath;
1697 std::string* mime_type = new std::string; 1700 std::string* mime_type = new std::string;
1698 GDataFileType* file_type = new GDataFileType(REGULAR_FILE); 1701 GDataFileType* file_type = new GDataFileType(REGULAR_FILE);
1699 PostBlockingPoolSequencedTaskAndReply( 1702 PostBlockingPoolSequencedTaskAndReply(
1700 kGDataFileSystemToken, 1703 kGDataFileSystemToken,
1701 FROM_HERE, 1704 FROM_HERE,
1702 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool, 1705 base::Bind(&CreateDocumentJsonFileOnIOThreadPool,
1703 GetCacheDirectoryPath( 1706 GetCacheDirectoryPath(
1704 GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS), 1707 GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS),
1705 file_properties.alternate_url, 1708 file_properties.alternate_url,
1706 file_properties.resource_id, 1709 file_properties.resource_id,
1707 error, 1710 error,
1708 temp_file_path, 1711 temp_file_path,
1709 mime_type, 1712 mime_type,
1710 file_type), 1713 file_type),
1711 base::Bind(&RunGetFileCallbackHelper, 1714 base::Bind(&RunGetFileCallbackHelper,
1712 callback, 1715 callback,
(...skipping 2684 matching lines...) Expand 10 before | Expand all | Expand 10 after
4397 pref_registrar_->Init(profile_->GetPrefs()); 4400 pref_registrar_->Init(profile_->GetPrefs());
4398 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4401 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4399 } 4402 }
4400 4403
4401 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4404 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4402 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4405 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4403 global_free_disk_getter_for_testing = getter; 4406 global_free_disk_getter_for_testing = getter;
4404 } 4407 }
4405 4408
4406 } // namespace gdata 4409 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698