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