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

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 // Sub-directory, under the system temporary directory, for hosting temporary
57 // document JSON file.
58 const FilePath::CharType kGDataTempDocumentDir[] =
59 FILE_PATH_LITERAL("gdata_documents");
56 const FilePath::CharType kLastFeedFile[] = FILE_PATH_LITERAL("last_feed.json"); 60 const FilePath::CharType kLastFeedFile[] = FILE_PATH_LITERAL("last_feed.json");
57 const char kGDataFileSystemToken[] = "GDataFileSystemToken"; 61 const char kGDataFileSystemToken[] = "GDataFileSystemToken";
58 const FilePath::CharType kAccountMetadataFile[] = 62 const FilePath::CharType kAccountMetadataFile[] =
59 FILE_PATH_LITERAL("account_metadata.json"); 63 FILE_PATH_LITERAL("account_metadata.json");
60 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null"); 64 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null");
61 65
62 // Converts gdata error code into file platform error code. 66 // Converts gdata error code into file platform error code.
63 base::PlatformFileError GDataToPlatformError(gdata::GDataErrorCode status) { 67 base::PlatformFileError GDataToPlatformError(gdata::GDataErrorCode status) {
64 switch (status) { 68 switch (status) {
65 case gdata::HTTP_SUCCESS: 69 case gdata::HTTP_SUCCESS:
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); 424 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname);
421 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); 425 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir);
422 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType. 426 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType.
423 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir)); 427 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir));
424 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir)); 428 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir));
425 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir)); 429 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir));
426 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir)); 430 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir));
427 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir)); 431 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir));
428 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir)); 432 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir));
429 433
434 // GetTempDir should not really fail here.
435 CHECK(file_util::GetTempDir(&temp_document_dir_));
436 temp_document_dir_ = temp_document_dir_.Append(kGDataTempDocumentDir);
437
430 documents_service_->Initialize(profile_); 438 documents_service_->Initialize(profile_);
431 439
432 root_.reset(new GDataRootDirectory(this)); 440 root_.reset(new GDataRootDirectory(this));
433 root_->set_file_name(kGDataRootDirectory); 441 root_->set_file_name(kGDataRootDirectory);
434 } 442 }
435 443
436 GDataFileSystem::~GDataFileSystem() { 444 GDataFileSystem::~GDataFileSystem() {
437 // Should be deleted on IO thread by GDataSystemService. 445 // Should be deleted on IO thread by GDataSystemService.
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
439 447
448 // Delete the sub-directory, under system temporary directory, for
449 // hosting temporary hosting document JSON files.
450 if (!temp_document_dir_.empty())
451 file_util::Delete(temp_document_dir_, true);
satorux1 2012/03/24 23:42:51 Oh you cannot do this here. BrowserThread::IO is
zel 2012/03/24 23:46:29 we can just leave this directory in place, no harm
452
440 // io_weak_ptr_factory_ must be deleted on IO thread. 453 // io_weak_ptr_factory_ must be deleted on IO thread.
441 io_weak_ptr_factory_.reset(); 454 io_weak_ptr_factory_.reset();
442 // documents_service_ must be deleted on IO thread, as it also owns 455 // documents_service_ must be deleted on IO thread, as it also owns
443 // WeakPtrFactory bound to IO thread. 456 // WeakPtrFactory bound to IO thread.
444 documents_service_.reset(); 457 documents_service_.reset();
445 } 458 }
446 459
447 void GDataFileSystem::ShutdownOnUIThread() { 460 void GDataFileSystem::ShutdownOnUIThread() {
448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
449 462
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 CreateDirectoryParams( 985 CreateDirectoryParams(
973 first_missing_path, 986 first_missing_path,
974 directory_path, 987 directory_path,
975 is_exclusive, 988 is_exclusive,
976 is_recursive, 989 is_recursive,
977 callback))); 990 callback)));
978 } 991 }
979 992
980 // static 993 // static
981 void GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool( 994 void GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool(
995 const FilePath& document_dir,
982 const GURL& edit_url, 996 const GURL& edit_url,
983 const std::string& resource_id, 997 const std::string& resource_id,
984 const GetFileCallback& callback, 998 const GetFileCallback& callback,
985 scoped_refptr<base::MessageLoopProxy> relay_proxy) { 999 scoped_refptr<base::MessageLoopProxy> relay_proxy) {
986 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 1000 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
987 FilePath temp_file; 1001 FilePath temp_file;
988 1002
989 if (file_util::CreateTemporaryFile(&temp_file)) { 1003 if (file_util::CreateDirectory(document_dir) &&
1004 file_util::CreateTemporaryFileInDir(document_dir, &temp_file)) {
990 std::string document_content = base::StringPrintf( 1005 std::string document_content = base::StringPrintf(
991 "{\"url\": \"%s\", \"resource_id\": \"%s\"}", 1006 "{\"url\": \"%s\", \"resource_id\": \"%s\"}",
992 edit_url.spec().c_str(), resource_id.c_str()); 1007 edit_url.spec().c_str(), resource_id.c_str());
993 int document_size = static_cast<int>(document_content.size()); 1008 int document_size = static_cast<int>(document_content.size());
994 if (file_util::WriteFile(temp_file, document_content.data(), 1009 if (file_util::WriteFile(temp_file, document_content.data(),
995 document_size) == document_size) { 1010 document_size) == document_size) {
996 error = base::PLATFORM_FILE_OK; 1011 error = base::PLATFORM_FILE_OK;
997 } 1012 }
998 } 1013 }
999 1014
(...skipping 21 matching lines...) Expand all
1021 return; 1036 return;
1022 } 1037 }
1023 1038
1024 // For a hosted document, we create a special JSON file to represent the 1039 // 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 1040 // 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 1041 // formats. The JSON file contains the edit URL and resource ID of the
1027 // document. 1042 // document.
1028 if (file_properties.is_hosted_document) { 1043 if (file_properties.is_hosted_document) {
1029 BrowserThread::PostBlockingPoolTask(FROM_HERE, 1044 BrowserThread::PostBlockingPoolTask(FROM_HERE,
1030 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool, 1045 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool,
1046 temp_document_dir_,
1031 file_properties.edit_url, 1047 file_properties.edit_url,
1032 file_properties.resource_id, 1048 file_properties.resource_id,
1033 callback, 1049 callback,
1034 base::MessageLoopProxy::current())); 1050 base::MessageLoopProxy::current()));
1035 return; 1051 return;
1036 } 1052 }
1037 1053
1038 // Returns absolute path of the file if it were cached or to be cached. 1054 // Returns absolute path of the file if it were cached or to be cached.
1039 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id, 1055 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id,
1040 file_properties.file_md5, 1056 file_properties.file_md5,
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 } 1248 }
1233 1249
1234 FilePath GDataFileSystem::GetGDataCachePinnedDirectory() const { 1250 FilePath GDataFileSystem::GetGDataCachePinnedDirectory() const {
1235 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED]; 1251 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED];
1236 } 1252 }
1237 1253
1238 FilePath GDataFileSystem::GetGDataCachePersistentDirectory() const { 1254 FilePath GDataFileSystem::GetGDataCachePersistentDirectory() const {
1239 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT]; 1255 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT];
1240 } 1256 }
1241 1257
1258 FilePath GDataFileSystem::GetGDataTempDocumentDirectory() const {
1259 return temp_document_dir_;
1260 }
1261
1242 base::WeakPtr<GDataFileSystem> GDataFileSystem::GetWeakPtrForCurrentThread() { 1262 base::WeakPtr<GDataFileSystem> GDataFileSystem::GetWeakPtrForCurrentThread() {
1243 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 1263 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
1244 return ui_weak_ptr_factory_->GetWeakPtr(); 1264 return ui_weak_ptr_factory_->GetWeakPtr();
1245 } else if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { 1265 } else if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
1246 if (!io_weak_ptr_factory_.get()) { 1266 if (!io_weak_ptr_factory_.get()) {
1247 io_weak_ptr_factory_.reset( 1267 io_weak_ptr_factory_.reset(
1248 new base::WeakPtrFactory<GDataFileSystem>(this)); 1268 new base::WeakPtrFactory<GDataFileSystem>(this));
1249 } 1269 }
1250 return io_weak_ptr_factory_->GetWeakPtr(); 1270 return io_weak_ptr_factory_->GetWeakPtr();
1251 } 1271 }
(...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 const bool posted = BrowserThread::PostBlockingPoolSequencedTask( 3343 const bool posted = BrowserThread::PostBlockingPoolSequencedTask(
3324 sequence_token_name, 3344 sequence_token_name,
3325 from_here, 3345 from_here,
3326 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool, 3346 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool,
3327 base::Unretained(this), 3347 base::Unretained(this),
3328 task)); 3348 task));
3329 DCHECK(posted); 3349 DCHECK(posted);
3330 } 3350 }
3331 3351
3332 } // namespace gdata 3352 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/mock_gdata_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698