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

Side by Side Diff: google_apis/drive/drive_entry_kinds.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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "google_apis/drive/drive_entry_kinds.h"
6
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/macros.h"
10
11 namespace google_apis {
12
13 namespace {
14
15 struct EntryKindMap {
16 DriveEntryKind kind;
17 const char* extension;
18 };
19
20 const EntryKindMap kEntryKindMap[] = {
21 { ENTRY_KIND_UNKNOWN, NULL},
22 { ENTRY_KIND_ITEM, NULL},
23 { ENTRY_KIND_DOCUMENT, ".gdoc"},
24 { ENTRY_KIND_SPREADSHEET, ".gsheet"},
25 { ENTRY_KIND_PRESENTATION, ".gslides" },
26 { ENTRY_KIND_DRAWING, ".gdraw"},
27 { ENTRY_KIND_TABLE, ".gtable"},
28 { ENTRY_KIND_FORM, ".gform"},
29 { ENTRY_KIND_EXTERNAL_APP, ".glink"},
30 { ENTRY_KIND_SITE, NULL},
31 { ENTRY_KIND_FOLDER, NULL},
32 { ENTRY_KIND_FILE, NULL},
33 { ENTRY_KIND_PDF, NULL},
34 };
35
36 COMPILE_ASSERT(arraysize(kEntryKindMap) == ENTRY_KIND_MAX_VALUE,
37 EntryKindMap_and_DriveEntryKind_are_not_in_sync);
38
39 } // namespace
40
41 std::string GetHostedDocumentExtension(DriveEntryKind kind) {
42 for (size_t i = 0; i < arraysize(kEntryKindMap); i++) {
43 if (kEntryKindMap[i].kind == kind) {
44 if (kEntryKindMap[i].extension)
45 return std::string(kEntryKindMap[i].extension);
46 else
47 return std::string();
48 }
49 }
50 return std::string();
51 }
52
53 DriveEntryKind GetEntryKindFromExtension(const std::string& extension) {
54 for (size_t i = 0; i < arraysize(kEntryKindMap); ++i) {
55 const char* document_extension = kEntryKindMap[i].extension;
56 if (document_extension && extension == document_extension)
57 return kEntryKindMap[i].kind;
58 }
59 return ENTRY_KIND_UNKNOWN;
60 }
61
62 int ClassifyEntryKindByFileExtension(const base::FilePath& file_path) {
63 #if defined(OS_WIN)
64 std::string file_extension = base::WideToUTF8(file_path.Extension());
65 #else
66 std::string file_extension = file_path.Extension();
67 #endif
68 return ClassifyEntryKind(GetEntryKindFromExtension(file_extension));
69 }
70
71 int ClassifyEntryKind(DriveEntryKind kind) {
72 int classes = 0;
73
74 // All DriveEntryKind members are listed here, so the compiler catches if a
75 // newly added member is missing here.
76 switch (kind) {
77 case ENTRY_KIND_UNKNOWN:
78 // Special entries.
79 case ENTRY_KIND_ITEM:
80 case ENTRY_KIND_SITE:
81 break;
82
83 // Hosted Google document.
84 case ENTRY_KIND_DOCUMENT:
85 case ENTRY_KIND_SPREADSHEET:
86 case ENTRY_KIND_PRESENTATION:
87 case ENTRY_KIND_DRAWING:
88 case ENTRY_KIND_TABLE:
89 case ENTRY_KIND_FORM:
90 classes = KIND_OF_GOOGLE_DOCUMENT | KIND_OF_HOSTED_DOCUMENT;
91 break;
92
93 // Hosted external application document.
94 case ENTRY_KIND_EXTERNAL_APP:
95 classes = KIND_OF_EXTERNAL_DOCUMENT | KIND_OF_HOSTED_DOCUMENT;
96 break;
97
98 // Folders, collections.
99 case ENTRY_KIND_FOLDER:
100 classes = KIND_OF_FOLDER;
101 break;
102
103 // Regular files.
104 case ENTRY_KIND_FILE:
105 case ENTRY_KIND_PDF:
106 classes = KIND_OF_FILE;
107 break;
108
109 case ENTRY_KIND_MAX_VALUE:
110 NOTREACHED();
111 }
112
113 return classes;
114 }
115
116 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698