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

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: 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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 return iter == resource_map_.end() ? NULL : iter->second; 670 return iter == resource_map_.end() ? NULL : iter->second;
671 } 671 }
672 672
673 void GDataDirectoryService::GetEntryByResourceIdAsync( 673 void GDataDirectoryService::GetEntryByResourceIdAsync(
674 const std::string& resource_id, 674 const std::string& resource_id,
675 const GetEntryByResourceIdCallback& callback) { 675 const GetEntryByResourceIdCallback& callback) {
676 GDataEntry* entry = GetEntryByResourceId(resource_id); 676 GDataEntry* entry = GetEntryByResourceId(resource_id);
677 callback.Run(entry); 677 callback.Run(entry);
678 } 678 }
679 679
680 void GDataDirectoryService::GetEntryInfoByPath(
681 const FilePath& path,
682 const GetEntryInfoCallback& callback) {
683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
684
685 scoped_ptr<GDataEntryProto> entry_proto;
686 GDataFileError error = GDATA_FILE_ERROR_FAILED;
687
688 GDataEntry* entry = FindEntryByPathSync(path);
689 if (entry) {
690 entry_proto.reset(new GDataEntryProto);
691 entry->ToProtoFull(entry_proto.get());
692 error = GDATA_FILE_OK;
693 } else {
694 error = GDATA_FILE_ERROR_NOT_FOUND;
695 }
696
697 if (!callback.is_null()) {
achuithb 2012/08/07 20:46:07 Should this be a DCHECK? You should probably bail
satorux1 2012/08/07 21:13:20 Made it a DCHECK. There is no point of calling thi
698 base::MessageLoopProxy::current()->PostTask(
699 FROM_HERE,
700 base::Bind(callback, error, base::Passed(&entry_proto)));
701 }
702 }
703
704 void GDataDirectoryService::ReadDirectoryByPath(
705 const FilePath& path,
706 const ReadDirectoryCallback& callback) {
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
708
709 scoped_ptr<GDataEntryProtoVector> entries;
710 GDataFileError error = GDATA_FILE_ERROR_FAILED;
711
712 GDataEntry* entry = FindEntryByPathSync(path);
713 if (entry && entry->AsGDataDirectory()) {
achuithb 2012/08/07 20:46:07 I feel like this would be easier to read if you us
satorux1 2012/08/07 21:13:20 Wanted to save one indentation level, so keep it a
714 GDataDirectory* directory = entry->AsGDataDirectory();
715 entries.reset(new GDataEntryProtoVector);
716 for (GDataFileCollection::const_iterator iter =
717 directory->child_files().begin();
718 iter != directory->child_files().end(); ++iter) {
719 GDataEntryProto proto;
720 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto);
achuithb 2012/08/07 20:46:07 Please add a comment as to why this static_cast is
satorux1 2012/08/07 21:13:20 Done. Turned out static_cast was not needed here.
721 entries->push_back(proto);
722 }
723 for (GDataDirectoryCollection::const_iterator iter =
724 directory->child_directories().begin();
725 iter != directory->child_directories().end(); ++iter) {
726 GDataEntryProto proto;
727 static_cast<const GDataEntry*>(iter->second)->ToProtoFull(&proto);
728 entries->push_back(proto);
729 }
730 error = GDATA_FILE_OK;
731 } else if (entry && !entry->AsGDataDirectory()) {
732 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
733 } else {
734 error = GDATA_FILE_ERROR_NOT_FOUND;
achuithb 2012/08/07 20:46:07 Don't really need this but I suppose if you want t
satorux1 2012/08/07 21:13:20 Yes
735 }
736
737 if (!callback.is_null()) {
achuithb 2012/08/07 20:46:07 Same as above. Don't think there's a point to this
satorux1 2012/08/07 21:13:20 Done.
738 base::MessageLoopProxy::current()->PostTask(
739 FROM_HERE,
740 base::Bind(callback, error, base::Passed(&entries)));
741 }
742 }
743
680 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) { 744 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) {
681 DCHECK(fresh_file.get()); 745 DCHECK(fresh_file.get());
682 746
683 // Need to get a reference here because Passed() could get evaluated first. 747 // Need to get a reference here because Passed() could get evaluated first.
684 const std::string& resource_id = fresh_file->resource_id(); 748 const std::string& resource_id = fresh_file->resource_id();
685 GetEntryByResourceIdAsync( 749 GetEntryByResourceIdAsync(
686 resource_id, 750 resource_id,
687 base::Bind(&GDataDirectoryService::RefreshFileInternal, 751 base::Bind(&GDataDirectoryService::RefreshFileInternal,
688 base::Passed(&fresh_file))); 752 base::Passed(&fresh_file)));
689 } 753 }
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 if (file->FromProto(entry_proto)) { 1161 if (file->FromProto(entry_proto)) {
1098 entry.reset(file.release()); 1162 entry.reset(file.release());
1099 } else { 1163 } else {
1100 NOTREACHED() << "FromProto (file) failed"; 1164 NOTREACHED() << "FromProto (file) failed";
1101 } 1165 }
1102 } 1166 }
1103 return entry.Pass(); 1167 return entry.Pass();
1104 } 1168 }
1105 1169
1106 } // namespace gdata 1170 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698