OLD | NEW |
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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // Parses and initializes data members from content of |value|. | 251 // Parses and initializes data members from content of |value|. |
252 // Return false if parsing fails. | 252 // Return false if parsing fails. |
253 bool Parse(const base::Value& value); | 253 bool Parse(const base::Value& value); |
254 | 254 |
255 std::string etag_; | 255 std::string etag_; |
256 ScopedVector<AppResource> items_; | 256 ScopedVector<AppResource> items_; |
257 | 257 |
258 DISALLOW_COPY_AND_ASSIGN(AppList); | 258 DISALLOW_COPY_AND_ASSIGN(AppList); |
259 }; | 259 }; |
260 | 260 |
261 // FileResource reporesents a file or folder metadata in Drive. | 261 // ParentReference represents a directory. |
| 262 // https://developers.google.com/drive/v2/reference/parents |
| 263 class ParentReference { |
| 264 public: |
| 265 ~ParentReference(); |
| 266 |
| 267 // Registers the mapping between JSON field names and the members in this |
| 268 // class. |
| 269 static void RegisterJSONConverter( |
| 270 base::JSONValueConverter<ParentReference>* converter); |
| 271 |
| 272 // Creates parent reference from parsed JSON. |
| 273 static scoped_ptr<ParentReference> CreateFrom(const base::Value& value); |
| 274 |
| 275 // Returns the file id of the reference. |
| 276 const std::string& file_id() const { return file_id_; } |
| 277 |
| 278 // Returns true if the reference is root directory. |
| 279 bool is_root() const { return is_root_; } |
| 280 |
| 281 private: |
| 282 friend class base::internal::RepeatedMessageConverter<ParentReference>; |
| 283 ParentReference(); |
| 284 |
| 285 // Parses and initializes data members from content of |value|. |
| 286 // Return false if parsing fails. |
| 287 bool Parse(const base::Value& value); |
| 288 |
| 289 std::string file_id_; |
| 290 bool is_root_; |
| 291 |
| 292 DISALLOW_COPY_AND_ASSIGN(ParentReference); |
| 293 }; |
| 294 |
| 295 // FileResource represents a file or folder metadata in Drive. |
262 // https://developers.google.com/drive/v2/reference/files | 296 // https://developers.google.com/drive/v2/reference/files |
263 class FileResource { | 297 class FileResource { |
264 public: | 298 public: |
265 ~FileResource(); | 299 ~FileResource(); |
266 | 300 |
267 // Registers the mapping between JSON field names and the members in this | 301 // Registers the mapping between JSON field names and the members in this |
268 // class. | 302 // class. |
269 static void RegisterJSONConverter( | 303 static void RegisterJSONConverter( |
270 base::JSONValueConverter<FileResource>* converter); | 304 base::JSONValueConverter<FileResource>* converter); |
| 305 |
| 306 // Creates file resource from parsed JSON. |
271 static scoped_ptr<FileResource> CreateFrom(const base::Value& value); | 307 static scoped_ptr<FileResource> CreateFrom(const base::Value& value); |
272 | 308 |
273 // Returns true if this is a directory. | 309 // Returns true if this is a directory. |
274 // Note: "folder" is used elsewhere in this file to match Drive API reference, | 310 // Note: "folder" is used elsewhere in this file to match Drive API reference, |
275 // but outside this file we use "directory" to match HTML5 filesystem API. | 311 // but outside this file we use "directory" to match HTML5 filesystem API. |
276 bool IsDirectory() const; | 312 bool IsDirectory() const; |
277 | 313 |
278 // Returns file ID. This is unique in all files in Google Drive. | 314 // Returns file ID. This is unique in all files in Google Drive. |
279 const std::string& file_id() const { return file_id_; } | 315 const std::string& file_id() const { return file_id_; } |
280 | 316 |
281 // Returns ETag for this file. | 317 // Returns ETag for this file. |
282 const std::string& etag() const { return etag_; } | 318 const std::string& etag() const { return etag_; } |
283 | 319 |
284 // Returns MIME type of this file. | 320 // Returns MIME type of this file. |
285 const std::string& mime_type() const { return mime_type_; } | 321 const std::string& mime_type() const { return mime_type_; } |
286 | 322 |
287 // Returns the title of this file. | 323 // Returns the title of this file. |
288 const std::string& title() const { return title_; } | 324 const std::string& title() const { return title_; } |
289 | 325 |
290 // Returns modification time by the user. | 326 // Returns modification time by the user. |
291 const base::Time& modified_by_me_date() const { return modified_by_me_date_; } | 327 const base::Time& modified_by_me_date() const { return modified_by_me_date_; } |
292 | 328 |
| 329 // Returns parent references (directories) of this file. |
| 330 const ScopedVector<ParentReference>& parents() const { return parents_; } |
| 331 |
293 // Returns the download URL. | 332 // Returns the download URL. |
294 const GURL& download_url() const { return download_url_; } | 333 const GURL& download_url() const { return download_url_; } |
295 | 334 |
296 // Returns the extension part of the filename. | 335 // Returns the extension part of the filename. |
297 const std::string& file_extension() const { return file_extension_; } | 336 const std::string& file_extension() const { return file_extension_; } |
298 | 337 |
299 // Returns MD5 checksum of this file. | 338 // Returns MD5 checksum of this file. |
300 const std::string& md5_checksum() const { return md5_checksum_; } | 339 const std::string& md5_checksum() const { return md5_checksum_; } |
301 | 340 |
302 // Returns the size of this file in bytes. | 341 // Returns the size of this file in bytes. |
303 int64 file_size() const { return file_size_; } | 342 int64 file_size() const { return file_size_; } |
304 | 343 |
305 private: | 344 private: |
306 friend class base::internal::RepeatedMessageConverter<FileResource>; | 345 friend class base::internal::RepeatedMessageConverter<FileResource>; |
| 346 friend class ChangeResource; |
307 friend class FileList; | 347 friend class FileList; |
308 FileResource(); | 348 FileResource(); |
309 | 349 |
310 // Parses and initializes data members from content of |value|. | 350 // Parses and initializes data members from content of |value|. |
311 // Return false if parsing fails. | 351 // Return false if parsing fails. |
312 bool Parse(const base::Value& value); | 352 bool Parse(const base::Value& value); |
313 | 353 |
314 std::string file_id_; | 354 std::string file_id_; |
315 std::string etag_; | 355 std::string etag_; |
316 std::string mime_type_; | 356 std::string mime_type_; |
317 std::string title_; | 357 std::string title_; |
318 base::Time modified_by_me_date_; | 358 base::Time modified_by_me_date_; |
| 359 ScopedVector<ParentReference> parents_; |
319 GURL download_url_; | 360 GURL download_url_; |
320 std::string file_extension_; | 361 std::string file_extension_; |
321 std::string md5_checksum_; | 362 std::string md5_checksum_; |
322 int64 file_size_; | 363 int64 file_size_; |
323 | 364 |
324 DISALLOW_COPY_AND_ASSIGN(FileResource); | 365 DISALLOW_COPY_AND_ASSIGN(FileResource); |
325 }; | 366 }; |
326 | 367 |
327 // FileList represents a collection of files and folders. | 368 // FileList represents a collection of files and folders. |
328 // https://developers.google.com/drive/v2/reference/files/list | 369 // https://developers.google.com/drive/v2/reference/files/list |
329 class FileList { | 370 class FileList { |
330 public: | 371 public: |
331 ~FileList(); | 372 ~FileList(); |
332 | 373 |
333 // Registers the mapping between JSON field names and the members in this | 374 // Registers the mapping between JSON field names and the members in this |
334 // class. | 375 // class. |
335 static void RegisterJSONConverter( | 376 static void RegisterJSONConverter( |
336 base::JSONValueConverter<FileList>* converter); | 377 base::JSONValueConverter<FileList>* converter); |
| 378 |
| 379 // Creates file list from parsed JSON. |
337 static scoped_ptr<FileList> CreateFrom(const base::Value& value); | 380 static scoped_ptr<FileList> CreateFrom(const base::Value& value); |
338 | 381 |
339 // Returns the ETag of the list. | 382 // Returns the ETag of the list. |
340 const std::string& etag() const { return etag_; } | 383 const std::string& etag() const { return etag_; } |
341 | 384 |
342 // Returns the page token for the next page of files, if the list is large | 385 // Returns the page token for the next page of files, if the list is large |
343 // to fit in one response. If this is empty, there is no more file lists. | 386 // to fit in one response. If this is empty, there is no more file lists. |
344 const std::string& next_page_token() const { return next_page_token_; } | 387 const std::string& next_page_token() const { return next_page_token_; } |
345 | 388 |
346 // Returns a link to the next page of files. The URL includes the next page | 389 // Returns a link to the next page of files. The URL includes the next page |
(...skipping 13 matching lines...) Expand all Loading... |
360 bool Parse(const base::Value& value); | 403 bool Parse(const base::Value& value); |
361 | 404 |
362 std::string etag_; | 405 std::string etag_; |
363 std::string next_page_token_; | 406 std::string next_page_token_; |
364 GURL next_link_; | 407 GURL next_link_; |
365 ScopedVector<FileResource> items_; | 408 ScopedVector<FileResource> items_; |
366 | 409 |
367 DISALLOW_COPY_AND_ASSIGN(FileList); | 410 DISALLOW_COPY_AND_ASSIGN(FileList); |
368 }; | 411 }; |
369 | 412 |
| 413 // ChangeResource represents a change in a file. |
| 414 // https://developers.google.com/drive/v2/reference/changes |
| 415 class ChangeResource { |
| 416 public: |
| 417 ~ChangeResource(); |
| 418 |
| 419 // Registers the mapping between JSON field names and the members in this |
| 420 // class. |
| 421 static void RegisterJSONConverter( |
| 422 base::JSONValueConverter<ChangeResource>* converter); |
| 423 |
| 424 // Creates change resource from parsed JSON. |
| 425 static scoped_ptr<ChangeResource> CreateFrom(const base::Value& value); |
| 426 |
| 427 // Returns change ID for this change. This is a monotonically increasing |
| 428 // number. |
| 429 int64 change_id() const { return change_id_; } |
| 430 |
| 431 // Returns a string file ID for corresponding file of the change. |
| 432 const std::string& file_id() const { return file_id_; } |
| 433 |
| 434 // Returns true if this file is deleted in the change. |
| 435 bool is_deleted() const { return deleted_; } |
| 436 |
| 437 // Returns FileResource of the file which the change refers to. |
| 438 const FileResource& file() const { return file_; } |
| 439 |
| 440 private: |
| 441 friend class base::internal::RepeatedMessageConverter<ChangeResource>; |
| 442 friend class ChangeList; |
| 443 ChangeResource(); |
| 444 |
| 445 // Parses and initializes data members from content of |value|. |
| 446 // Return false if parsing fails. |
| 447 bool Parse(const base::Value& value); |
| 448 |
| 449 int64 change_id_; |
| 450 std::string file_id_; |
| 451 bool deleted_; |
| 452 FileResource file_; |
| 453 |
| 454 DISALLOW_COPY_AND_ASSIGN(ChangeResource); |
| 455 }; |
| 456 |
| 457 // ChangeList represents a set of changes in the drive. |
| 458 // https://developers.google.com/drive/v2/reference/changes/list |
| 459 class ChangeList { |
| 460 public: |
| 461 ~ChangeList(); |
| 462 |
| 463 // Registers the mapping between JSON field names and the members in this |
| 464 // class. |
| 465 static void RegisterJSONConverter( |
| 466 base::JSONValueConverter<ChangeList>* converter); |
| 467 |
| 468 // Creates change list from parsed JSON. |
| 469 static scoped_ptr<ChangeList> CreateFrom(const base::Value& value); |
| 470 |
| 471 // Returns the ETag of the list. |
| 472 const std::string& etag() const { return etag_; } |
| 473 |
| 474 // Returns the page token for the next page of files, if the list is large |
| 475 // to fit in one response. If this is empty, there is no more file lists. |
| 476 const std::string& next_page_token() const { return next_page_token_; } |
| 477 |
| 478 // Returns a link to the next page of files. The URL includes the next page |
| 479 // token. |
| 480 const GURL& next_link() const { return next_link_; } |
| 481 |
| 482 // Returns the largest change ID number. |
| 483 int64 largest_change_id() const { return largest_change_id_; } |
| 484 |
| 485 // Returns a set of changes in this list. |
| 486 const ScopedVector<ChangeResource>& items() const { return items_; } |
| 487 |
| 488 private: |
| 489 friend class DriveAPIParserTest; |
| 490 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser); |
| 491 ChangeList(); |
| 492 |
| 493 // Parses and initializes data members from content of |value|. |
| 494 // Return false if parsing fails. |
| 495 bool Parse(const base::Value& value); |
| 496 |
| 497 std::string etag_; |
| 498 std::string next_page_token_; |
| 499 GURL next_link_; |
| 500 int64 largest_change_id_; |
| 501 ScopedVector<ChangeResource> items_; |
| 502 |
| 503 DISALLOW_COPY_AND_ASSIGN(ChangeList); |
| 504 }; |
| 505 |
370 } // namespace gdata | 506 } // namespace gdata |
371 | 507 |
372 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | 508 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ |
OLD | NEW |