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

Side by Side Diff: google_apis/drive/gdata_wapi_parser.cc

Issue 384543004: Get rid of DriveEntryKind. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
« no previous file with comments | « google_apis/drive/gdata_wapi_parser.h ('k') | google_apis/drive/gdata_wapi_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "google_apis/drive/gdata_wapi_parser.h" 5 #include "google_apis/drive/gdata_wapi_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const char kTitleTField[] = "title.$t"; 67 const char kTitleTField[] = "title.$t";
68 const char kTypeField[] = "type"; 68 const char kTypeField[] = "type";
69 const char kUpdatedField[] = "updated.$t"; 69 const char kUpdatedField[] = "updated.$t";
70 70
71 // Link Prefixes 71 // Link Prefixes
72 const char kOpenWithPrefix[] = "http://schemas.google.com/docs/2007#open-with-"; 72 const char kOpenWithPrefix[] = "http://schemas.google.com/docs/2007#open-with-";
73 const size_t kOpenWithPrefixSize = arraysize(kOpenWithPrefix) - 1; 73 const size_t kOpenWithPrefixSize = arraysize(kOpenWithPrefix) - 1;
74 74
75 struct EntryKindMap { 75 struct EntryKindMap {
76 DriveEntryKind kind; 76 DriveEntryKind kind;
77 const char* entry; 77 const char* entry;
fukino 2014/07/10 06:45:28 Only ResourceEntry has dependency on the relations
78 const char* extension;
79 }; 78 };
80 79
81 const EntryKindMap kEntryKindMap[] = { 80 const EntryKindMap kEntryKindMap[] = {
82 { ENTRY_KIND_UNKNOWN, "unknown", NULL}, 81 { ENTRY_KIND_UNKNOWN, "unknown"},
83 { ENTRY_KIND_ITEM, "item", NULL}, 82 { ENTRY_KIND_ITEM, "item"},
84 { ENTRY_KIND_DOCUMENT, "document", ".gdoc"}, 83 { ENTRY_KIND_DOCUMENT, "document"},
85 { ENTRY_KIND_SPREADSHEET, "spreadsheet", ".gsheet"}, 84 { ENTRY_KIND_SPREADSHEET, "spreadsheet"},
86 { ENTRY_KIND_PRESENTATION, "presentation", ".gslides" }, 85 { ENTRY_KIND_PRESENTATION, "presentation"},
87 { ENTRY_KIND_DRAWING, "drawing", ".gdraw"}, 86 { ENTRY_KIND_DRAWING, "drawing"},
88 { ENTRY_KIND_TABLE, "table", ".gtable"}, 87 { ENTRY_KIND_TABLE, "table"},
89 { ENTRY_KIND_FORM, "form", ".gform"}, 88 { ENTRY_KIND_FORM, "form"},
90 { ENTRY_KIND_EXTERNAL_APP, "externalapp", ".glink"}, 89 { ENTRY_KIND_EXTERNAL_APP, "externalapp"},
91 { ENTRY_KIND_SITE, "site", NULL}, 90 { ENTRY_KIND_SITE, "site"},
92 { ENTRY_KIND_FOLDER, "folder", NULL}, 91 { ENTRY_KIND_FOLDER, "folder"},
93 { ENTRY_KIND_FILE, "file", NULL}, 92 { ENTRY_KIND_FILE, "file"},
94 { ENTRY_KIND_PDF, "pdf", NULL}, 93 { ENTRY_KIND_PDF, "pdf"},
95 }; 94 };
96 COMPILE_ASSERT(arraysize(kEntryKindMap) == ENTRY_KIND_MAX_VALUE, 95 COMPILE_ASSERT(arraysize(kEntryKindMap) == ENTRY_KIND_MAX_VALUE,
97 EntryKindMap_and_DriveEntryKind_are_not_in_sync); 96 EntryKindMap_and_DriveEntryKind_are_not_in_sync);
98 97
99 struct LinkTypeMap { 98 struct LinkTypeMap {
100 Link::LinkType type; 99 Link::LinkType type;
101 const char* rel; 100 const char* rel;
102 }; 101 };
103 102
104 const LinkTypeMap kLinkTypeMap[] = { 103 const LinkTypeMap kLinkTypeMap[] = {
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 kDeletedField, &ResourceEntry::deleted_, &ResourceEntry::HasFieldPresent); 431 kDeletedField, &ResourceEntry::deleted_, &ResourceEntry::HasFieldPresent);
433 converter->RegisterCustomValueField<bool>( 432 converter->RegisterCustomValueField<bool>(
434 kRemovedField, &ResourceEntry::removed_, &ResourceEntry::HasFieldPresent); 433 kRemovedField, &ResourceEntry::removed_, &ResourceEntry::HasFieldPresent);
435 converter->RegisterCustomValueField<int64>( 434 converter->RegisterCustomValueField<int64>(
436 kChangestampField, &ResourceEntry::changestamp_, 435 kChangestampField, &ResourceEntry::changestamp_,
437 &ResourceEntry::ParseChangestamp); 436 &ResourceEntry::ParseChangestamp);
438 // ImageMediaMetadata fields are not supported by WAPI. 437 // ImageMediaMetadata fields are not supported by WAPI.
439 } 438 }
440 439
441 // static 440 // static
442 std::string ResourceEntry::GetHostedDocumentExtension(DriveEntryKind kind) {
443 for (size_t i = 0; i < arraysize(kEntryKindMap); i++) {
444 if (kEntryKindMap[i].kind == kind) {
445 if (kEntryKindMap[i].extension)
446 return std::string(kEntryKindMap[i].extension);
447 else
448 return std::string();
449 }
450 }
451 return std::string();
452 }
453
454 // static
455 DriveEntryKind ResourceEntry::GetEntryKindFromExtension(
456 const std::string& extension) {
457 for (size_t i = 0; i < arraysize(kEntryKindMap); ++i) {
458 const char* document_extension = kEntryKindMap[i].extension;
459 if (document_extension && extension == document_extension)
460 return kEntryKindMap[i].kind;
461 }
462 return ENTRY_KIND_UNKNOWN;
463 }
464
465 // static
466 int ResourceEntry::ClassifyEntryKindByFileExtension(
467 const base::FilePath& file_path) {
468 #if defined(OS_WIN)
469 std::string file_extension = base::WideToUTF8(file_path.Extension());
470 #else
471 std::string file_extension = file_path.Extension();
472 #endif
473 return ClassifyEntryKind(GetEntryKindFromExtension(file_extension));
474 }
475
476 // static
477 DriveEntryKind ResourceEntry::GetEntryKindFromTerm( 441 DriveEntryKind ResourceEntry::GetEntryKindFromTerm(
478 const std::string& term) { 442 const std::string& term) {
479 if (!StartsWithASCII(term, kTermPrefix, false)) { 443 if (!StartsWithASCII(term, kTermPrefix, false)) {
480 DVLOG(1) << "Unexpected term prefix term " << term; 444 DVLOG(1) << "Unexpected term prefix term " << term;
481 return ENTRY_KIND_UNKNOWN; 445 return ENTRY_KIND_UNKNOWN;
482 } 446 }
483 447
484 std::string type = term.substr(strlen(kTermPrefix)); 448 std::string type = term.substr(strlen(kTermPrefix));
485 for (size_t i = 0; i < arraysize(kEntryKindMap); i++) { 449 for (size_t i = 0; i < arraysize(kEntryKindMap); i++) {
486 if (type == kEntryKindMap[i].entry) 450 if (type == kEntryKindMap[i].entry)
487 return kEntryKindMap[i].kind; 451 return kEntryKindMap[i].kind;
488 } 452 }
489 DVLOG(1) << "Unknown entry type for term " << term << ", type " << type; 453 DVLOG(1) << "Unknown entry type for term " << term << ", type " << type;
490 return ENTRY_KIND_UNKNOWN; 454 return ENTRY_KIND_UNKNOWN;
491 } 455 }
492 456
493 // static
494 int ResourceEntry::ClassifyEntryKind(DriveEntryKind kind) {
495 int classes = 0;
496
497 // All DriveEntryKind members are listed here, so the compiler catches if a
498 // newly added member is missing here.
499 switch (kind) {
500 case ENTRY_KIND_UNKNOWN:
501 // Special entries.
502 case ENTRY_KIND_ITEM:
503 case ENTRY_KIND_SITE:
504 break;
505
506 // Hosted Google document.
507 case ENTRY_KIND_DOCUMENT:
508 case ENTRY_KIND_SPREADSHEET:
509 case ENTRY_KIND_PRESENTATION:
510 case ENTRY_KIND_DRAWING:
511 case ENTRY_KIND_TABLE:
512 case ENTRY_KIND_FORM:
513 classes = KIND_OF_GOOGLE_DOCUMENT | KIND_OF_HOSTED_DOCUMENT;
514 break;
515
516 // Hosted external application document.
517 case ENTRY_KIND_EXTERNAL_APP:
518 classes = KIND_OF_EXTERNAL_DOCUMENT | KIND_OF_HOSTED_DOCUMENT;
519 break;
520
521 // Folders, collections.
522 case ENTRY_KIND_FOLDER:
523 classes = KIND_OF_FOLDER;
524 break;
525
526 // Regular files.
527 case ENTRY_KIND_FILE:
528 case ENTRY_KIND_PDF:
529 classes = KIND_OF_FILE;
530 break;
531
532 case ENTRY_KIND_MAX_VALUE:
533 NOTREACHED();
534 }
535
536 return classes;
537 }
538
539 void ResourceEntry::FillRemainingFields() { 457 void ResourceEntry::FillRemainingFields() {
540 // Set |kind_| and |labels_| based on the |categories_| in the class. 458 // Set |kind_| and |labels_| based on the |categories_| in the class.
541 // JSONValueConverter does not have the ability to catch an element in a list 459 // JSONValueConverter does not have the ability to catch an element in a list
542 // based on a predicate. Thus we need to iterate over |categories_| and 460 // based on a predicate. Thus we need to iterate over |categories_| and
543 // find the elements to set these fields as a post-process. 461 // find the elements to set these fields as a post-process.
544 for (size_t i = 0; i < categories_.size(); ++i) { 462 for (size_t i = 0; i < categories_.size(); ++i) {
545 const Category* category = categories_[i]; 463 const Category* category = categories_[i];
546 if (category->type() == Category::CATEGORY_KIND) 464 if (category->type() == Category::CATEGORY_KIND)
547 kind_ = GetEntryKindFromTerm(category->term()); 465 kind_ = GetEntryKindFromTerm(category->term());
548 else if (category->type() == Category::CATEGORY_LABEL) 466 else if (category->type() == Category::CATEGORY_LABEL)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } 576 }
659 } 577 }
660 return false; 578 return false;
661 } 579 }
662 580
663 void ResourceList::ReleaseEntries(std::vector<ResourceEntry*>* entries) { 581 void ResourceList::ReleaseEntries(std::vector<ResourceEntry*>* entries) {
664 entries_.release(entries); 582 entries_.release(entries);
665 } 583 }
666 584
667 } // namespace google_apis 585 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/gdata_wapi_parser.h ('k') | google_apis/drive/gdata_wapi_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698