Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/drive/drive_resource_metadata.h" | 5 #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" |
| 6 | 6 |
| 7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
| 8 #include <stack> | 8 #include <stack> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 | 508 |
| 509 scoped_ptr<DriveEntry> drive_entry = CreateDriveEntryFromProto(entry_proto); | 509 scoped_ptr<DriveEntry> drive_entry = CreateDriveEntryFromProto(entry_proto); |
| 510 if (!drive_entry.get()) { | 510 if (!drive_entry.get()) { |
| 511 PostGetEntryInfoWithFilePathCallbackError( | 511 PostGetEntryInfoWithFilePathCallbackError( |
| 512 callback, DRIVE_FILE_ERROR_FAILED); | 512 callback, DRIVE_FILE_ERROR_FAILED); |
| 513 return; | 513 return; |
| 514 } | 514 } |
| 515 | 515 |
| 516 DriveEntry* old_entry = GetEntryByResourceId(drive_entry->resource_id()); | 516 DriveEntry* old_entry = GetEntryByResourceId(drive_entry->resource_id()); |
| 517 DriveDirectory* old_parent = NULL; | 517 DriveDirectory* old_parent = NULL; |
| 518 DriveDirectory* new_parent = NULL; | |
| 518 if (old_entry && !old_entry->parent_resource_id().empty()) { | 519 if (old_entry && !old_entry->parent_resource_id().empty()) { |
|
hashimoto
2013/03/11 09:32:17
Can't this parent_resource_id().empty() check be r
Haruki Sato
2013/03/11 14:15:35
Yes, assuming all non-root entry has parent_resour
| |
| 519 old_parent = GetEntryByResourceId( | 520 old_parent = GetEntryByResourceId( |
| 520 old_entry->parent_resource_id())->AsDriveDirectory(); | 521 old_entry->parent_resource_id())->AsDriveDirectory(); |
| 522 new_parent = entry_proto.parent_resource_id().empty() ? NULL : | |
| 523 GetParent(entry_proto.parent_resource_id()); | |
|
hashimoto
2013/03/11 09:32:17
Why do you allow entry_proto.parent_resource_id()
Haruki Sato
2013/03/11 14:15:35
Done. And we can simplify it. Thanks.
| |
| 521 } | 524 } |
| 522 DriveDirectory* new_parent = GetParent(entry_proto.parent_resource_id()); | |
| 523 | 525 |
| 524 scoped_ptr<DriveEntryProto> result_entry_proto(new DriveEntryProto); | 526 scoped_ptr<DriveEntryProto> result_entry_proto(new DriveEntryProto); |
| 525 // We special case root here because old_parent of root is null. | 527 // We special case root here because old_parent of root is null. |
| 528 // Note that this also catches "old_entry == NULL" case. | |
| 526 if ((!old_parent || !new_parent) && old_entry != root_.get()) { | 529 if ((!old_parent || !new_parent) && old_entry != root_.get()) { |
| 527 drive_entry->ToProtoFull(result_entry_proto.get()); | 530 drive_entry->ToProtoFull(result_entry_proto.get()); |
| 528 base::MessageLoopProxy::current()->PostTask( | 531 base::MessageLoopProxy::current()->PostTask( |
| 529 FROM_HERE, | 532 FROM_HERE, |
| 530 base::Bind(callback, | 533 base::Bind(callback, |
| 531 DRIVE_FILE_ERROR_NOT_FOUND, | 534 DRIVE_FILE_ERROR_NOT_FOUND, |
| 532 base::FilePath(), | 535 base::FilePath(), |
| 533 base::Passed(&result_entry_proto))); | 536 base::Passed(&result_entry_proto))); |
| 534 return; | 537 return; |
| 535 } | 538 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 return; | 617 return; |
| 615 } | 618 } |
| 616 | 619 |
| 617 DriveEntry* added_entry = new_entry.release(); | 620 DriveEntry* added_entry = new_entry.release(); |
| 618 parent->AddEntry(added_entry); // Transfers ownership. | 621 parent->AddEntry(added_entry); // Transfers ownership. |
| 619 DVLOG(1) << "AddEntry " << added_entry->GetFilePath().value(); | 622 DVLOG(1) << "AddEntry " << added_entry->GetFilePath().value(); |
| 620 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 623 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
| 621 base::Bind(callback, DRIVE_FILE_OK, added_entry->GetFilePath())); | 624 base::Bind(callback, DRIVE_FILE_OK, added_entry->GetFilePath())); |
| 622 } | 625 } |
| 623 | 626 |
| 624 DriveDirectory* DriveResourceMetadata::GetParent( | 627 DriveDirectory* DriveResourceMetadata::GetParent( |
|
hashimoto
2013/03/11 09:32:17
Could you rename this method to GetDirectory() whi
Haruki Sato
2013/03/11 14:15:35
Done.
| |
| 625 const std::string& parent_resource_id) { | 628 const std::string& parent_resource_id) { |
| 626 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 627 | 630 DCHECK(!parent_resource_id.empty()); |
| 628 if (parent_resource_id.empty()) | |
| 629 return root_.get(); | |
| 630 | 631 |
| 631 DriveEntry* entry = GetEntryByResourceId(parent_resource_id); | 632 DriveEntry* entry = GetEntryByResourceId(parent_resource_id); |
| 632 return entry ? entry->AsDriveDirectory() : NULL; | 633 return entry ? entry->AsDriveDirectory() : NULL; |
| 633 } | 634 } |
| 634 | 635 |
| 635 void DriveResourceMetadata::GetChildDirectories( | 636 void DriveResourceMetadata::GetChildDirectories( |
| 636 const std::string& resource_id, | 637 const std::string& resource_id, |
| 637 const GetChildDirectoriesCallback& changed_dirs_callback) { | 638 const GetChildDirectoriesCallback& changed_dirs_callback) { |
| 638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 639 DCHECK(!changed_dirs_callback.is_null()); | 640 DCHECK(!changed_dirs_callback.is_null()); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 932 DCHECK(result.get()); | 933 DCHECK(result.get()); |
| 933 | 934 |
| 934 result->second.path = second_path; | 935 result->second.path = second_path; |
| 935 result->second.error = error; | 936 result->second.error = error; |
| 936 result->second.proto = entry_proto.Pass(); | 937 result->second.proto = entry_proto.Pass(); |
| 937 | 938 |
| 938 callback.Run(result.Pass()); | 939 callback.Run(result.Pass()); |
| 939 } | 940 } |
| 940 | 941 |
| 941 } // namespace drive | 942 } // namespace drive |
| OLD | NEW |