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

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

Issue 10837201: Pass parsed ChangeList to GDataFileSystem. (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_wapi_parser.h" 5 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/json/json_value_converter.h" 11 #include "base/json/json_value_converter.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_piece.h" 14 #include "base/string_piece.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/chromeos/gdata/drive_api_parser.h"
18 #include "chrome/browser/chromeos/gdata/gdata_util.h" 19 #include "chrome/browser/chromeos/gdata/gdata_util.h"
19 #include "third_party/libxml/chromium/libxml_utils.h" 20 #include "third_party/libxml/chromium/libxml_utils.h"
20 21
21 using base::Value; 22 using base::Value;
22 using base::DictionaryValue; 23 using base::DictionaryValue;
23 using base::ListValue; 24 using base::ListValue;
24 25
25 namespace gdata { 26 namespace gdata {
26 27
27 namespace { 28 namespace {
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } else { 798 } else {
798 DVLOG(1) << "Unknown node " << xml_reader->NodeName(); 799 DVLOG(1) << "Unknown node " << xml_reader->NodeName();
799 } 800 }
800 } while (skip_read || xml_reader->Next()); 801 } while (skip_read || xml_reader->Next());
801 802
802 entry->FillRemainingFields(); 803 entry->FillRemainingFields();
803 return entry; 804 return entry;
804 } 805 }
805 806
806 // static 807 // static
808 DocumentEntry* DocumentEntry::CreateFromFileResource(const FileResource& file) {
809 scoped_ptr<DocumentEntry> entry(new DocumentEntry());
810
811 // DocumentEntry
812 entry->resource_id_ = file.file_id();
813 entry->id_ = file.file_id();
814 entry->kind_ = file.GetKind();
815 entry->title_ = UTF8ToUTF16(file.title());
816 entry->published_time_ = file.created_date();
817 // TODO(kochi): entry->labels_
818 entry->content_.url_ = file.web_content_link();
819 entry->content_.mime_type_ = file.mime_type();
820 // TODO(kochi): entry->feed_links_
821
822 // For file entries
823 entry->filename_ = UTF8ToUTF16(file.title());
824 entry->suggested_filename_ = UTF8ToUTF16(file.title());
825 entry->file_md5_ = file.md5_checksum();
826 entry->file_size_ = file.file_size();
827
828 entry->deleted_ = false; // later filled by CreateFromChangeResource.
829 entry->removed_ = false; // later filled by CreateFromChangeResource.
830
831 // FeedEntry
832 entry->etag_ = file.etag();
833 // entry->authors_
834 // entry->links_.
835 if (!file.parents().empty()) {
836 Link* link = new Link();
837 link->type_ = Link::PARENT;
838 link->href_ = file.parents()[0]->parent_link();
839 entry->links_.push_back(link);
840 }
841 if (!file.self_link().is_empty()) {
842 Link* link = new Link();
843 link->type_ = Link::EDIT;
844 link->href_ = file.self_link();
845 entry->links_.push_back(link);
846 }
847 if (!file.thumbnail_link().is_empty()) {
848 Link* link = new Link();
849 link->type_ = Link::THUMBNAIL;
850 link->href_ = file.thumbnail_link();
851 entry->links_.push_back(link);
852 }
853 if (!file.alternate_link().is_empty()) {
854 Link* link = new Link();
855 link->type_ = Link::ALTERNATE;
856 link->href_ = file.alternate_link();
857 entry->links_.push_back(link);
858 }
859 if (!file.embed_link().is_empty()) {
860 Link* link = new Link();
861 link->type_ = Link::EMBED;
862 link->href_ = file.embed_link();
863 entry->links_.push_back(link);
864 }
865 // entry->categories_
866 entry->updated_time_ = file.modified_by_me_date();
867
868 // TODO: Do we need this?
869 entry->FillRemainingFields();
870 return entry.release();
871 }
872
873 // static
874 DocumentEntry*
875 DocumentEntry::CreateFromChangeResource(const ChangeResource& change) {
876 DocumentEntry* entry = CreateFromFileResource(change.file());
877
878 entry->deleted_ = change.is_deleted();
879 entry->removed_ = change.is_deleted();
880
881 return entry;
882 }
883
884 // static
807 std::string DocumentEntry::GetEntryNodeName() { 885 std::string DocumentEntry::GetEntryNodeName() {
808 return kEntryNode; 886 return kEntryNode;
809 } 887 }
810 888
811 //////////////////////////////////////////////////////////////////////////////// 889 ////////////////////////////////////////////////////////////////////////////////
812 // DocumentFeed implementation 890 // DocumentFeed implementation
813 891
814 DocumentFeed::DocumentFeed() 892 DocumentFeed::DocumentFeed()
815 : start_index_(0), 893 : start_index_(0),
816 items_per_page_(0), 894 items_per_page_(0),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 scoped_ptr<DocumentFeed> DocumentFeed::CreateFrom(const base::Value& value) { 949 scoped_ptr<DocumentFeed> DocumentFeed::CreateFrom(const base::Value& value) {
872 scoped_ptr<DocumentFeed> feed(new DocumentFeed()); 950 scoped_ptr<DocumentFeed> feed(new DocumentFeed());
873 if (!feed->Parse(value)) { 951 if (!feed->Parse(value)) {
874 DVLOG(1) << "Invalid document feed!"; 952 DVLOG(1) << "Invalid document feed!";
875 return scoped_ptr<DocumentFeed>(NULL); 953 return scoped_ptr<DocumentFeed>(NULL);
876 } 954 }
877 955
878 return feed.Pass(); 956 return feed.Pass();
879 } 957 }
880 958
959 // static
960 scoped_ptr<DocumentFeed> DocumentFeed::CreateFromFileList(
satorux1 2012/08/10 18:14:34 This doesn't seem to be used.
kochi 2012/08/13 09:08:39 Removed.
961 const FileList& filelist) {
962 scoped_ptr<DocumentFeed> feed(new DocumentFeed());
963 ScopedVector<FileResource>::const_iterator iter = filelist.items().begin();
964 while (iter != filelist.items().end()) {
965 feed->entries_.push_back(DocumentEntry::CreateFromFileResource(**iter));
966 ++iter;
967 }
968 return feed.Pass();
969 }
970
971 // static
972 scoped_ptr<DocumentFeed> DocumentFeed::CreateFromChangeList(
973 const ChangeList& changelist) {
974 scoped_ptr<DocumentFeed> feed(new DocumentFeed());
975 int64 largest_changestamp = 0;
976 ScopedVector<ChangeResource>::const_iterator iter =
977 changelist.items().begin();
978 while (iter != changelist.items().end()) {
979 const FileResource& file = (*iter)->file();
980 largest_changestamp = std::max(largest_changestamp, (*iter)->change_id());
981 feed->entries_.push_back(DocumentEntry::CreateFromFileResource(file));
982 ++iter;
983 }
984 feed->largest_changestamp_ = largest_changestamp;
985 return feed.Pass();
986 }
987
881 bool DocumentFeed::GetNextFeedURL(GURL* url) { 988 bool DocumentFeed::GetNextFeedURL(GURL* url) {
882 DCHECK(url); 989 DCHECK(url);
883 for (size_t i = 0; i < links_.size(); ++i) { 990 for (size_t i = 0; i < links_.size(); ++i) {
884 if (links_[i]->type() == Link::NEXT) { 991 if (links_[i]->type() == Link::NEXT) {
885 *url = links_[i]->href(); 992 *url = links_[i]->href();
886 return true; 993 return true;
887 } 994 }
888 } 995 }
889 return false; 996 return false;
890 } 997 }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 bool AccountMetadataFeed::Parse(const base::Value& value) { 1128 bool AccountMetadataFeed::Parse(const base::Value& value) {
1022 base::JSONValueConverter<AccountMetadataFeed> converter; 1129 base::JSONValueConverter<AccountMetadataFeed> converter;
1023 if (!converter.Convert(value, this)) { 1130 if (!converter.Convert(value, this)) {
1024 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; 1131 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!";
1025 return false; 1132 return false;
1026 } 1133 }
1027 return true; 1134 return true;
1028 } 1135 }
1029 1136
1030 } // namespace gdata 1137 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698