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

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

Issue 9834091: gdata: Fix issue with copying hosted documents out from Docs folder. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 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/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 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); 46 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1");
47 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); 47 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta");
48 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); 48 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned");
49 const FilePath::CharType kGDataCacheOutgoingDir[] = 49 const FilePath::CharType kGDataCacheOutgoingDir[] =
50 FILE_PATH_LITERAL("outgoing"); 50 FILE_PATH_LITERAL("outgoing");
51 const FilePath::CharType kGDataCachePersistentDir[] = 51 const FilePath::CharType kGDataCachePersistentDir[] =
52 FILE_PATH_LITERAL("persistent"); 52 FILE_PATH_LITERAL("persistent");
53 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp"); 53 const FilePath::CharType kGDataCacheTmpDir[] = FILE_PATH_LITERAL("tmp");
54 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = 54 const FilePath::CharType kGDataCacheTmpDownloadsDir[] =
55 FILE_PATH_LITERAL("tmp/downloads"); 55 FILE_PATH_LITERAL("tmp/downloads");
56 const FilePath::CharType kGDataCacheTmpDocumentsDir[] =
57 FILE_PATH_LITERAL("tmp/documents");
56 const FilePath::CharType kLastFeedFile[] = FILE_PATH_LITERAL("last_feed.json"); 58 const FilePath::CharType kLastFeedFile[] = FILE_PATH_LITERAL("last_feed.json");
57 const char kGDataFileSystemToken[] = "GDataFileSystemToken"; 59 const char kGDataFileSystemToken[] = "GDataFileSystemToken";
58 const FilePath::CharType kAccountMetadataFile[] = 60 const FilePath::CharType kAccountMetadataFile[] =
59 FILE_PATH_LITERAL("account_metadata.json"); 61 FILE_PATH_LITERAL("account_metadata.json");
60 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null"); 62 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null");
61 63
62 // Converts gdata error code into file platform error code. 64 // Converts gdata error code into file platform error code.
63 base::PlatformFileError GDataToPlatformError(gdata::GDataErrorCode status) { 65 base::PlatformFileError GDataToPlatformError(gdata::GDataErrorCode status) {
64 switch (status) { 66 switch (status) {
65 case gdata::HTTP_SUCCESS: 67 case gdata::HTTP_SUCCESS:
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); 421 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path);
420 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); 422 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname);
421 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); 423 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir);
422 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType. 424 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType.
423 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir)); 425 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir));
424 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir)); 426 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir));
425 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir)); 427 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir));
426 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir)); 428 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir));
427 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir)); 429 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir));
428 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir)); 430 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir));
431 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDocumentsDir));
429 432
430 documents_service_->Initialize(profile_); 433 documents_service_->Initialize(profile_);
431 434
432 root_.reset(new GDataRootDirectory(this)); 435 root_.reset(new GDataRootDirectory(this));
433 root_->set_file_name(kGDataRootDirectory); 436 root_->set_file_name(kGDataRootDirectory);
434 } 437 }
435 438
436 GDataFileSystem::~GDataFileSystem() { 439 GDataFileSystem::~GDataFileSystem() {
437 // Should be deleted on IO thread by GDataSystemService. 440 // Should be deleted on IO thread by GDataSystemService.
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 CreateDirectoryParams( 975 CreateDirectoryParams(
973 first_missing_path, 976 first_missing_path,
974 directory_path, 977 directory_path,
975 is_exclusive, 978 is_exclusive,
976 is_recursive, 979 is_recursive,
977 callback))); 980 callback)));
978 } 981 }
979 982
980 // static 983 // static
981 void GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool( 984 void GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool(
985 const FilePath& document_dir,
982 const GURL& edit_url, 986 const GURL& edit_url,
983 const std::string& resource_id, 987 const std::string& resource_id,
984 const GetFileCallback& callback, 988 const GetFileCallback& callback,
985 scoped_refptr<base::MessageLoopProxy> relay_proxy) { 989 scoped_refptr<base::MessageLoopProxy> relay_proxy) {
986 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 990 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
987 FilePath temp_file; 991 FilePath temp_file;
988 992
989 if (file_util::CreateTemporaryFile(&temp_file)) { 993 if (file_util::CreateTemporaryFileInDir(document_dir, &temp_file)) {
990 std::string document_content = base::StringPrintf( 994 std::string document_content = base::StringPrintf(
991 "{\"url\": \"%s\", \"resource_id\": \"%s\"}", 995 "{\"url\": \"%s\", \"resource_id\": \"%s\"}",
992 edit_url.spec().c_str(), resource_id.c_str()); 996 edit_url.spec().c_str(), resource_id.c_str());
993 int document_size = static_cast<int>(document_content.size()); 997 int document_size = static_cast<int>(document_content.size());
994 if (file_util::WriteFile(temp_file, document_content.data(), 998 if (file_util::WriteFile(temp_file, document_content.data(),
995 document_size) == document_size) { 999 document_size) == document_size) {
996 error = base::PLATFORM_FILE_OK; 1000 error = base::PLATFORM_FILE_OK;
997 } 1001 }
998 } 1002 }
999 1003
(...skipping 19 matching lines...) Expand all
1019 REGULAR_FILE)); 1023 REGULAR_FILE));
1020 } 1024 }
1021 return; 1025 return;
1022 } 1026 }
1023 1027
1024 // For a hosted document, we create a special JSON file to represent the 1028 // For a hosted document, we create a special JSON file to represent the
1025 // document instead of fetching the document content in one of the exported 1029 // document instead of fetching the document content in one of the exported
1026 // formats. The JSON file contains the edit URL and resource ID of the 1030 // formats. The JSON file contains the edit URL and resource ID of the
1027 // document. 1031 // document.
1028 if (file_properties.is_hosted_document) { 1032 if (file_properties.is_hosted_document) {
1029 BrowserThread::PostBlockingPoolTask(FROM_HERE, 1033 InitializeCacheIfNecessary();
1034
1035 PostBlockingPoolSequencedTask(
1036 kGDataFileSystemToken,
1037 FROM_HERE,
1030 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool, 1038 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool,
1039 GetGDataTempDocumentFolderPath(),
1031 file_properties.edit_url, 1040 file_properties.edit_url,
1032 file_properties.resource_id, 1041 file_properties.resource_id,
1033 callback, 1042 callback,
1034 base::MessageLoopProxy::current())); 1043 base::MessageLoopProxy::current()));
1035 return; 1044 return;
1036 } 1045 }
1037 1046
1038 // Returns absolute path of the file if it were cached or to be cached. 1047 // Returns absolute path of the file if it were cached or to be cached.
1039 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id, 1048 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id,
1040 file_properties.file_md5, 1049 file_properties.file_md5,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 } 1278 }
1270 1279
1271 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const { 1280 FilePath GDataFileSystem::GetGDataCacheTmpDirectory() const {
1272 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP]; 1281 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP];
1273 } 1282 }
1274 1283
1275 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const { 1284 FilePath GDataFileSystem::GetGDataTempDownloadFolderPath() const {
1276 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS]; 1285 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOWNLOADS];
1277 } 1286 }
1278 1287
1288 FilePath GDataFileSystem::GetGDataTempDocumentFolderPath() const {
1289 return cache_paths_[GDataRootDirectory::CACHE_TYPE_TMP_DOCUMENTS];
1290 }
1291
1279 FilePath GDataFileSystem::GetGDataCachePinnedDirectory() const { 1292 FilePath GDataFileSystem::GetGDataCachePinnedDirectory() const {
1280 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED]; 1293 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED];
1281 } 1294 }
1282 1295
1283 FilePath GDataFileSystem::GetGDataCachePersistentDirectory() const { 1296 FilePath GDataFileSystem::GetGDataCachePersistentDirectory() const {
1284 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT]; 1297 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT];
1285 } 1298 }
1286 1299
1287 base::WeakPtr<GDataFileSystem> GDataFileSystem::GetWeakPtrForCurrentThread() { 1300 base::WeakPtr<GDataFileSystem> GDataFileSystem::GetWeakPtrForCurrentThread() {
1288 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 1301 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
(...skipping 2073 matching lines...) Expand 10 before | Expand all | Expand 10 after
3362 const bool posted = BrowserThread::PostBlockingPoolSequencedTask( 3375 const bool posted = BrowserThread::PostBlockingPoolSequencedTask(
3363 sequence_token_name, 3376 sequence_token_name,
3364 from_here, 3377 from_here,
3365 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool, 3378 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool,
3366 base::Unretained(this), 3379 base::Unretained(this),
3367 task)); 3380 task));
3368 DCHECK(posted); 3381 DCHECK(posted);
3369 } 3382 }
3370 3383
3371 } // namespace gdata 3384 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_files.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698