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

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

Issue 10539112: Revert 141680 - Adds parsing for the app_id field from an "open-with-" link (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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_parser.h" 5 #include "chrome/browser/chromeos/gdata/gdata_parser.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/json/json_value_converter.h" 9 #include "base/json/json_value_converter.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 const char kHrefAttr[] = "href"; 117 const char kHrefAttr[] = "href";
118 const char kLabelAttr[] = "label"; 118 const char kLabelAttr[] = "label";
119 const char kNameAttr[] = "name"; 119 const char kNameAttr[] = "name";
120 const char kRelAttr[] = "rel"; 120 const char kRelAttr[] = "rel";
121 const char kSchemeAttr[] = "scheme"; 121 const char kSchemeAttr[] = "scheme";
122 const char kSrcAttr[] = "src"; 122 const char kSrcAttr[] = "src";
123 const char kTermAttr[] = "term"; 123 const char kTermAttr[] = "term";
124 const char kTypeAttr[] = "type"; 124 const char kTypeAttr[] = "type";
125 const char kValueAttr[] = "value"; 125 const char kValueAttr[] = "value";
126 126
127 // Link Prefixes
128 const char kOpenWithPrefix[] = "http://schemas.google.com/docs/2007#open-with-";
129 const size_t kOpenWithPrefixSize = arraysize(kOpenWithPrefix) - 1;
130
131 struct EntryKindMap { 127 struct EntryKindMap {
132 DocumentEntry::EntryKind kind; 128 DocumentEntry::EntryKind kind;
133 const char* entry; 129 const char* entry;
134 const char* extension; 130 const char* extension;
135 }; 131 };
136 132
137 const EntryKindMap kEntryKindMap[] = { 133 const EntryKindMap kEntryKindMap[] = {
138 { DocumentEntry::ITEM, "item", NULL}, 134 { DocumentEntry::ITEM, "item", NULL},
139 { DocumentEntry::DOCUMENT, "document", ".gdoc"}, 135 { DocumentEntry::DOCUMENT, "document", ".gdoc"},
140 { DocumentEntry::SPREADSHEET, "spreadsheet", ".gsheet"}, 136 { DocumentEntry::SPREADSHEET, "spreadsheet", ".gsheet"},
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 } while (depth == xml_reader->Depth() && (skip_read || xml_reader->Next())); 269 } while (depth == xml_reader->Depth() && (skip_read || xml_reader->Next()));
274 return author; 270 return author;
275 } 271 }
276 272
277 //////////////////////////////////////////////////////////////////////////////// 273 ////////////////////////////////////////////////////////////////////////////////
278 // Link implementation 274 // Link implementation
279 275
280 Link::Link() : type_(Link::UNKNOWN) { 276 Link::Link() : type_(Link::UNKNOWN) {
281 } 277 }
282 278
283 // static
284 bool Link::GetAppID(const base::StringPiece& rel, std::string* app_id) {
285 DCHECK(app_id);
286 // Fast return path if the link clearly isn't an OPEN_WITH link.
287 if (rel.size() < kOpenWithPrefixSize) {
288 app_id->clear();
289 return true;
290 }
291
292 const std::string kOpenWithPrefixStr(kOpenWithPrefix);
293 if (StartsWithASCII(rel.as_string(), kOpenWithPrefixStr, false)) {
294 *app_id = rel.as_string().substr(kOpenWithPrefixStr.size());
295 return true;
296 }
297
298 app_id->clear();
299 return true;
300 }
301
302 // static. 279 // static.
303 bool Link::GetLinkType(const base::StringPiece& rel, Link::LinkType* type) { 280 bool Link::GetLinkType(const base::StringPiece& rel, Link::LinkType* result) {
304 DCHECK(type);
305 for (size_t i = 0; i < arraysize(kLinkTypeMap); i++) { 281 for (size_t i = 0; i < arraysize(kLinkTypeMap); i++) {
306 if (rel == kLinkTypeMap[i].rel) { 282 if (rel == kLinkTypeMap[i].rel) {
307 *type = kLinkTypeMap[i].type; 283 *result = kLinkTypeMap[i].type;
308 return true; 284 return true;
309 } 285 }
310 } 286 }
311
312 // OPEN_WITH links have extra information at the end of the rel that is unique
313 // for each one, so we can't just check the usual map. This check is slightly
314 // redundant to provide a quick skip if it's obviously not an OPEN_WITH url.
315 if (rel.size() >= kOpenWithPrefixSize &&
316 StartsWithASCII(rel.as_string(), kOpenWithPrefix, false)) {
317 *type = OPEN_WITH;
318 return true;
319 }
320
321 // Let unknown link types through, just report it; if the link type is needed 287 // Let unknown link types through, just report it; if the link type is needed
322 // in the future, add it into LinkType and kLinkTypeMap. 288 // in the future, add it into LinkType and kLinkTypeMap.
323 DVLOG(1) << "Ignoring unknown link type for rel " << rel; 289 DVLOG(1) << "Ignoring unknown link type for rel " << rel;
324 *type = UNKNOWN; 290 *result = UNKNOWN;
325 return true; 291 return true;
326 } 292 }
327 293
328 // static 294 // static
329 void Link::RegisterJSONConverter(base::JSONValueConverter<Link>* converter) { 295 void Link::RegisterJSONConverter(base::JSONValueConverter<Link>* converter) {
330 converter->RegisterCustomField<Link::LinkType>(kRelField, 296 converter->RegisterCustomField<Link::LinkType>(
331 &Link::type_, 297 kRelField, &Link::type_, &Link::GetLinkType);
332 &Link::GetLinkType);
333 // We have to register kRelField twice because we extract two different pieces
334 // of data from the same rel field.
335 converter->RegisterCustomField<std::string>(kRelField,
336 &Link::app_id_,
337 &Link::GetAppID);
338 converter->RegisterCustomField(kHrefField, &Link::href_, &GetGURLFromString); 298 converter->RegisterCustomField(kHrefField, &Link::href_, &GetGURLFromString);
339 converter->RegisterStringField(kTitleField, &Link::title_); 299 converter->RegisterStringField(kTitleField, &Link::title_);
340 converter->RegisterStringField(kTypeField, &Link::mime_type_); 300 converter->RegisterStringField(kTypeField, &Link::mime_type_);
341 } 301 }
342 302
343 // static. 303 // static.
344 Link* Link::CreateFromXml(XmlReader* xml_reader) { 304 Link* Link::CreateFromXml(XmlReader* xml_reader) {
345 if (xml_reader->NodeName() != kLinkNode) 305 if (xml_reader->NodeName() != kLinkNode)
346 return NULL; 306 return NULL;
347 307
348 Link* link = new Link(); 308 Link* link = new Link();
349 xml_reader->NodeAttribute(kTypeAttr, &link->mime_type_); 309 xml_reader->NodeAttribute(kTypeAttr, &link->mime_type_);
350 310
351 std::string href; 311 std::string href;
352 if (xml_reader->NodeAttribute(kHrefAttr, &href)) 312 if (xml_reader->NodeAttribute(kHrefAttr, &href))
353 link->href_ = GURL(href); 313 link->href_ = GURL(href);
354 314
355 std::string rel; 315 std::string rel;
356 if (xml_reader->NodeAttribute(kRelAttr, &rel)) { 316 if (xml_reader->NodeAttribute(kRelAttr, &rel))
357 GetLinkType(rel, &link->type_); 317 GetLinkType(rel, &link->type_);
358 if (link->type_ == OPEN_WITH)
359 GetAppID(rel, &link->app_id_);
360 }
361 318
362 return link; 319 return link;
363 } 320 }
364 321
365 //////////////////////////////////////////////////////////////////////////////// 322 ////////////////////////////////////////////////////////////////////////////////
366 // FeedLink implementation 323 // FeedLink implementation
367 324
368 FeedLink::FeedLink() : type_(FeedLink::UNKNOWN) { 325 FeedLink::FeedLink() : type_(FeedLink::UNKNOWN) {
369 } 326 }
370 327
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 bool AccountMetadataFeed::Parse(const base::Value& value) { 906 bool AccountMetadataFeed::Parse(const base::Value& value) {
950 base::JSONValueConverter<AccountMetadataFeed> converter; 907 base::JSONValueConverter<AccountMetadataFeed> converter;
951 if (!converter.Convert(value, this)) { 908 if (!converter.Convert(value, this)) {
952 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; 909 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!";
953 return false; 910 return false;
954 } 911 }
955 return true; 912 return true;
956 } 913 }
957 914
958 } // namespace gdata 915 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_parser.h ('k') | chrome/browser/chromeos/gdata/gdata_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698