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

Side by Side Diff: chrome/browser/chromeos/drive/drive_resource_metadata.cc

Issue 12585003: drive: Add showroot=true to WAPI feed URLs and ignore "no parent" entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, revert version-up. Created 7 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/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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 // Reject incompatible input. 381 // Reject incompatible input.
382 if (entry->proto().file_info().is_directory() != 382 if (entry->proto().file_info().is_directory() !=
383 entry_proto.file_info().is_directory()) { 383 entry_proto.file_info().is_directory()) {
384 PostGetEntryInfoWithFilePathCallbackError( 384 PostGetEntryInfoWithFilePathCallbackError(
385 callback, DRIVE_FILE_ERROR_INVALID_OPERATION); 385 callback, DRIVE_FILE_ERROR_INVALID_OPERATION);
386 return; 386 return;
387 } 387 }
388 388
389 // Update data. 389 // Update data.
390 if (entry != root_.get()) { 390 if (entry != root_.get()) {
391 DriveDirectory* old_parent = GetParent(entry->parent_resource_id()); 391 DriveDirectory* old_parent = GetDirectory(entry->parent_resource_id());
392 DriveDirectory* new_parent = GetParent(entry_proto.parent_resource_id()); 392 DriveDirectory* new_parent = GetDirectory(entry_proto.parent_resource_id());
393 393
394 if (!old_parent || !new_parent) { 394 if (!old_parent || !new_parent) {
395 PostGetEntryInfoWithFilePathCallbackError( 395 PostGetEntryInfoWithFilePathCallbackError(
396 callback, DRIVE_FILE_ERROR_NOT_FOUND); 396 callback, DRIVE_FILE_ERROR_NOT_FOUND);
397 return; 397 return;
398 } 398 }
399 399
400 // Remove from the old parent and add to the new parent. 400 // Remove from the old parent and add to the new parent.
401 old_parent->RemoveChild(entry); 401 old_parent->RemoveChild(entry);
402 // FromProto(entry_proto) imports the fields from |entry_proto|. Note that
403 // this assumes |entry_proto| contains metadata only about the entry itself.
hashimoto 2013/03/12 07:55:17 This comment seems to be redundant. Only DriveDire
Haruki Sato 2013/03/12 08:17:23 Thank you for the good explanation. Seemsl like I
404 // i.e. no children protos included.
402 entry->FromProto(entry_proto); 405 entry->FromProto(entry_proto);
403 new_parent->AddEntry(entry); // Transfers ownership. 406 new_parent->AddEntry(entry); // Transfers ownership.
404 } else { 407 } else {
405 // root has no parent. 408 // root has no parent.
406 entry->FromProto(entry_proto); 409 entry->FromProto(entry_proto);
407 } 410 }
408 411
409 DVLOG(1) << "RefreshEntry " << GetFilePath(entry->proto()).value(); 412 DVLOG(1) << "RefreshEntry " << GetFilePath(entry->proto()).value();
410 // Note that base_name is not the same for new_entry and entry_proto. 413 // Note that base_name is not the same for new_entry and entry_proto.
411 scoped_ptr<DriveEntryProto> result_entry_proto( 414 scoped_ptr<DriveEntryProto> result_entry_proto(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 base::MessageLoopProxy::current()->PostTask( 457 base::MessageLoopProxy::current()->PostTask(
455 FROM_HERE, 458 FROM_HERE,
456 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(directory->proto()))); 459 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(directory->proto())));
457 } 460 }
458 461
459 void DriveResourceMetadata::AddEntry(const DriveEntryProto& entry_proto, 462 void DriveResourceMetadata::AddEntry(const DriveEntryProto& entry_proto,
460 const FileMoveCallback& callback) { 463 const FileMoveCallback& callback) {
461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
462 DCHECK(!callback.is_null()); 465 DCHECK(!callback.is_null());
463 466
464 DriveDirectory* parent = GetParent(entry_proto.parent_resource_id()); 467 DriveDirectory* parent = GetDirectory(entry_proto.parent_resource_id());
465 if (!parent) { 468 if (!parent) {
466 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_NOT_FOUND); 469 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_NOT_FOUND);
467 return; 470 return;
468 } 471 }
469 472
470 scoped_ptr<DriveEntry> new_entry = CreateDriveEntryFromProto(entry_proto); 473 scoped_ptr<DriveEntry> new_entry = CreateDriveEntryFromProto(entry_proto);
471 if (!new_entry.get()) { 474 if (!new_entry.get()) {
472 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_FAILED); 475 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_FAILED);
473 return; 476 return;
474 } 477 }
475 478
476 DriveEntry* added_entry = new_entry.release(); 479 DriveEntry* added_entry = new_entry.release();
477 parent->AddEntry(added_entry); // Transfers ownership. 480 parent->AddEntry(added_entry); // Transfers ownership.
478 DVLOG(1) << "AddEntry " << GetFilePath(added_entry->proto()).value(); 481 DVLOG(1) << "AddEntry " << GetFilePath(added_entry->proto()).value();
479 base::MessageLoopProxy::current()->PostTask( 482 base::MessageLoopProxy::current()->PostTask(
480 FROM_HERE, 483 FROM_HERE,
481 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(added_entry->proto()))); 484 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(added_entry->proto())));
482 } 485 }
483 486
484 DriveDirectory* DriveResourceMetadata::GetParent( 487 DriveDirectory* DriveResourceMetadata::GetDirectory(
485 const std::string& parent_resource_id) { 488 const std::string& parent_resource_id) {
hashimoto 2013/03/12 07:55:17 nit: s/parent_resource_id/resource_id/?
Haruki Sato 2013/03/12 08:17:23 Done. Thanks.
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
487 490 DCHECK(!parent_resource_id.empty());
488 if (parent_resource_id.empty())
489 return root_.get();
490 491
491 DriveEntry* entry = GetEntryByResourceId(parent_resource_id); 492 DriveEntry* entry = GetEntryByResourceId(parent_resource_id);
492 return entry ? entry->AsDriveDirectory() : NULL; 493 return entry ? entry->AsDriveDirectory() : NULL;
493 } 494 }
494 495
495 base::FilePath DriveResourceMetadata::GetFilePath( 496 base::FilePath DriveResourceMetadata::GetFilePath(
496 const DriveEntryProto& entry) { 497 const DriveEntryProto& entry) {
497 base::FilePath path; 498 base::FilePath path;
498 DriveEntry* parent = entry.parent_resource_id().empty() ? NULL : 499 DriveEntry* parent = entry.parent_resource_id().empty() ? NULL :
499 GetEntryByResourceId(entry.parent_resource_id()); 500 GetEntryByResourceId(entry.parent_resource_id());
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 DCHECK(result.get()); 640 DCHECK(result.get());
640 641
641 result->second.path = second_path; 642 result->second.path = second_path;
642 result->second.error = error; 643 result->second.error = error;
643 result->second.proto = entry_proto.Pass(); 644 result->second.proto = entry_proto.Pass();
644 645
645 callback.Run(result.Pass()); 646 callback.Run(result.Pass());
646 } 647 }
647 648
648 } // namespace drive 649 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698