OLD | NEW |
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 Loading... |
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 Loading... |
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::CreateFromChangeList( |
| 961 const ChangeList& changelist) { |
| 962 scoped_ptr<DocumentFeed> feed(new DocumentFeed()); |
| 963 int64 largest_changestamp = 0; |
| 964 ScopedVector<ChangeResource>::const_iterator iter = |
| 965 changelist.items().begin(); |
| 966 while (iter != changelist.items().end()) { |
| 967 const FileResource& file = (*iter)->file(); |
| 968 largest_changestamp = std::max(largest_changestamp, (*iter)->change_id()); |
| 969 feed->entries_.push_back(DocumentEntry::CreateFromFileResource(file)); |
| 970 ++iter; |
| 971 } |
| 972 feed->largest_changestamp_ = largest_changestamp; |
| 973 return feed.Pass(); |
| 974 } |
| 975 |
881 bool DocumentFeed::GetNextFeedURL(GURL* url) { | 976 bool DocumentFeed::GetNextFeedURL(GURL* url) { |
882 DCHECK(url); | 977 DCHECK(url); |
883 for (size_t i = 0; i < links_.size(); ++i) { | 978 for (size_t i = 0; i < links_.size(); ++i) { |
884 if (links_[i]->type() == Link::NEXT) { | 979 if (links_[i]->type() == Link::NEXT) { |
885 *url = links_[i]->href(); | 980 *url = links_[i]->href(); |
886 return true; | 981 return true; |
887 } | 982 } |
888 } | 983 } |
889 return false; | 984 return false; |
890 } | 985 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 bool AccountMetadataFeed::Parse(const base::Value& value) { | 1116 bool AccountMetadataFeed::Parse(const base::Value& value) { |
1022 base::JSONValueConverter<AccountMetadataFeed> converter; | 1117 base::JSONValueConverter<AccountMetadataFeed> converter; |
1023 if (!converter.Convert(value, this)) { | 1118 if (!converter.Convert(value, this)) { |
1024 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; | 1119 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; |
1025 return false; | 1120 return false; |
1026 } | 1121 } |
1027 return true; | 1122 return true; |
1028 } | 1123 } |
1029 | 1124 |
1030 } // namespace gdata | 1125 } // namespace gdata |
OLD | NEW |