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

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: fix browser_tests. 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 entry->FromProto(entry_proto); 402 entry->FromProto(entry_proto);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 base::MessageLoopProxy::current()->PostTask( 454 base::MessageLoopProxy::current()->PostTask(
455 FROM_HERE, 455 FROM_HERE,
456 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(directory->proto()))); 456 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(directory->proto())));
457 } 457 }
458 458
459 void DriveResourceMetadata::AddEntry(const DriveEntryProto& entry_proto, 459 void DriveResourceMetadata::AddEntry(const DriveEntryProto& entry_proto,
460 const FileMoveCallback& callback) { 460 const FileMoveCallback& callback) {
461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
462 DCHECK(!callback.is_null()); 462 DCHECK(!callback.is_null());
463 463
464 DriveDirectory* parent = GetParent(entry_proto.parent_resource_id()); 464 DriveDirectory* parent = GetDirectory(entry_proto.parent_resource_id());
465 if (!parent) { 465 if (!parent) {
466 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_NOT_FOUND); 466 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_NOT_FOUND);
467 return; 467 return;
468 } 468 }
469 469
470 scoped_ptr<DriveEntry> new_entry = CreateDriveEntryFromProto(entry_proto); 470 scoped_ptr<DriveEntry> new_entry = CreateDriveEntryFromProto(entry_proto);
471 if (!new_entry.get()) { 471 if (!new_entry.get()) {
472 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_FAILED); 472 PostFileMoveCallbackError(callback, DRIVE_FILE_ERROR_FAILED);
473 return; 473 return;
474 } 474 }
475 475
476 DriveEntry* added_entry = new_entry.release(); 476 DriveEntry* added_entry = new_entry.release();
477 parent->AddEntry(added_entry); // Transfers ownership. 477 parent->AddEntry(added_entry); // Transfers ownership.
478 DVLOG(1) << "AddEntry " << GetFilePath(added_entry->proto()).value(); 478 DVLOG(1) << "AddEntry " << GetFilePath(added_entry->proto()).value();
479 base::MessageLoopProxy::current()->PostTask( 479 base::MessageLoopProxy::current()->PostTask(
480 FROM_HERE, 480 FROM_HERE,
481 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(added_entry->proto()))); 481 base::Bind(callback, DRIVE_FILE_OK, GetFilePath(added_entry->proto())));
482 } 482 }
483 483
484 DriveDirectory* DriveResourceMetadata::GetParent( 484 DriveDirectory* DriveResourceMetadata::GetDirectory(
485 const std::string& parent_resource_id) { 485 const std::string& resource_id) {
486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
487 DCHECK(!resource_id.empty());
487 488
488 if (parent_resource_id.empty()) 489 DriveEntry* entry = GetEntryByResourceId(resource_id);
489 return root_.get();
490
491 DriveEntry* entry = GetEntryByResourceId(parent_resource_id);
492 return entry ? entry->AsDriveDirectory() : NULL; 490 return entry ? entry->AsDriveDirectory() : NULL;
493 } 491 }
494 492
495 base::FilePath DriveResourceMetadata::GetFilePath( 493 base::FilePath DriveResourceMetadata::GetFilePath(
496 const DriveEntryProto& entry) { 494 const DriveEntryProto& entry) {
497 base::FilePath path; 495 base::FilePath path;
498 DriveEntry* parent = entry.parent_resource_id().empty() ? NULL : 496 DriveEntry* parent = entry.parent_resource_id().empty() ? NULL :
499 GetEntryByResourceId(entry.parent_resource_id()); 497 GetEntryByResourceId(entry.parent_resource_id());
500 if (parent) 498 if (parent)
501 path = GetFilePath(parent->proto()); 499 path = GetFilePath(parent->proto());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 DCHECK(result.get()); 637 DCHECK(result.get());
640 638
641 result->second.path = second_path; 639 result->second.path = second_path;
642 result->second.error = error; 640 result->second.error = error;
643 result->second.proto = entry_proto.Pass(); 641 result->second.proto = entry_proto.Pass();
644 642
645 callback.Run(result.Pass()); 643 callback.Run(result.Pass());
646 } 644 }
647 645
648 } // namespace drive 646 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698