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

Side by Side Diff: chrome/browser/chromeos/gdata/drive_api_parser.h

Issue 10810070: Add Drive API parser for About/Apps json (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase. Created 8 years, 4 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 | « no previous file | chrome/browser/chromeos/gdata/drive_api_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_
6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/scoped_vector.h"
15 #include "base/string_piece.h"
16 #include "base/time.h"
17 #include "googleurl/src/gurl.h"
18
19 namespace base {
20 class Value;
21 template <class StructType>
22 class JSONValueConverter;
23
24 namespace internal {
25 template <class NestedType>
26 class RepeatedMessageConverter;
27 } // namespace internal
28 } // namespace base
29
30 // TODO(kochi): Rename to namespace drive. http://crbug.com/136371
31 namespace gdata {
32
33 // About resource represents the account information about the current user.
34 // https://developers.google.com/drive/v2/reference/about
35 class AboutResource {
36 public:
37 ~AboutResource();
38
39 // Registers the mapping between JSON field names and the members in this
40 // class.
41 static void RegisterJSONConverter(
42 base::JSONValueConverter<AboutResource>* converter);
43
44 // Creates about resource from parsed JSON.
45 static scoped_ptr<AboutResource> CreateFrom(const base::Value& value);
46
47 // Returns root folder ID.
48 const std::string& root_folder_id() const { return root_folder_id_; }
49 // Returns total number of quta bytes.
50 int64 quota_bytes_total() const { return quota_bytes_total_; }
51 // Returns the number of quota bytes used.
52 int64 quota_bytes_used() const { return quota_bytes_used_; }
53 // Returns the largest change ID number.
54 int64 largest_change_id() const { return largest_change_id_; }
55
56 private:
57 friend class DriveAPIParserTest;
58 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AboutResourceParser);
59 AboutResource();
60
61 // Parses and initializes data members from content of |value|.
62 // Return false if parsing fails.
63 bool Parse(const base::Value& value);
64
65 std::string root_folder_id_;
66 int64 quota_bytes_total_;
67 int64 quota_bytes_used_;
68 int64 largest_change_id_;
69
70 DISALLOW_COPY_AND_ASSIGN(AboutResource);
71 };
72
73 // DriveAppIcon represents an icon for Drive Application.
74 // https://developers.google.com/drive/v2/reference/apps/list
75 class DriveAppIcon {
76 public:
77 enum IconCategory {
78 UNKNOWN, // Uninitialized state
79 DOCUMENT, // Document icon for various MIME types
80 APPLICATION, // Application icon for various MIME types
81 SHARED_DOCUMENT, // Icon for documents that are shared from other users.
82 };
83
84 ~DriveAppIcon();
85
86 // Registers the mapping between JSON field names and the members in this
87 // class.
88 static void RegisterJSONConverter(
89 base::JSONValueConverter<DriveAppIcon>* converter);
90
91 // Creates drive app icon instance from parsed JSON.
92 static scoped_ptr<DriveAppIcon> CreateFrom(const base::Value& value);
93
94 // Category of the icon.
95 IconCategory category() const { return category_; }
96
97 // Size in pixels of one side of the icon (icons are always square).
98 const int icon_side_length() const { return icon_side_length_; }
99
100 // Returns URL for this icon.
101 const GURL& icon_url() const { return icon_url_; }
102
103 private:
104 // Parses and initializes data members from content of |value|.
105 // Return false if parsing fails.
106 bool Parse(const base::Value& value);
107
108 // Extracts the icon category from the given string. Returns false and does
109 // not change |result| when |scheme| has an unrecognizable value.
110 static bool GetIconCategory(const base::StringPiece& category,
111 IconCategory* result);
112
113 friend class base::internal::RepeatedMessageConverter<DriveAppIcon>;
114 friend class AppResource;
115 DriveAppIcon();
116
117 IconCategory category_;
118 int icon_side_length_;
119 GURL icon_url_;
120
121 DISALLOW_COPY_AND_ASSIGN(DriveAppIcon);
122 };
123
124 // AppResource represents a Drive Application.
125 // https://developers.google.com/drive/v2/reference/apps/list
126 class AppResource {
127 public:
128 ~AppResource();
129
130 // Registers the mapping between JSON field names and the members in this
131 // class.
132 static void RegisterJSONConverter(
133 base::JSONValueConverter<AppResource>* converter);
134
135 // Creates app resource from parsed JSON.
136 static scoped_ptr<AppResource> CreateFrom(const base::Value& value);
137
138 // Returns application ID, which is 12-digit decimals (e.g. "123456780123").
139 const std::string& id() const { return id_; }
140
141 // Returns application name.
142 const std::string& name() const { return name_; }
143
144 // Returns the name of the type of object this application creates.
145 // This can be any string. TODO(kochi): figure out how to use this value.
146 const std::string& object_type() const { return object_type_; }
147
148 // Returns whether this application suuports creating new objects.
149 bool supports_create() const { return supports_create_; }
150
151 // Returns whether this application supports importing Google Docs.
152 bool supports_import() const { return supports_import_; }
153
154 // Returns whether this application is installed.
155 bool is_installed() const { return installed_; }
156
157 // Returns whether this application is authorized to access data on the
158 // user's Drive.
159 bool is_authorized() const { return authorized_; }
160
161 // Returns the product URL, e.g. at Chrmoe Web Store.
162 const GURL& product_url() const { return product_url_; }
163
164 // List of primary mime types supported by this WebApp. Primary status should
165 // trigger this WebApp becoming the default handler of file instances that
166 // have these mime types.
167 const ScopedVector<std::string>& primary_mimetypes() const {
168 return primary_mimetypes_;
169 }
170
171 // List of secondary mime types supported by this WebApp. Secondary status
172 // should make this WebApp show up in "Open with..." pop-up menu of the
173 // default action menu for file with matching mime types.
174 const ScopedVector<std::string>& secondary_mimetypes() const {
175 return secondary_mimetypes_;
176 }
177
178 // List of primary file extensions supported by this WebApp. Primary status
179 // should trigger this WebApp becoming the default handler of file instances
180 // that match these extensions.
181 const ScopedVector<std::string>& primary_file_extensions() const {
182 return primary_file_extensions_;
183 }
184
185 // List of secondary file extensions supported by this WebApp. Secondary
186 // status should make this WebApp show up in "Open with..." pop-up menu of the
187 // default action menu for file with matching extensions.
188 const ScopedVector<std::string>& secondary_file_extensions() const {
189 return secondary_file_extensions_;
190 }
191
192 // Returns Icons for this application. An application can have multiple
193 // icons for different purpose (application, document, shared document)
194 // in several sizes.
195 const ScopedVector<DriveAppIcon>& icons() const {
196 return icons_;
197 }
198
199 private:
200 friend class base::internal::RepeatedMessageConverter<AppResource>;
201 friend class AppList;
202 AppResource();
203
204 // Parses and initializes data members from content of |value|.
205 // Return false if parsing fails.
206 bool Parse(const base::Value& value);
207
208 std::string id_;
209 std::string name_;
210 std::string object_type_;
211 bool supports_create_;
212 bool supports_import_;
213 bool installed_;
214 bool authorized_;
215 GURL product_url_;
216 ScopedVector<std::string> primary_mimetypes_;
217 ScopedVector<std::string> secondary_mimetypes_;
218 ScopedVector<std::string> primary_file_extensions_;
219 ScopedVector<std::string> secondary_file_extensions_;
220 ScopedVector<DriveAppIcon> icons_;
221
222 DISALLOW_COPY_AND_ASSIGN(AppResource);
223 };
224
225 // AppList represents a list of Drive Applications.
226 // https://developers.google.com/drive/v2/reference/apps/list
227 class AppList {
228 public:
229 ~AppList();
230
231 // Registers the mapping between JSON field names and the members in this
232 // class.
233 static void RegisterJSONConverter(
234 base::JSONValueConverter<AppList>* converter);
235
236 // Creates app list from parsed JSON.
237 static scoped_ptr<AppList> CreateFrom(const base::Value& value);
238
239 // ETag for this resource.
240 const std::string& etag() const { return etag_; }
241
242 // Returns a vector of applications.
243 const ScopedVector<AppResource>& items() const { return items_; }
244
245 private:
246 friend class DriveAPIParserTest;
247 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AppListParser);
248 AppList();
249
250 // Parses and initializes data members from content of |value|.
251 // Return false if parsing fails.
252 bool Parse(const base::Value& value);
253
254 std::string etag_;
255 ScopedVector<AppResource> items_;
256
257 DISALLOW_COPY_AND_ASSIGN(AppList);
258 };
259
260 } // namespace gdata
261
262 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/drive_api_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698