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

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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); 420 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname);
421 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); 421 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir);
422 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType. 422 // Insert into |cache_paths_| in order defined in enum CacheSubDirectoryType.
423 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir)); 423 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheMetaDir));
424 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir)); 424 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePinnedDir));
425 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir)); 425 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheOutgoingDir));
426 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir)); 426 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCachePersistentDir));
427 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir)); 427 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDir));
428 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir)); 428 cache_paths_.push_back(gdata_cache_path_.Append(kGDataCacheTmpDownloadsDir));
429 429
430 // Bail out if we can't create the directory for hosting temporary document
431 // JSON files.
Ben Chan 2012/03/24 22:55:34 Should we bail out here or return an error in Crea
432 CHECK(temp_document_dir_.CreateUniqueTempDir());
zel 2012/03/24 23:03:10 you can't create dir on UI thread - check CreateCa
Ben Chan 2012/03/24 23:33:46 Done.
433
430 documents_service_->Initialize(profile_); 434 documents_service_->Initialize(profile_);
431 435
432 root_.reset(new GDataRootDirectory(this)); 436 root_.reset(new GDataRootDirectory(this));
433 root_->set_file_name(kGDataRootDirectory); 437 root_->set_file_name(kGDataRootDirectory);
434 } 438 }
435 439
436 GDataFileSystem::~GDataFileSystem() { 440 GDataFileSystem::~GDataFileSystem() {
437 // Should be deleted on IO thread by GDataSystemService. 441 // Should be deleted on IO thread by GDataSystemService.
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
439 443
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 CreateDirectoryParams( 976 CreateDirectoryParams(
973 first_missing_path, 977 first_missing_path,
974 directory_path, 978 directory_path,
975 is_exclusive, 979 is_exclusive,
976 is_recursive, 980 is_recursive,
977 callback))); 981 callback)));
978 } 982 }
979 983
980 // static 984 // static
981 void GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool( 985 void GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool(
986 const FilePath& document_dir,
982 const GURL& edit_url, 987 const GURL& edit_url,
983 const std::string& resource_id, 988 const std::string& resource_id,
984 const GetFileCallback& callback, 989 const GetFileCallback& callback,
985 scoped_refptr<base::MessageLoopProxy> relay_proxy) { 990 scoped_refptr<base::MessageLoopProxy> relay_proxy) {
986 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED; 991 base::PlatformFileError error = base::PLATFORM_FILE_ERROR_FAILED;
987 FilePath temp_file; 992 FilePath temp_file;
988 993
989 if (file_util::CreateTemporaryFile(&temp_file)) { 994 if (file_util::CreateTemporaryFileInDir(document_dir, &temp_file)) {
990 std::string document_content = base::StringPrintf( 995 std::string document_content = base::StringPrintf(
991 "{\"url\": \"%s\", \"resource_id\": \"%s\"}", 996 "{\"url\": \"%s\", \"resource_id\": \"%s\"}",
992 edit_url.spec().c_str(), resource_id.c_str()); 997 edit_url.spec().c_str(), resource_id.c_str());
993 int document_size = static_cast<int>(document_content.size()); 998 int document_size = static_cast<int>(document_content.size());
994 if (file_util::WriteFile(temp_file, document_content.data(), 999 if (file_util::WriteFile(temp_file, document_content.data(),
995 document_size) == document_size) { 1000 document_size) == document_size) {
996 error = base::PLATFORM_FILE_OK; 1001 error = base::PLATFORM_FILE_OK;
997 } 1002 }
998 } 1003 }
999 1004
(...skipping 21 matching lines...) Expand all
1021 return; 1026 return;
1022 } 1027 }
1023 1028
1024 // For a hosted document, we create a special JSON file to represent the 1029 // 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 1030 // 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 1031 // formats. The JSON file contains the edit URL and resource ID of the
1027 // document. 1032 // document.
1028 if (file_properties.is_hosted_document) { 1033 if (file_properties.is_hosted_document) {
1029 BrowserThread::PostBlockingPoolTask(FROM_HERE, 1034 BrowserThread::PostBlockingPoolTask(FROM_HERE,
1030 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool, 1035 base::Bind(&GDataFileSystem::CreateDocumentJsonFileOnIOThreadPool,
1036 temp_document_dir_.path(),
1031 file_properties.edit_url, 1037 file_properties.edit_url,
1032 file_properties.resource_id, 1038 file_properties.resource_id,
1033 callback, 1039 callback,
1034 base::MessageLoopProxy::current())); 1040 base::MessageLoopProxy::current()));
1035 return; 1041 return;
1036 } 1042 }
1037 1043
1038 // Returns absolute path of the file if it were cached or to be cached. 1044 // Returns absolute path of the file if it were cached or to be cached.
1039 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id, 1045 FilePath local_tmp_path = GetCacheFilePath(file_properties.resource_id,
1040 file_properties.file_md5, 1046 file_properties.file_md5,
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 } 1238 }
1233 1239
1234 FilePath GDataFileSystem::GetGDataCachePinnedDirectory() const { 1240 FilePath GDataFileSystem::GetGDataCachePinnedDirectory() const {
1235 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED]; 1241 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PINNED];
1236 } 1242 }
1237 1243
1238 FilePath GDataFileSystem::GetGDataCachePersistentDirectory() const { 1244 FilePath GDataFileSystem::GetGDataCachePersistentDirectory() const {
1239 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT]; 1245 return cache_paths_[GDataRootDirectory::CACHE_TYPE_PERSISTENT];
1240 } 1246 }
1241 1247
1248 FilePath GDataFileSystem::GetGDataTempDocumentDirectory() const {
1249 return temp_document_dir_.path();
1250 }
1251
1242 base::WeakPtr<GDataFileSystem> GDataFileSystem::GetWeakPtrForCurrentThread() { 1252 base::WeakPtr<GDataFileSystem> GDataFileSystem::GetWeakPtrForCurrentThread() {
1243 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 1253 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
1244 return ui_weak_ptr_factory_->GetWeakPtr(); 1254 return ui_weak_ptr_factory_->GetWeakPtr();
1245 } else if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { 1255 } else if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
1246 if (!io_weak_ptr_factory_.get()) { 1256 if (!io_weak_ptr_factory_.get()) {
1247 io_weak_ptr_factory_.reset( 1257 io_weak_ptr_factory_.reset(
1248 new base::WeakPtrFactory<GDataFileSystem>(this)); 1258 new base::WeakPtrFactory<GDataFileSystem>(this));
1249 } 1259 }
1250 return io_weak_ptr_factory_->GetWeakPtr(); 1260 return io_weak_ptr_factory_->GetWeakPtr();
1251 } 1261 }
(...skipping 2071 matching lines...) Expand 10 before | Expand all | Expand 10 after
3323 const bool posted = BrowserThread::PostBlockingPoolSequencedTask( 3333 const bool posted = BrowserThread::PostBlockingPoolSequencedTask(
3324 sequence_token_name, 3334 sequence_token_name,
3325 from_here, 3335 from_here,
3326 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool, 3336 base::Bind(&GDataFileSystem::RunTaskOnIOThreadPool,
3327 base::Unretained(this), 3337 base::Unretained(this),
3328 task)); 3338 task));
3329 DCHECK(posted); 3339 DCHECK(posted);
3330 } 3340 }
3331 3341
3332 } // namespace gdata 3342 } // 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