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

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

Issue 10837148: gdata: Add GetEntryInfoByPath() and ReadDirectoryByPath() to GDataDirectoryService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 return iter == resource_map_.end() ? NULL : iter->second; 644 return iter == resource_map_.end() ? NULL : iter->second;
645 } 645 }
646 646
647 void GDataDirectoryService::GetEntryByResourceIdAsync( 647 void GDataDirectoryService::GetEntryByResourceIdAsync(
648 const std::string& resource_id, 648 const std::string& resource_id,
649 const GetEntryByResourceIdCallback& callback) { 649 const GetEntryByResourceIdCallback& callback) {
650 GDataEntry* entry = GetEntryByResourceId(resource_id); 650 GDataEntry* entry = GetEntryByResourceId(resource_id);
651 callback.Run(entry); 651 callback.Run(entry);
652 } 652 }
653 653
654 void GDataDirectoryService::GetEntryInfoByPath(
655 const FilePath& path,
656 const GetEntryInfoCallback& callback) {
657 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
658 DCHECK(!callback.is_null());
659
660 scoped_ptr<GDataEntryProto> entry_proto;
661 GDataFileError error = GDATA_FILE_ERROR_FAILED;
662
663 GDataEntry* entry = FindEntryByPathSync(path);
664 if (entry) {
665 entry_proto.reset(new GDataEntryProto);
666 entry->ToProtoFull(entry_proto.get());
667 error = GDATA_FILE_OK;
668 } else {
669 error = GDATA_FILE_ERROR_NOT_FOUND;
670 }
671
672 base::MessageLoopProxy::current()->PostTask(
673 FROM_HERE,
674 base::Bind(callback, error, base::Passed(&entry_proto)));
675 }
676
677 void GDataDirectoryService::ReadDirectoryByPath(
678 const FilePath& path,
679 const ReadDirectoryCallback& callback) {
680 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
681 DCHECK(!callback.is_null());
682
683 scoped_ptr<GDataEntryProtoVector> entries;
684 GDataFileError error = GDATA_FILE_ERROR_FAILED;
685
686 GDataEntry* entry = FindEntryByPathSync(path);
687 if (entry && entry->AsGDataDirectory()) {
688 entries = entry->AsGDataDirectory()->ToProtoVector();
689 error = GDATA_FILE_OK;
690 } else if (entry && !entry->AsGDataDirectory()) {
691 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
692 } else {
693 error = GDATA_FILE_ERROR_NOT_FOUND;
694 }
695
696 base::MessageLoopProxy::current()->PostTask(
697 FROM_HERE,
698 base::Bind(callback, error, base::Passed(&entries)));
699 }
700
654 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) { 701 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) {
655 DCHECK(fresh_file.get()); 702 DCHECK(fresh_file.get());
656 703
657 // Need to get a reference here because Passed() could get evaluated first. 704 // Need to get a reference here because Passed() could get evaluated first.
658 const std::string& resource_id = fresh_file->resource_id(); 705 const std::string& resource_id = fresh_file->resource_id();
659 GetEntryByResourceIdAsync( 706 GetEntryByResourceIdAsync(
660 resource_id, 707 resource_id,
661 base::Bind(&GDataDirectoryService::RefreshFileInternal, 708 base::Bind(&GDataDirectoryService::RefreshFileInternal,
662 base::Passed(&fresh_file))); 709 base::Passed(&fresh_file)));
663 } 710 }
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 file->ToProto(proto->add_child_files()); 1038 file->ToProto(proto->add_child_files());
992 } 1039 }
993 for (GDataDirectoryCollection::const_iterator iter = 1040 for (GDataDirectoryCollection::const_iterator iter =
994 child_directories_.begin(); 1041 child_directories_.begin();
995 iter != child_directories_.end(); ++iter) { 1042 iter != child_directories_.end(); ++iter) {
996 GDataDirectory* dir = iter->second; 1043 GDataDirectory* dir = iter->second;
997 dir->ToProto(proto->add_child_directories()); 1044 dir->ToProto(proto->add_child_directories());
998 } 1045 }
999 } 1046 }
1000 1047
1048 scoped_ptr<GDataEntryProtoVector> GDataDirectory::ToProtoVector() const {
1049 scoped_ptr<GDataEntryProtoVector> entries(new GDataEntryProtoVector);
1050 for (GDataFileCollection::const_iterator iter = child_files().begin();
1051 iter != child_files().end(); ++iter) {
1052 GDataEntryProto proto;
1053 iter->second->ToProto(&proto);
1054 entries->push_back(proto);
1055 }
1056 for (GDataDirectoryCollection::const_iterator iter =
1057 child_directories().begin();
1058 iter != child_directories().end(); ++iter) {
1059 GDataEntryProto proto;
1060 // Convert to GDataEntry, as we don't want to include children in |proto|.
1061 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto);
1062 entries->push_back(proto);
1063 }
1064
1065 return entries.Pass();
1066 }
1067
1001 void GDataEntry::SerializeToString(std::string* serialized_proto) const { 1068 void GDataEntry::SerializeToString(std::string* serialized_proto) const {
1002 const GDataFile* file = AsGDataFileConst(); 1069 const GDataFile* file = AsGDataFileConst();
1003 const GDataDirectory* dir = AsGDataDirectoryConst(); 1070 const GDataDirectory* dir = AsGDataDirectoryConst();
1004 1071
1005 if (file) { 1072 if (file) {
1006 GDataEntryProto entry_proto; 1073 GDataEntryProto entry_proto;
1007 file->ToProto(&entry_proto); 1074 file->ToProto(&entry_proto);
1008 const bool ok = entry_proto.SerializeToString(serialized_proto); 1075 const bool ok = entry_proto.SerializeToString(serialized_proto);
1009 DCHECK(ok); 1076 DCHECK(ok);
1010 } else if (dir) { 1077 } else if (dir) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 if (file->FromProto(entry_proto)) { 1138 if (file->FromProto(entry_proto)) {
1072 entry.reset(file.release()); 1139 entry.reset(file.release());
1073 } else { 1140 } else {
1074 NOTREACHED() << "FromProto (file) failed"; 1141 NOTREACHED() << "FromProto (file) failed";
1075 } 1142 }
1076 } 1143 }
1077 return entry.Pass(); 1144 return entry.Pass();
1078 } 1145 }
1079 1146
1080 } // namespace gdata 1147 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_files.h ('k') | chrome/browser/chromeos/gdata/gdata_files_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698