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

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

Issue 10827211: Replace GDataDirectory::TakeEntry with GDataDirectoryService::AddEntryToDirectory. (Closed) Base URL: svn://chrome-svn/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_files.h" 5 #include "chrome/browser/chromeos/gdata/gdata_files.h"
6 6
7 #include <leveldb/db.h> 7 #include <leveldb/db.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 317
318 // Add entry to resource map. 318 // Add entry to resource map.
319 if (directory_service_) 319 if (directory_service_)
320 directory_service_->AddEntryToResourceMap(entry); 320 directory_service_->AddEntryToResourceMap(entry);
321 321
322 // Setup child and parent links. 322 // Setup child and parent links.
323 AddChild(entry); 323 AddChild(entry);
324 entry->SetParent(this); 324 entry->SetParent(this);
325 } 325 }
326 326
327 bool GDataDirectory::TakeEntry(GDataEntry* entry) {
328 DCHECK(entry);
329 DCHECK(entry->parent());
330
331 entry->parent()->RemoveChild(entry);
332 AddEntry(entry);
333
334 return true;
335 }
336
337 bool GDataDirectory::TakeOverEntries(GDataDirectory* dir) { 327 bool GDataDirectory::TakeOverEntries(GDataDirectory* dir) {
338 for (GDataFileCollection::iterator iter = dir->child_files_.begin(); 328 for (GDataFileCollection::iterator iter = dir->child_files_.begin();
339 iter != dir->child_files_.end(); ++iter) { 329 iter != dir->child_files_.end(); ++iter) {
340 AddEntry(iter->second); 330 AddEntry(iter->second);
341 } 331 }
342 dir->child_files_.clear(); 332 dir->child_files_.clear();
343 333
344 for (GDataDirectoryCollection::iterator iter = 334 for (GDataDirectoryCollection::iterator iter =
345 dir->child_directories_.begin(); 335 dir->child_directories_.begin();
346 iter != dir->child_directories_.end(); ++iter) { 336 iter != dir->child_directories_.end(); ++iter) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 root_->RemoveChildren(); 563 root_->RemoveChildren();
574 RemoveEntryFromResourceMap(root_.get()); 564 RemoveEntryFromResourceMap(root_.get());
575 DCHECK(resource_map_.empty()); 565 DCHECK(resource_map_.empty());
576 resource_map_.clear(); 566 resource_map_.clear();
577 root_.reset(); 567 root_.reset();
578 } 568 }
579 569
580 void GDataDirectoryService::AddEntryToDirectory( 570 void GDataDirectoryService::AddEntryToDirectory(
581 const FilePath& directory_path, 571 const FilePath& directory_path,
582 GDataEntry* entry, 572 GDataEntry* entry,
583 const FileOperationCallback& callback) { 573 const FilePathUpdateCallback& callback) {
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
575 DCHECK(entry);
576
577 if (entry->parent())
578 entry->parent()->RemoveChild(entry);
579
584 GDataEntry* destination = FindEntryByPathSync(directory_path); 580 GDataEntry* destination = FindEntryByPathSync(directory_path);
581 FilePath updated_file_path;
585 GDataFileError error = GDATA_FILE_ERROR_FAILED; 582 GDataFileError error = GDATA_FILE_ERROR_FAILED;
586 if (!destination) { 583 if (!destination) {
587 error = GDATA_FILE_ERROR_NOT_FOUND; 584 error = GDATA_FILE_ERROR_NOT_FOUND;
588 } else if (!destination->AsGDataDirectory()) { 585 } else if (!destination->AsGDataDirectory()) {
589 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 586 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
590 } else { 587 } else {
591 destination->AsGDataDirectory()->AddEntry(entry); 588 destination->AsGDataDirectory()->AddEntry(entry);
589 updated_file_path = entry->GetFilePath();
592 error = GDATA_FILE_OK; 590 error = GDATA_FILE_OK;
593 } 591 }
594 if (!callback.is_null()) { 592 if (!callback.is_null()) {
595 base::MessageLoopProxy::current()->PostTask( 593 base::MessageLoopProxy::current()->PostTask(
596 FROM_HERE, base::Bind(callback, error)); 594 FROM_HERE, base::Bind(callback, error, updated_file_path));
597 } 595 }
598 } 596 }
599 597
600 void GDataDirectoryService::AddEntryToResourceMap(GDataEntry* entry) { 598 void GDataDirectoryService::AddEntryToResourceMap(GDataEntry* entry) {
601 // GDataFileSystem has already locked. 599 // GDataFileSystem has already locked.
602 DVLOG(1) << "AddEntryToResourceMap " << entry->resource_id(); 600 DVLOG(1) << "AddEntryToResourceMap " << entry->resource_id();
603 resource_map_.insert(std::make_pair(entry->resource_id(), entry)); 601 resource_map_.insert(std::make_pair(entry->resource_id(), entry));
604 } 602 }
605 603
606 void GDataDirectoryService::RemoveEntryFromResourceMap(GDataEntry* entry) { 604 void GDataDirectoryService::RemoveEntryFromResourceMap(GDataEntry* entry) {
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 file_specific_info->set_file_md5(file_md5_); 947 file_specific_info->set_file_md5(file_md5_);
950 file_specific_info->set_document_extension(document_extension_); 948 file_specific_info->set_document_extension(document_extension_);
951 file_specific_info->set_is_hosted_document(is_hosted_document_); 949 file_specific_info->set_is_hosted_document(is_hosted_document_);
952 } 950 }
953 951
954 bool GDataDirectory::FromProto(const GDataDirectoryProto& proto) { 952 bool GDataDirectory::FromProto(const GDataDirectoryProto& proto) {
955 DCHECK(proto.gdata_entry().file_info().is_directory()); 953 DCHECK(proto.gdata_entry().file_info().is_directory());
956 DCHECK(!proto.gdata_entry().has_file_specific_info()); 954 DCHECK(!proto.gdata_entry().has_file_specific_info());
957 955
958 for (int i = 0; i < proto.child_files_size(); ++i) { 956 for (int i = 0; i < proto.child_files_size(); ++i) {
959 scoped_ptr<GDataFile> file(new GDataFile(this, directory_service_)); 957 scoped_ptr<GDataFile> file(new GDataFile(NULL, directory_service_));
satorux1 2012/08/08 14:09:06 so the parent parameter was unnecessary, because A
achuithb 2012/08/08 22:08:41 I intend to, and it will be a fun patch, but I don
960 if (!file->FromProto(proto.child_files(i))) { 958 if (!file->FromProto(proto.child_files(i))) {
961 RemoveChildren(); 959 RemoveChildren();
962 return false; 960 return false;
963 } 961 }
964 AddEntry(file.release()); 962 AddEntry(file.release());
965 } 963 }
966 for (int i = 0; i < proto.child_directories_size(); ++i) { 964 for (int i = 0; i < proto.child_directories_size(); ++i) {
967 scoped_ptr<GDataDirectory> dir(new GDataDirectory(this, 965 scoped_ptr<GDataDirectory> dir(new GDataDirectory(NULL,
968 directory_service_)); 966 directory_service_));
969 if (!dir->FromProto(proto.child_directories(i))) { 967 if (!dir->FromProto(proto.child_directories(i))) {
970 RemoveChildren(); 968 RemoveChildren();
971 return false; 969 return false;
972 } 970 }
973 AddEntry(dir.release()); 971 AddEntry(dir.release());
974 } 972 }
975 973
976 // The states of the directory should be updated after children are 974 // The states of the directory should be updated after children are
977 // handled successfully, so that incomplete states are not left. 975 // handled successfully, so that incomplete states are not left.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 if (file->FromProto(entry_proto)) { 1069 if (file->FromProto(entry_proto)) {
1072 entry.reset(file.release()); 1070 entry.reset(file.release());
1073 } else { 1071 } else {
1074 NOTREACHED() << "FromProto (file) failed"; 1072 NOTREACHED() << "FromProto (file) failed";
1075 } 1073 }
1076 } 1074 }
1077 return entry.Pass(); 1075 return entry.Pass();
1078 } 1076 }
1079 1077
1080 } // namespace gdata 1078 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698