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

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

Issue 10831212: gdata: Add GDataDirectoryService::GetEntryInfoPairByPaths() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 LOG(ERROR) << "Incompatible proto detected (bad resource ID): " 59 LOG(ERROR) << "Incompatible proto detected (bad resource ID): "
60 << entry_proto.resource_id(); 60 << entry_proto.resource_id();
61 return false; 61 return false;
62 } 62 }
63 63
64 return true; 64 return true;
65 } 65 }
66 66
67 } // namespace 67 } // namespace
68 68
69 EntryInfoResult::EntryInfoResult() : error(GDATA_FILE_ERROR_FAILED) {
70 }
71
72 EntryInfoResult::~EntryInfoResult() {
73 }
74
75 EntryInfoPairResult::EntryInfoPairResult() {
76 }
77
78 EntryInfoPairResult::~EntryInfoPairResult() {
79 }
80
69 // GDataEntry class. 81 // GDataEntry class.
70 82
71 GDataEntry::GDataEntry(GDataDirectory* parent, 83 GDataEntry::GDataEntry(GDataDirectory* parent,
72 GDataDirectoryService* directory_service) 84 GDataDirectoryService* directory_service)
73 : directory_service_(directory_service), 85 : directory_service_(directory_service),
74 deleted_(false) { 86 deleted_(false) {
75 SetParent(parent); 87 SetParent(parent);
76 } 88 }
77 89
78 GDataEntry::~GDataEntry() { 90 GDataEntry::~GDataEntry() {
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; 703 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
692 } else { 704 } else {
693 error = GDATA_FILE_ERROR_NOT_FOUND; 705 error = GDATA_FILE_ERROR_NOT_FOUND;
694 } 706 }
695 707
696 base::MessageLoopProxy::current()->PostTask( 708 base::MessageLoopProxy::current()->PostTask(
697 FROM_HERE, 709 FROM_HERE,
698 base::Bind(callback, error, base::Passed(&entries))); 710 base::Bind(callback, error, base::Passed(&entries)));
699 } 711 }
700 712
713 void GDataDirectoryService::GetEntryInfoPairByPaths(
714 const FilePath& first_path,
715 const FilePath& second_path,
716 const GetEntryInfoPairCallback& callback) {
717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
718 DCHECK(!callback.is_null());
719
720 // Get the first entry.
721 GetEntryInfoByPath(
722 first_path,
723 base::Bind(&GDataDirectoryService::GetEntryInfoPairByPathsAfterGetFirst,
724 weak_ptr_factory_.GetWeakPtr(),
725 first_path,
726 second_path,
727 callback));
728 }
729
701 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) { 730 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) {
702 DCHECK(fresh_file.get()); 731 DCHECK(fresh_file.get());
703 732
704 // Need to get a reference here because Passed() could get evaluated first. 733 // Need to get a reference here because Passed() could get evaluated first.
705 const std::string& resource_id = fresh_file->resource_id(); 734 const std::string& resource_id = fresh_file->resource_id();
706 GetEntryByResourceIdAsync( 735 GetEntryByResourceIdAsync(
707 resource_id, 736 resource_id,
708 base::Bind(&GDataDirectoryService::RefreshFileInternal, 737 base::Bind(&GDataDirectoryService::RefreshFileInternal,
709 base::Passed(&fresh_file))); 738 base::Passed(&fresh_file)));
710 } 739 }
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1137 // Call GDataFile::FromProto. 1166 // Call GDataFile::FromProto.
1138 if (file->FromProto(entry_proto)) { 1167 if (file->FromProto(entry_proto)) {
1139 entry.reset(file.release()); 1168 entry.reset(file.release());
1140 } else { 1169 } else {
1141 NOTREACHED() << "FromProto (file) failed"; 1170 NOTREACHED() << "FromProto (file) failed";
1142 } 1171 }
1143 } 1172 }
1144 return entry.Pass(); 1173 return entry.Pass();
1145 } 1174 }
1146 1175
1176 void GDataDirectoryService::GetEntryInfoPairByPathsAfterGetFirst(
1177 const FilePath& first_path,
1178 const FilePath& second_path,
1179 const GetEntryInfoPairCallback& callback,
1180 GDataFileError error,
1181 scoped_ptr<GDataEntryProto> entry_proto) {
1182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1183 DCHECK(!callback.is_null());
1184
1185 scoped_ptr<EntryInfoPairResult> result(new EntryInfoPairResult);
1186 result->first.path = first_path;
achuithb 2012/08/08 22:02:47 You could optionally add a member like void EntryI
satorux1 2012/08/08 22:13:34 Thank you for the suggestion, but I'd keep this as
1187 result->first.error = error;
1188 result->first.proto = entry_proto.Pass();
1189
1190 if (error != GDATA_FILE_OK) {
1191 callback.Run(result.Pass());
achuithb 2012/08/08 22:02:47 Let's also add a comment here saying that if the f
satorux1 2012/08/08 22:13:34 Done.
1192 return;
1193 }
1194
1195 // Get the second entry.
1196 GetEntryInfoByPath(
1197 second_path,
1198 base::Bind(&GDataDirectoryService::GetEntryInfoPairByPathsAfterGetSecond,
1199 weak_ptr_factory_.GetWeakPtr(),
1200 second_path,
1201 callback,
1202 base::Passed(&result)));
1203 }
1204
1205 void GDataDirectoryService::GetEntryInfoPairByPathsAfterGetSecond(
1206 const FilePath& second_path,
1207 const GetEntryInfoPairCallback& callback,
1208 scoped_ptr<EntryInfoPairResult> result,
1209 GDataFileError error,
1210 scoped_ptr<GDataEntryProto> entry_proto) {
1211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1212 DCHECK(!callback.is_null());
1213 DCHECK(result.get());
1214
1215 result->second.path = second_path;
1216 result->second.error = error;
1217 result->second.proto = entry_proto.Pass();
1218
1219 callback.Run(result.Pass());
1220 }
1221
1147 } // namespace gdata 1222 } // 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