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

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

Issue 10920091: Move Drive API files to google_apis directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reflect comments Created 8 years, 3 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 (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
10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/string_piece.h"
15 #include "base/time.h"
16 #include "googleurl/src/gurl.h"
17 // TODO(kochi): Eliminate this dependency once dependency to EntryKind is gone.
18 // http://crbug.com/142293
19 #include "chrome/browser/chromeos/gdata/gdata_wapi_parser.h"
20
21 namespace base {
22 class Value;
23 template <class StructType>
24 class JSONValueConverter;
25
26 namespace internal {
27 template <class NestedType>
28 class RepeatedMessageConverter;
29 } // namespace internal
30 } // namespace base
31
32 // TODO(kochi): Rename to namespace drive. http://crbug.com/136371
33 namespace gdata {
34
35 // About resource represents the account information about the current user.
36 // https://developers.google.com/drive/v2/reference/about
37 class AboutResource {
38 public:
39 ~AboutResource();
40
41 // Registers the mapping between JSON field names and the members in this
42 // class.
43 static void RegisterJSONConverter(
44 base::JSONValueConverter<AboutResource>* converter);
45
46 // Creates about resource from parsed JSON.
47 static scoped_ptr<AboutResource> CreateFrom(const base::Value& value);
48
49 // Returns the largest change ID number.
50 int64 largest_change_id() const { return largest_change_id_; }
51 // Returns total number of quta bytes.
52 int64 quota_bytes_total() const { return quota_bytes_total_; }
53 // Returns the number of quota bytes used.
54 int64 quota_bytes_used() const { return quota_bytes_used_; }
55 // Returns root folder ID.
56 const std::string& root_folder_id() const { return root_folder_id_; }
57
58 private:
59 friend class DriveAPIParserTest;
60 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AboutResourceParser);
61 AboutResource();
62
63 // Parses and initializes data members from content of |value|.
64 // Return false if parsing fails.
65 bool Parse(const base::Value& value);
66
67 int64 largest_change_id_;
68 int64 quota_bytes_total_;
69 int64 quota_bytes_used_;
70 std::string root_folder_id_;
71
72 DISALLOW_COPY_AND_ASSIGN(AboutResource);
73 };
74
75 // DriveAppIcon represents an icon for Drive Application.
76 // https://developers.google.com/drive/v2/reference/apps/list
77 class DriveAppIcon {
78 public:
79 enum IconCategory {
80 UNKNOWN, // Uninitialized state
81 DOCUMENT, // Document icon for various MIME types
82 APPLICATION, // Application icon for various MIME types
83 SHARED_DOCUMENT, // Icon for documents that are shared from other users.
84 };
85
86 ~DriveAppIcon();
87
88 // Registers the mapping between JSON field names and the members in this
89 // class.
90 static void RegisterJSONConverter(
91 base::JSONValueConverter<DriveAppIcon>* converter);
92
93 // Creates drive app icon instance from parsed JSON.
94 static scoped_ptr<DriveAppIcon> CreateFrom(const base::Value& value);
95
96 // Category of the icon.
97 IconCategory category() const { return category_; }
98
99 // Size in pixels of one side of the icon (icons are always square).
100 int icon_side_length() const { return icon_side_length_; }
101
102 // Returns URL for this icon.
103 const GURL& icon_url() const { return icon_url_; }
104
105 private:
106 // Parses and initializes data members from content of |value|.
107 // Return false if parsing fails.
108 bool Parse(const base::Value& value);
109
110 // Extracts the icon category from the given string. Returns false and does
111 // not change |result| when |scheme| has an unrecognizable value.
112 static bool GetIconCategory(const base::StringPiece& category,
113 IconCategory* result);
114
115 friend class base::internal::RepeatedMessageConverter<DriveAppIcon>;
116 friend class AppResource;
117 DriveAppIcon();
118
119 IconCategory category_;
120 int icon_side_length_;
121 GURL icon_url_;
122
123 DISALLOW_COPY_AND_ASSIGN(DriveAppIcon);
124 };
125
126 // AppResource represents a Drive Application.
127 // https://developers.google.com/drive/v2/reference/apps/list
128 class AppResource {
129 public:
130 ~AppResource();
131
132 // Registers the mapping between JSON field names and the members in this
133 // class.
134 static void RegisterJSONConverter(
135 base::JSONValueConverter<AppResource>* converter);
136
137 // Creates app resource from parsed JSON.
138 static scoped_ptr<AppResource> CreateFrom(const base::Value& value);
139
140 // Returns application ID, which is 12-digit decimals (e.g. "123456780123").
141 const std::string& application_id() const { return application_id_; }
142
143 // Returns application name.
144 const std::string& name() const { return name_; }
145
146 // Returns the name of the type of object this application creates.
147 // This is used for displaying in "Create" menu item for this app.
148 // If empty, application name is used instead.
149 const std::string& object_type() const { return object_type_; }
150
151 // Returns whether this application supports creating new objects.
152 bool supports_create() const { return supports_create_; }
153
154 // Returns whether this application supports importing Google Docs.
155 bool supports_import() const { return supports_import_; }
156
157 // Returns whether this application is installed.
158 bool is_installed() const { return installed_; }
159
160 // Returns whether this application is authorized to access data on the
161 // user's Drive.
162 bool is_authorized() const { return authorized_; }
163
164 // Returns the product URL, e.g. at Chrome Web Store.
165 const GURL& product_url() const { return product_url_; }
166
167 // List of primary mime types supported by this WebApp. Primary status should
168 // trigger this WebApp becoming the default handler of file instances that
169 // have these mime types.
170 const ScopedVector<std::string>& primary_mimetypes() const {
171 return primary_mimetypes_;
172 }
173
174 // List of secondary mime types supported by this WebApp. Secondary status
175 // should make this WebApp show up in "Open with..." pop-up menu of the
176 // default action menu for file with matching mime types.
177 const ScopedVector<std::string>& secondary_mimetypes() const {
178 return secondary_mimetypes_;
179 }
180
181 // List of primary file extensions supported by this WebApp. Primary status
182 // should trigger this WebApp becoming the default handler of file instances
183 // that match these extensions.
184 const ScopedVector<std::string>& primary_file_extensions() const {
185 return primary_file_extensions_;
186 }
187
188 // List of secondary file extensions supported by this WebApp. Secondary
189 // status should make this WebApp show up in "Open with..." pop-up menu of the
190 // default action menu for file with matching extensions.
191 const ScopedVector<std::string>& secondary_file_extensions() const {
192 return secondary_file_extensions_;
193 }
194
195 // Returns Icons for this application. An application can have multiple
196 // icons for different purpose (application, document, shared document)
197 // in several sizes.
198 const ScopedVector<DriveAppIcon>& icons() const {
199 return icons_;
200 }
201
202 private:
203 friend class base::internal::RepeatedMessageConverter<AppResource>;
204 friend class AppList;
205 AppResource();
206
207 // Parses and initializes data members from content of |value|.
208 // Return false if parsing fails.
209 bool Parse(const base::Value& value);
210
211 std::string application_id_;
212 std::string name_;
213 std::string object_type_;
214 bool supports_create_;
215 bool supports_import_;
216 bool installed_;
217 bool authorized_;
218 GURL product_url_;
219 ScopedVector<std::string> primary_mimetypes_;
220 ScopedVector<std::string> secondary_mimetypes_;
221 ScopedVector<std::string> primary_file_extensions_;
222 ScopedVector<std::string> secondary_file_extensions_;
223 ScopedVector<DriveAppIcon> icons_;
224
225 DISALLOW_COPY_AND_ASSIGN(AppResource);
226 };
227
228 // AppList represents a list of Drive Applications.
229 // https://developers.google.com/drive/v2/reference/apps/list
230 class AppList {
231 public:
232 ~AppList();
233
234 // Registers the mapping between JSON field names and the members in this
235 // class.
236 static void RegisterJSONConverter(
237 base::JSONValueConverter<AppList>* converter);
238
239 // Creates app list from parsed JSON.
240 static scoped_ptr<AppList> CreateFrom(const base::Value& value);
241
242 // ETag for this resource.
243 const std::string& etag() const { return etag_; }
244
245 // Returns a vector of applications.
246 const ScopedVector<AppResource>& items() const { return items_; }
247
248 private:
249 friend class DriveAPIParserTest;
250 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AppListParser);
251 AppList();
252
253 // Parses and initializes data members from content of |value|.
254 // Return false if parsing fails.
255 bool Parse(const base::Value& value);
256
257 std::string etag_;
258 ScopedVector<AppResource> items_;
259
260 DISALLOW_COPY_AND_ASSIGN(AppList);
261 };
262
263 // ParentReference represents a directory.
264 // https://developers.google.com/drive/v2/reference/parents
265 class ParentReference {
266 public:
267 ~ParentReference();
268
269 // Registers the mapping between JSON field names and the members in this
270 // class.
271 static void RegisterJSONConverter(
272 base::JSONValueConverter<ParentReference>* converter);
273
274 // Creates parent reference from parsed JSON.
275 static scoped_ptr<ParentReference> CreateFrom(const base::Value& value);
276
277 // Returns the file id of the reference.
278 const std::string& file_id() const { return file_id_; }
279
280 // Returns the URL for the parent in Drive.
281 const GURL& parent_link() const { return parent_link_; }
282
283 // Returns true if the reference is root directory.
284 bool is_root() const { return is_root_; }
285
286 private:
287 friend class base::internal::RepeatedMessageConverter<ParentReference>;
288 ParentReference();
289
290 // Parses and initializes data members from content of |value|.
291 // Return false if parsing fails.
292 bool Parse(const base::Value& value);
293
294 std::string file_id_;
295 GURL parent_link_;
296 bool is_root_;
297
298 DISALLOW_COPY_AND_ASSIGN(ParentReference);
299 };
300
301 // FileLabels represents labels for file or folder.
302 // https://developers.google.com/drive/v2/reference/files
303 class FileLabels {
304 public:
305 ~FileLabels();
306
307 // Registers the mapping between JSON field names and the members in this
308 // class.
309 static void RegisterJSONConverter(
310 base::JSONValueConverter<FileLabels>* converter);
311
312 // Creates about resource from parsed JSON.
313 static scoped_ptr<FileLabels> CreateFrom(const base::Value& value);
314
315 // Whether this file is starred by the user.
316 bool is_starred() const { return starred_; }
317 // Whether this file is hidden from the user.
318 bool is_hidden() const { return hidden_; }
319 // Whether this file has been trashed.
320 bool is_trashed() const { return trashed_; }
321 // Whether viewers are prevented from downloading this file.
322 bool is_restricted() const { return restricted_; }
323 // Whether this file has been viewed by this user.
324 bool is_viewed() const { return viewed_; }
325
326 private:
327 friend class FileResource;
328 FileLabels();
329
330 // Parses and initializes data members from content of |value|.
331 // Return false if parsing fails.
332 bool Parse(const base::Value& value);
333
334 bool starred_;
335 bool hidden_;
336 bool trashed_;
337 bool restricted_;
338 bool viewed_;
339
340 DISALLOW_COPY_AND_ASSIGN(FileLabels);
341 };
342
343 // FileResource represents a file or folder metadata in Drive.
344 // https://developers.google.com/drive/v2/reference/files
345 class FileResource {
346 public:
347 ~FileResource();
348
349 // Registers the mapping between JSON field names and the members in this
350 // class.
351 static void RegisterJSONConverter(
352 base::JSONValueConverter<FileResource>* converter);
353
354 // Creates file resource from parsed JSON.
355 static scoped_ptr<FileResource> CreateFrom(const base::Value& value);
356
357 // Returns true if this is a directory.
358 // Note: "folder" is used elsewhere in this file to match Drive API reference,
359 // but outside this file we use "directory" to match HTML5 filesystem API.
360 bool IsDirectory() const;
361
362 // Returns EntryKind for this file.
363 // TODO(kochi): Remove this once FileResource is directly converted to proto.
364 // http://crbug.com/142293
365 DriveEntryKind GetKind() const;
366
367 // Returns file ID. This is unique in all files in Google Drive.
368 const std::string& file_id() const { return file_id_; }
369
370 // Returns ETag for this file.
371 const std::string& etag() const { return etag_; }
372
373 // Returns the link to JSON of this file itself.
374 const GURL& self_link() const { return self_link_; }
375
376 // Returns the title of this file.
377 const std::string& title() const { return title_; }
378
379 // Returns MIME type of this file.
380 const std::string& mime_type() const { return mime_type_; }
381
382 // Returns labels for this file.
383 const FileLabels& labels() const { return labels_; }
384
385 // Returns created time of this file.
386 const base::Time& created_date() const { return created_date_; }
387
388 // Returns modification time by the user.
389 const base::Time& modified_by_me_date() const { return modified_by_me_date_; }
390
391 // Returns the short-lived download URL for the file. This field exists
392 // only when the file content is stored in Drive.
393 const GURL& download_url() const { return download_url_; }
394
395 // Returns the extension part of the filename.
396 const std::string& file_extension() const { return file_extension_; }
397
398 // Returns MD5 checksum of this file.
399 const std::string& md5_checksum() const { return md5_checksum_; }
400
401 // Returns the size of this file in bytes.
402 int64 file_size() const { return file_size_; }
403
404 // Return the link to open the file in Google editor or viewer.
405 // E.g. Google Document, Google Spreadsheet.
406 const GURL& alternate_link() const { return alternate_link_; }
407
408 // Returns the link for embedding the file.
409 const GURL& embed_link() const { return embed_link_; }
410
411 // Returns parent references (directories) of this file.
412 const ScopedVector<ParentReference>& parents() const { return parents_; }
413
414 // Returns the link to the file's thumbnail.
415 const GURL& thumbnail_link() const { return thumbnail_link_; }
416
417 // Returns the link to open its downloadable content, using cookie based
418 // authentication.
419 const GURL& web_content_link() const { return web_content_link_; }
420
421 private:
422 friend class base::internal::RepeatedMessageConverter<FileResource>;
423 friend class ChangeResource;
424 friend class FileList;
425 FileResource();
426
427 // Parses and initializes data members from content of |value|.
428 // Return false if parsing fails.
429 bool Parse(const base::Value& value);
430
431 std::string file_id_;
432 std::string etag_;
433 GURL self_link_;
434 std::string title_;
435 std::string mime_type_;
436 FileLabels labels_;
437 base::Time created_date_;
438 base::Time modified_by_me_date_;
439 GURL download_url_;
440 std::string file_extension_;
441 std::string md5_checksum_;
442 int64 file_size_;
443 GURL alternate_link_;
444 GURL embed_link_;
445 ScopedVector<ParentReference> parents_;
446 GURL thumbnail_link_;
447 GURL web_content_link_;
448
449 DISALLOW_COPY_AND_ASSIGN(FileResource);
450 };
451
452 // FileList represents a collection of files and folders.
453 // https://developers.google.com/drive/v2/reference/files/list
454 class FileList {
455 public:
456 ~FileList();
457
458 // Registers the mapping between JSON field names and the members in this
459 // class.
460 static void RegisterJSONConverter(
461 base::JSONValueConverter<FileList>* converter);
462
463 // Creates file list from parsed JSON.
464 static scoped_ptr<FileList> CreateFrom(const base::Value& value);
465
466 // Returns the ETag of the list.
467 const std::string& etag() const { return etag_; }
468
469 // Returns the page token for the next page of files, if the list is large
470 // to fit in one response. If this is empty, there is no more file lists.
471 const std::string& next_page_token() const { return next_page_token_; }
472
473 // Returns a link to the next page of files. The URL includes the next page
474 // token.
475 const GURL& next_link() const { return next_link_; }
476
477 // Returns a set of files in this list.
478 const ScopedVector<FileResource>& items() const { return items_; }
479
480 private:
481 friend class DriveAPIParserTest;
482 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, FileListParser);
483 FileList();
484
485 // Parses and initializes data members from content of |value|.
486 // Return false if parsing fails.
487 bool Parse(const base::Value& value);
488
489 std::string etag_;
490 std::string next_page_token_;
491 GURL next_link_;
492 ScopedVector<FileResource> items_;
493
494 DISALLOW_COPY_AND_ASSIGN(FileList);
495 };
496
497 // ChangeResource represents a change in a file.
498 // https://developers.google.com/drive/v2/reference/changes
499 class ChangeResource {
500 public:
501 ~ChangeResource();
502
503 // Registers the mapping between JSON field names and the members in this
504 // class.
505 static void RegisterJSONConverter(
506 base::JSONValueConverter<ChangeResource>* converter);
507
508 // Creates change resource from parsed JSON.
509 static scoped_ptr<ChangeResource> CreateFrom(const base::Value& value);
510
511 // Returns change ID for this change. This is a monotonically increasing
512 // number.
513 int64 change_id() const { return change_id_; }
514
515 // Returns a string file ID for corresponding file of the change.
516 const std::string& file_id() const { return file_id_; }
517
518 // Returns true if this file is deleted in the change.
519 bool is_deleted() const { return deleted_; }
520
521 // Returns FileResource of the file which the change refers to.
522 const FileResource& file() const { return file_; }
523
524 private:
525 friend class base::internal::RepeatedMessageConverter<ChangeResource>;
526 friend class ChangeList;
527 ChangeResource();
528
529 // Parses and initializes data members from content of |value|.
530 // Return false if parsing fails.
531 bool Parse(const base::Value& value);
532
533 int64 change_id_;
534 std::string file_id_;
535 bool deleted_;
536 FileResource file_;
537
538 DISALLOW_COPY_AND_ASSIGN(ChangeResource);
539 };
540
541 // ChangeList represents a set of changes in the drive.
542 // https://developers.google.com/drive/v2/reference/changes/list
543 class ChangeList {
544 public:
545 ~ChangeList();
546
547 // Registers the mapping between JSON field names and the members in this
548 // class.
549 static void RegisterJSONConverter(
550 base::JSONValueConverter<ChangeList>* converter);
551
552 // Creates change list from parsed JSON.
553 static scoped_ptr<ChangeList> CreateFrom(const base::Value& value);
554
555 // Returns the ETag of the list.
556 const std::string& etag() const { return etag_; }
557
558 // Returns the page token for the next page of files, if the list is large
559 // to fit in one response. If this is empty, there is no more file lists.
560 const std::string& next_page_token() const { return next_page_token_; }
561
562 // Returns a link to the next page of files. The URL includes the next page
563 // token.
564 const GURL& next_link() const { return next_link_; }
565
566 // Returns the largest change ID number.
567 int64 largest_change_id() const { return largest_change_id_; }
568
569 // Returns a set of changes in this list.
570 const ScopedVector<ChangeResource>& items() const { return items_; }
571
572 private:
573 friend class DriveAPIParserTest;
574 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser);
575 ChangeList();
576
577 // Parses and initializes data members from content of |value|.
578 // Return false if parsing fails.
579 bool Parse(const base::Value& value);
580
581 std::string etag_;
582 std::string next_page_token_;
583 GURL next_link_;
584 int64 largest_change_id_;
585 ScopedVector<ChangeResource> items_;
586
587 DISALLOW_COPY_AND_ASSIGN(ChangeList);
588 };
589
590 } // namespace gdata
591
592 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/drive_api_operations.cc ('k') | chrome/browser/chromeos/gdata/drive_api_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698