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

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

Issue 10832276: gdata: Remove use of FindEntryByPathAsyncOnUI from CreateFileOnUIThread() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 is_exclusive, 1455 is_exclusive,
1456 is_recursive, 1456 is_recursive,
1457 callback))); 1457 callback)));
1458 } 1458 }
1459 1459
1460 void GDataFileSystem::CreateFile(const FilePath& file_path, 1460 void GDataFileSystem::CreateFile(const FilePath& file_path,
1461 bool is_exclusive, 1461 bool is_exclusive,
1462 const FileOperationCallback& callback) { 1462 const FileOperationCallback& callback) {
1463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1464 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1464 BrowserThread::CurrentlyOn(BrowserThread::IO));
1465 DCHECK(!callback.is_null());
1466
1465 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateFileOnUIThread, 1467 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateFileOnUIThread,
1466 ui_weak_ptr_, 1468 ui_weak_ptr_,
1467 file_path, 1469 file_path,
1468 is_exclusive, 1470 is_exclusive,
1469 CreateRelayCallback(callback))); 1471 CreateRelayCallback(callback)));
1470 } 1472 }
1471 1473
1472 void GDataFileSystem::CreateFileOnUIThread( 1474 void GDataFileSystem::CreateFileOnUIThread(
1473 const FilePath& file_path, 1475 const FilePath& file_path,
1474 bool is_exclusive, 1476 bool is_exclusive,
1475 const FileOperationCallback& callback) { 1477 const FileOperationCallback& callback) {
1476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1479 DCHECK(!callback.is_null());
1477 1480
1478 // First, checks the existence of a file at |file_path|. 1481 // First, checks the existence of a file at |file_path|.
1479 FindEntryByPathAsyncOnUIThread( 1482 directory_service_->GetEntryInfoByPath(
1480 file_path, 1483 file_path,
1481 base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile, 1484 base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile,
1482 ui_weak_ptr_, 1485 ui_weak_ptr_,
1483 file_path, 1486 file_path,
1484 is_exclusive, 1487 is_exclusive,
1485 callback)); 1488 callback));
1486 } 1489 }
1487 1490
1488 void GDataFileSystem::OnGetEntryInfoForCreateFile( 1491 void GDataFileSystem::OnGetEntryInfoForCreateFile(
1489 const FilePath& file_path, 1492 const FilePath& file_path,
1490 bool is_exclusive, 1493 bool is_exclusive,
1491 const FileOperationCallback& callback, 1494 const FileOperationCallback& callback,
1492 GDataFileError result, 1495 GDataFileError result,
1493 GDataEntry* entry) { 1496 scoped_ptr<GDataEntryProto> entry_proto) {
1494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1498 DCHECK(!callback.is_null());
1495 1499
1496 // The |file_path| is invalid. It is an error. 1500 // The |file_path| is invalid. It is an error.
1497 if (result != GDATA_FILE_ERROR_NOT_FOUND && 1501 if (result != GDATA_FILE_ERROR_NOT_FOUND &&
1498 result != GDATA_FILE_OK) { 1502 result != GDATA_FILE_OK) {
1499 if (!callback.is_null()) 1503 callback.Run(result);
1500 callback.Run(result);
1501 return; 1504 return;
1502 } 1505 }
1503 1506
1504 // An entry already exists at |file_path|. 1507 // An entry already exists at |file_path|.
1505 if (result == GDATA_FILE_OK) { 1508 if (result == GDATA_FILE_OK) {
1509 DCHECK(entry_proto.get());
1506 // If an exclusive mode is requested, or the entry is not a regular file, 1510 // If an exclusive mode is requested, or the entry is not a regular file,
1507 // it is an error. 1511 // it is an error.
1508 if (is_exclusive || 1512 if (is_exclusive ||
1509 !entry->AsGDataFile() || 1513 entry_proto->file_info().is_directory() ||
1510 entry->AsGDataFile()->is_hosted_document()) { 1514 entry_proto->file_specific_info().is_hosted_document()) {
1511 if (!callback.is_null()) 1515 callback.Run(GDATA_FILE_ERROR_EXISTS);
1512 callback.Run(GDATA_FILE_ERROR_EXISTS);
1513 return; 1516 return;
1514 } 1517 }
1515 1518
1516 // Otherwise nothing more to do. Succeeded. 1519 // Otherwise nothing more to do. Succeeded.
1517 if (!callback.is_null()) 1520 callback.Run(GDATA_FILE_OK);
1518 callback.Run(GDATA_FILE_OK);
1519 return; 1521 return;
1520 } 1522 }
1521 1523
1522 // No entry found at |file_path|. Let's create a brand new file. 1524 // No entry found at |file_path|. Let's create a brand new file.
1523 // For now, it is implemented by uploading an empty file (/dev/null). 1525 // For now, it is implemented by uploading an empty file (/dev/null).
1524 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. 1526 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way.
1525 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback); 1527 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback);
1526 } 1528 }
1527 1529
1528 void GDataFileSystem::GetFileByPath( 1530 void GDataFileSystem::GetFileByPath(
(...skipping 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after
3465 } 3467 }
3466 3468
3467 PlatformFileInfoProto entry_file_info; 3469 PlatformFileInfoProto entry_file_info;
3468 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3470 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3469 *entry_proto->mutable_file_info() = entry_file_info; 3471 *entry_proto->mutable_file_info() = entry_file_info;
3470 if (!callback.is_null()) 3472 if (!callback.is_null())
3471 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3473 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3472 } 3474 }
3473 3475
3474 } // namespace gdata 3476 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698