| 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" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 { DocumentEntry::FILE, "file", NULL}, | 155 { DocumentEntry::FILE, "file", NULL}, |
| 156 { DocumentEntry::PDF, "pdf", NULL}, | 156 { DocumentEntry::PDF, "pdf", NULL}, |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 struct LinkTypeMap { | 159 struct LinkTypeMap { |
| 160 Link::LinkType type; | 160 Link::LinkType type; |
| 161 const char* rel; | 161 const char* rel; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 const LinkTypeMap kLinkTypeMap[] = { | 164 const LinkTypeMap kLinkTypeMap[] = { |
| 165 { Link::SELF, | 165 { Link::kSelf, |
| 166 "self" }, | 166 "self" }, |
| 167 { Link::NEXT, | 167 { Link::kNext, |
| 168 "next" }, | 168 "next" }, |
| 169 { Link::PARENT, | 169 { Link::kParent, |
| 170 "http://schemas.google.com/docs/2007#parent" }, | 170 "http://schemas.google.com/docs/2007#parent" }, |
| 171 { Link::ALTERNATE, | 171 { Link::kAlternate, |
| 172 "alternate"}, | 172 "alternate"}, |
| 173 { Link::EDIT, | 173 { Link::kEdit, |
| 174 "edit" }, | 174 "edit" }, |
| 175 { Link::EDIT_MEDIA, | 175 { Link::kEditMedia, |
| 176 "edit-media" }, | 176 "edit-media" }, |
| 177 { Link::ALT_EDIT_MEDIA, | 177 { Link::kAltEditMedia, |
| 178 "http://schemas.google.com/docs/2007#alt-edit-media" }, | 178 "http://schemas.google.com/docs/2007#alt-edit-media" }, |
| 179 { Link::ALT_POST, | 179 { Link::kAltPost, |
| 180 "http://schemas.google.com/docs/2007#alt-post" }, | 180 "http://schemas.google.com/docs/2007#alt-post" }, |
| 181 { Link::FEED, | 181 { Link::kFeed, |
| 182 "http://schemas.google.com/g/2005#feed"}, | 182 "http://schemas.google.com/g/2005#feed"}, |
| 183 { Link::POST, | 183 { Link::kPost, |
| 184 "http://schemas.google.com/g/2005#post"}, | 184 "http://schemas.google.com/g/2005#post"}, |
| 185 { Link::BATCH, | 185 { Link::kBatch, |
| 186 "http://schemas.google.com/g/2005#batch"}, | 186 "http://schemas.google.com/g/2005#batch"}, |
| 187 { Link::THUMBNAIL, | 187 { Link::kThumbnail, |
| 188 "http://schemas.google.com/docs/2007/thumbnail"}, | 188 "http://schemas.google.com/docs/2007/thumbnail"}, |
| 189 { Link::RESUMABLE_EDIT_MEDIA, | 189 { Link::kResumableEditMedia, |
| 190 "http://schemas.google.com/g/2005#resumable-edit-media"}, | 190 "http://schemas.google.com/g/2005#resumable-edit-media"}, |
| 191 { Link::RESUMABLE_CREATE_MEDIA, | 191 { Link::kResumableCreateMedia, |
| 192 "http://schemas.google.com/g/2005#resumable-create-media"}, | 192 "http://schemas.google.com/g/2005#resumable-create-media"}, |
| 193 { Link::TABLES_FEED, | 193 { Link::kTablesFeed, |
| 194 "http://schemas.google.com/spreadsheets/2006#tablesfeed"}, | 194 "http://schemas.google.com/spreadsheets/2006#tablesfeed"}, |
| 195 { Link::WORKSHEET_FEED, | 195 { Link::kWorksheetFeed, |
| 196 "http://schemas.google.com/spreadsheets/2006#worksheetsfeed"}, | 196 "http://schemas.google.com/spreadsheets/2006#worksheetsfeed"}, |
| 197 { Link::EMBED, | 197 { Link::kEmbed, |
| 198 "http://schemas.google.com/docs/2007#embed"}, | 198 "http://schemas.google.com/docs/2007#embed"}, |
| 199 { Link::PRODUCT, | 199 { Link::kProduct, |
| 200 "http://schemas.google.com/docs/2007#product"}, | 200 "http://schemas.google.com/docs/2007#product"}, |
| 201 { Link::ICON, | 201 { Link::kIcon, |
| 202 "http://schemas.google.com/docs/2007#icon"}, | 202 "http://schemas.google.com/docs/2007#icon"}, |
| 203 }; | 203 }; |
| 204 | 204 |
| 205 struct FeedLinkTypeMap { | 205 struct FeedLinkTypeMap { |
| 206 FeedLink::FeedLinkType type; | 206 FeedLink::FeedLinkType type; |
| 207 const char* rel; | 207 const char* rel; |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 const FeedLinkTypeMap kFeedLinkTypeMap[] = { | 210 const FeedLinkTypeMap kFeedLinkTypeMap[] = { |
| 211 { FeedLink::ACL, "http://schemas.google.com/acl/2007#accessControlList" }, | 211 { FeedLink::ACL, "http://schemas.google.com/acl/2007#accessControlList" }, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 xml_reader->ReadElementContent(&author->email_); | 290 xml_reader->ReadElementContent(&author->email_); |
| 291 skip_read = true; | 291 skip_read = true; |
| 292 } | 292 } |
| 293 } while (depth == xml_reader->Depth() && (skip_read || xml_reader->Next())); | 293 } while (depth == xml_reader->Depth() && (skip_read || xml_reader->Next())); |
| 294 return author; | 294 return author; |
| 295 } | 295 } |
| 296 | 296 |
| 297 //////////////////////////////////////////////////////////////////////////////// | 297 //////////////////////////////////////////////////////////////////////////////// |
| 298 // Link implementation | 298 // Link implementation |
| 299 | 299 |
| 300 Link::Link() : type_(Link::UNKNOWN) { | 300 Link::Link() : type_(Link::kUnknown) { |
| 301 } | 301 } |
| 302 | 302 |
| 303 Link::~Link() { | 303 Link::~Link() { |
| 304 } | 304 } |
| 305 | 305 |
| 306 // static | 306 // static |
| 307 bool Link::GetAppID(const base::StringPiece& rel, std::string* app_id) { | 307 bool Link::GetAppID(const base::StringPiece& rel, std::string* app_id) { |
| 308 DCHECK(app_id); | 308 DCHECK(app_id); |
| 309 // Fast return path if the link clearly isn't an OPEN_WITH link. | 309 // Fast return path if the link clearly isn't an OPEN_WITH link. |
| 310 if (rel.size() < kOpenWithPrefixSize) { | 310 if (rel.size() < kOpenWithPrefixSize) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 330 *type = kLinkTypeMap[i].type; | 330 *type = kLinkTypeMap[i].type; |
| 331 return true; | 331 return true; |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 // OPEN_WITH links have extra information at the end of the rel that is unique | 335 // OPEN_WITH links have extra information at the end of the rel that is unique |
| 336 // for each one, so we can't just check the usual map. This check is slightly | 336 // for each one, so we can't just check the usual map. This check is slightly |
| 337 // redundant to provide a quick skip if it's obviously not an OPEN_WITH url. | 337 // redundant to provide a quick skip if it's obviously not an OPEN_WITH url. |
| 338 if (rel.size() >= kOpenWithPrefixSize && | 338 if (rel.size() >= kOpenWithPrefixSize && |
| 339 StartsWithASCII(rel.as_string(), kOpenWithPrefix, false)) { | 339 StartsWithASCII(rel.as_string(), kOpenWithPrefix, false)) { |
| 340 *type = OPEN_WITH; | 340 *type = kOpenWith; |
| 341 return true; | 341 return true; |
| 342 } | 342 } |
| 343 | 343 |
| 344 // Let unknown link types through, just report it; if the link type is needed | 344 // Let unknown link types through, just report it; if the link type is needed |
| 345 // in the future, add it into LinkType and kLinkTypeMap. | 345 // in the future, add it into LinkType and kLinkTypeMap. |
| 346 DVLOG(1) << "Ignoring unknown link type for rel " << rel; | 346 DVLOG(1) << "Ignoring unknown link type for rel " << rel; |
| 347 *type = UNKNOWN; | 347 *type = kUnknown; |
| 348 return true; | 348 return true; |
| 349 } | 349 } |
| 350 | 350 |
| 351 // static | 351 // static |
| 352 void Link::RegisterJSONConverter(base::JSONValueConverter<Link>* converter) { | 352 void Link::RegisterJSONConverter(base::JSONValueConverter<Link>* converter) { |
| 353 converter->RegisterCustomField<Link::LinkType>(kRelField, | 353 converter->RegisterCustomField<Link::LinkType>(kRelField, |
| 354 &Link::type_, | 354 &Link::type_, |
| 355 &Link::GetLinkType); | 355 &Link::GetLinkType); |
| 356 // We have to register kRelField twice because we extract two different pieces | 356 // We have to register kRelField twice because we extract two different pieces |
| 357 // of data from the same rel field. | 357 // of data from the same rel field. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 371 Link* link = new Link(); | 371 Link* link = new Link(); |
| 372 xml_reader->NodeAttribute(kTypeAttr, &link->mime_type_); | 372 xml_reader->NodeAttribute(kTypeAttr, &link->mime_type_); |
| 373 | 373 |
| 374 std::string href; | 374 std::string href; |
| 375 if (xml_reader->NodeAttribute(kHrefAttr, &href)) | 375 if (xml_reader->NodeAttribute(kHrefAttr, &href)) |
| 376 link->href_ = GURL(href); | 376 link->href_ = GURL(href); |
| 377 | 377 |
| 378 std::string rel; | 378 std::string rel; |
| 379 if (xml_reader->NodeAttribute(kRelAttr, &rel)) { | 379 if (xml_reader->NodeAttribute(kRelAttr, &rel)) { |
| 380 GetLinkType(rel, &link->type_); | 380 GetLinkType(rel, &link->type_); |
| 381 if (link->type_ == OPEN_WITH) | 381 if (link->type_ == kOpenWith) |
| 382 GetAppID(rel, &link->app_id_); | 382 GetAppID(rel, &link->app_id_); |
| 383 } | 383 } |
| 384 | 384 |
| 385 return link; | 385 return link; |
| 386 } | 386 } |
| 387 | 387 |
| 388 //////////////////////////////////////////////////////////////////////////////// | 388 //////////////////////////////////////////////////////////////////////////////// |
| 389 // FeedLink implementation | 389 // FeedLink implementation |
| 390 | 390 |
| 391 FeedLink::FeedLink() : type_(FeedLink::UNKNOWN) { | 391 FeedLink::FeedLink() : type_(FeedLink::UNKNOWN) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 &AppIcon::category_, | 529 &AppIcon::category_, |
| 530 &AppIcon::GetIconCategory); | 530 &AppIcon::GetIconCategory); |
| 531 converter->RegisterCustomField<int>(kInstalledAppIconSizeField, | 531 converter->RegisterCustomField<int>(kInstalledAppIconSizeField, |
| 532 &AppIcon::icon_side_length_, | 532 &AppIcon::icon_side_length_, |
| 533 base::StringToInt); | 533 base::StringToInt); |
| 534 converter->RegisterRepeatedMessage(kLinkField, &AppIcon::links_); | 534 converter->RegisterRepeatedMessage(kLinkField, &AppIcon::links_); |
| 535 } | 535 } |
| 536 | 536 |
| 537 GURL AppIcon::GetIconURL() const { | 537 GURL AppIcon::GetIconURL() const { |
| 538 for (size_t i = 0; i < links_.size(); ++i) { | 538 for (size_t i = 0; i < links_.size(); ++i) { |
| 539 if (links_[i]->type() == Link::ICON) | 539 if (links_[i]->type() == Link::kIcon) |
| 540 return links_[i]->href(); | 540 return links_[i]->href(); |
| 541 } | 541 } |
| 542 return GURL(); | 542 return GURL(); |
| 543 } | 543 } |
| 544 | 544 |
| 545 // static | 545 // static |
| 546 bool AppIcon::GetIconCategory(const base::StringPiece& category, | 546 bool AppIcon::GetIconCategory(const base::StringPiece& category, |
| 547 AppIcon::IconCategory* result) { | 547 AppIcon::IconCategory* result) { |
| 548 for (size_t i = 0; i < arraysize(kAppIconCategoryMap); i++) { | 548 for (size_t i = 0; i < arraysize(kAppIconCategoryMap); i++) { |
| 549 if (category == kAppIconCategoryMap[i].category_name) { | 549 if (category == kAppIconCategoryMap[i].category_name) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 // ChangeResource, and is reflected in |removed_|. If file is trashed, the | 829 // ChangeResource, and is reflected in |removed_|. If file is trashed, the |
| 830 // file entry still exists but with its "trashed" label true. | 830 // file entry still exists but with its "trashed" label true. |
| 831 entry->deleted_ = file.labels().is_trashed(); | 831 entry->deleted_ = file.labels().is_trashed(); |
| 832 | 832 |
| 833 // FeedEntry | 833 // FeedEntry |
| 834 entry->etag_ = file.etag(); | 834 entry->etag_ = file.etag(); |
| 835 // entry->authors_ | 835 // entry->authors_ |
| 836 // entry->links_. | 836 // entry->links_. |
| 837 if (!file.parents().empty()) { | 837 if (!file.parents().empty()) { |
| 838 Link* link = new Link(); | 838 Link* link = new Link(); |
| 839 link->type_ = Link::PARENT; | 839 link->type_ = Link::kParent; |
| 840 link->href_ = file.parents()[0]->parent_link(); | 840 link->href_ = file.parents()[0]->parent_link(); |
| 841 entry->links_.push_back(link); | 841 entry->links_.push_back(link); |
| 842 } | 842 } |
| 843 if (!file.self_link().is_empty()) { | 843 if (!file.self_link().is_empty()) { |
| 844 Link* link = new Link(); | 844 Link* link = new Link(); |
| 845 link->type_ = Link::EDIT; | 845 link->type_ = Link::kEdit; |
| 846 link->href_ = file.self_link(); | 846 link->href_ = file.self_link(); |
| 847 entry->links_.push_back(link); | 847 entry->links_.push_back(link); |
| 848 } | 848 } |
| 849 if (!file.thumbnail_link().is_empty()) { | 849 if (!file.thumbnail_link().is_empty()) { |
| 850 Link* link = new Link(); | 850 Link* link = new Link(); |
| 851 link->type_ = Link::THUMBNAIL; | 851 link->type_ = Link::kThumbnail; |
| 852 link->href_ = file.thumbnail_link(); | 852 link->href_ = file.thumbnail_link(); |
| 853 entry->links_.push_back(link); | 853 entry->links_.push_back(link); |
| 854 } | 854 } |
| 855 if (!file.alternate_link().is_empty()) { | 855 if (!file.alternate_link().is_empty()) { |
| 856 Link* link = new Link(); | 856 Link* link = new Link(); |
| 857 link->type_ = Link::ALTERNATE; | 857 link->type_ = Link::kAlternate; |
| 858 link->href_ = file.alternate_link(); | 858 link->href_ = file.alternate_link(); |
| 859 entry->links_.push_back(link); | 859 entry->links_.push_back(link); |
| 860 } | 860 } |
| 861 if (!file.embed_link().is_empty()) { | 861 if (!file.embed_link().is_empty()) { |
| 862 Link* link = new Link(); | 862 Link* link = new Link(); |
| 863 link->type_ = Link::EMBED; | 863 link->type_ = Link::kEmbed; |
| 864 link->href_ = file.embed_link(); | 864 link->href_ = file.embed_link(); |
| 865 entry->links_.push_back(link); | 865 entry->links_.push_back(link); |
| 866 } | 866 } |
| 867 // entry->categories_ | 867 // entry->categories_ |
| 868 entry->updated_time_ = file.modified_by_me_date(); | 868 entry->updated_time_ = file.modified_by_me_date(); |
| 869 | 869 |
| 870 entry->FillRemainingFields(); | 870 entry->FillRemainingFields(); |
| 871 return entry.release(); | 871 return entry.release(); |
| 872 } | 872 } |
| 873 | 873 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 feed->entries_.push_back(DocumentEntry::CreateFromFileResource(file)); | 970 feed->entries_.push_back(DocumentEntry::CreateFromFileResource(file)); |
| 971 ++iter; | 971 ++iter; |
| 972 } | 972 } |
| 973 feed->largest_changestamp_ = largest_changestamp; | 973 feed->largest_changestamp_ = largest_changestamp; |
| 974 return feed.Pass(); | 974 return feed.Pass(); |
| 975 } | 975 } |
| 976 | 976 |
| 977 bool DocumentFeed::GetNextFeedURL(GURL* url) { | 977 bool DocumentFeed::GetNextFeedURL(GURL* url) { |
| 978 DCHECK(url); | 978 DCHECK(url); |
| 979 for (size_t i = 0; i < links_.size(); ++i) { | 979 for (size_t i = 0; i < links_.size(); ++i) { |
| 980 if (links_[i]->type() == Link::NEXT) { | 980 if (links_[i]->type() == Link::kNext) { |
| 981 *url = links_[i]->href(); | 981 *url = links_[i]->href(); |
| 982 return true; | 982 return true; |
| 983 } | 983 } |
| 984 } | 984 } |
| 985 return false; | 985 return false; |
| 986 } | 986 } |
| 987 | 987 |
| 988 void DocumentFeed::ReleaseEntries(std::vector<DocumentEntry*>* entries) { | 988 void DocumentFeed::ReleaseEntries(std::vector<DocumentEntry*>* entries) { |
| 989 entries_.release(entries); | 989 entries_.release(entries); |
| 990 } | 990 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1015 | 1015 |
| 1016 // Return a sorted list, smallest to largest. | 1016 // Return a sorted list, smallest to largest. |
| 1017 std::sort(result.begin(), result.end(), SortBySize); | 1017 std::sort(result.begin(), result.end(), SortBySize); |
| 1018 return result; | 1018 return result; |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 GURL InstalledApp::GetProductUrl() const { | 1021 GURL InstalledApp::GetProductUrl() const { |
| 1022 for (ScopedVector<Link>::const_iterator it = links_.begin(); | 1022 for (ScopedVector<Link>::const_iterator it = links_.begin(); |
| 1023 it != links_.end(); ++it) { | 1023 it != links_.end(); ++it) { |
| 1024 const Link* link = *it; | 1024 const Link* link = *it; |
| 1025 if (link->type() == Link::PRODUCT) | 1025 if (link->type() == Link::kProduct) |
| 1026 return link->href(); | 1026 return link->href(); |
| 1027 } | 1027 } |
| 1028 return GURL(); | 1028 return GURL(); |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 // static | 1031 // static |
| 1032 bool InstalledApp::GetValueString(const base::Value* value, | 1032 bool InstalledApp::GetValueString(const base::Value* value, |
| 1033 std::string* result) { | 1033 std::string* result) { |
| 1034 const base::DictionaryValue* dict = NULL; | 1034 const base::DictionaryValue* dict = NULL; |
| 1035 if (!value->GetAsDictionary(&dict)) | 1035 if (!value->GetAsDictionary(&dict)) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 bool AccountMetadataFeed::Parse(const base::Value& value) { | 1121 bool AccountMetadataFeed::Parse(const base::Value& value) { |
| 1122 base::JSONValueConverter<AccountMetadataFeed> converter; | 1122 base::JSONValueConverter<AccountMetadataFeed> converter; |
| 1123 if (!converter.Convert(value, this)) { | 1123 if (!converter.Convert(value, this)) { |
| 1124 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; | 1124 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; |
| 1125 return false; | 1125 return false; |
| 1126 } | 1126 } |
| 1127 return true; | 1127 return true; |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 } // namespace gdata | 1130 } // namespace gdata |
| OLD | NEW |