| Index: chrome/browser/chromeos/gdata/gdata_parser.cc
|
| diff --git a/chrome/browser/chromeos/gdata/gdata_parser.cc b/chrome/browser/chromeos/gdata/gdata_parser.cc
|
| index 7cd8edbded8541dcac47b2950db8b4837c872eb0..acfc46274189f578e07c005dfa3e000538972eed 100644
|
| --- a/chrome/browser/chromeos/gdata/gdata_parser.cc
|
| +++ b/chrome/browser/chromeos/gdata/gdata_parser.cc
|
| @@ -134,6 +134,11 @@ const char kValueAttr[] = "value";
|
| const char kOpenWithPrefix[] = "http://schemas.google.com/docs/2007#open-with-";
|
| const size_t kOpenWithPrefixSize = arraysize(kOpenWithPrefix) - 1;
|
|
|
| +// Drive API JSON names.
|
| +const char kQuotaBytesTotal[] = "quotaBytesTotal";
|
| +const char kQuotaBytesUsed[] = "quotaBytesUsed";
|
| +const char kLargestChangeId[] = "largestChangeId";
|
| +
|
| struct EntryKindMap {
|
| DocumentEntry::EntryKind kind;
|
| const char* entry;
|
| @@ -1000,6 +1005,42 @@ void InstalledApp::RegisterJSONConverter(
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // AccountMetadataFeed implementation
|
|
|
| +class AccountMetadataFeedDocumentList : public AccountMetadataFeed {
|
| + public:
|
| + AccountMetadataFeedDocumentList() : AccountMetadataFeed() {}
|
| + virtual ~AccountMetadataFeedDocumentList() {}
|
| +
|
| + // Registers the mapping between JSON field names and the members in this
|
| + // class.
|
| + static void RegisterJSONConverter(
|
| + base::JSONValueConverter<AccountMetadataFeedDocumentList>* converter);
|
| +
|
| + // Parses and initializes data members from content of |value|.
|
| + // Return false if parsing fails.
|
| + virtual bool Parse(const base::Value& value) OVERRIDE;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(AccountMetadataFeedDocumentList);
|
| +};
|
| +
|
| +class AccountMetadataFeedDriveAPI : public AccountMetadataFeed {
|
| + public:
|
| + AccountMetadataFeedDriveAPI() : AccountMetadataFeed() {}
|
| + virtual ~AccountMetadataFeedDriveAPI() {}
|
| +
|
| + // Registers the mapping between JSON field names and the members in this
|
| + // class.
|
| + static void RegisterJSONConverter(
|
| + base::JSONValueConverter<AccountMetadataFeedDriveAPI>* converter);
|
| +
|
| + // Parses and initializes data members from content of |value|.
|
| + // Return false if parsing fails.
|
| + virtual bool Parse(const base::Value& value) OVERRIDE;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(AccountMetadataFeedDriveAPI);
|
| +};
|
| +
|
| AccountMetadataFeed::AccountMetadataFeed()
|
| : quota_bytes_total_(0),
|
| quota_bytes_used_(0),
|
| @@ -1010,42 +1051,80 @@ AccountMetadataFeed::~AccountMetadataFeed() {
|
| }
|
|
|
| // static
|
| -void AccountMetadataFeed::RegisterJSONConverter(
|
| - base::JSONValueConverter<AccountMetadataFeed>* converter) {
|
| +scoped_ptr<AccountMetadataFeed> AccountMetadataFeed::CreateFrom(
|
| + const base::Value& value, bool use_drive_api) {
|
| + if (use_drive_api) {
|
| + scoped_ptr<AccountMetadataFeedDriveAPI> feed(
|
| + new AccountMetadataFeedDriveAPI());
|
| + if (!feed->Parse(value)) {
|
| + LOG(ERROR) << "Unable to create: Invalid account metadata feed!";
|
| + return scoped_ptr<AccountMetadataFeed>(NULL);
|
| + }
|
| + return feed.PassAs<AccountMetadataFeed>();
|
| + }
|
| +
|
| + scoped_ptr<AccountMetadataFeedDocumentList> feed(
|
| + new AccountMetadataFeedDocumentList());
|
| + const base::DictionaryValue* dictionary = NULL;
|
| + base::Value* entry = NULL;
|
| + if (!value.GetAsDictionary(&dictionary) ||
|
| + !dictionary->Get(kEntryField, &entry) ||
|
| + !feed->Parse(*entry)) {
|
| + LOG(ERROR) << "Unable to create: Invalid account metadata feed!";
|
| + return scoped_ptr<AccountMetadataFeed>(NULL);
|
| + }
|
| + return feed.PassAs<AccountMetadataFeed>();
|
| +}
|
| +
|
| +// static
|
| +void AccountMetadataFeedDocumentList::RegisterJSONConverter(
|
| + base::JSONValueConverter<AccountMetadataFeedDocumentList>* converter) {
|
| converter->RegisterCustomField<int64>(
|
| kQuotaBytesTotalField,
|
| - &AccountMetadataFeed::quota_bytes_total_,
|
| + &AccountMetadataFeedDocumentList::quota_bytes_total_,
|
| &base::StringToInt64);
|
| converter->RegisterCustomField<int64>(
|
| kQuotaBytesUsedField,
|
| - &AccountMetadataFeed::quota_bytes_used_,
|
| + &AccountMetadataFeedDocumentList::quota_bytes_used_,
|
| &base::StringToInt64);
|
| converter->RegisterCustomField<int>(
|
| kLargestChangestampField,
|
| - &AccountMetadataFeed::largest_changestamp_,
|
| + &AccountMetadataFeedDocumentList::largest_changestamp_,
|
| &base::StringToInt);
|
| - converter->RegisterRepeatedMessage(kInstalledAppField,
|
| - &AccountMetadataFeed::installed_apps_);
|
| + converter->RegisterRepeatedMessage<InstalledApp>(
|
| + kInstalledAppField,
|
| + &AccountMetadataFeedDocumentList::installed_apps_);
|
| }
|
|
|
| -// static
|
| -scoped_ptr<AccountMetadataFeed> AccountMetadataFeed::CreateFrom(
|
| - const base::Value& value) {
|
| - scoped_ptr<AccountMetadataFeed> feed(new AccountMetadataFeed());
|
| - const base::DictionaryValue* dictionary = NULL;
|
| - base::Value* entry = NULL;
|
| - if (!value.GetAsDictionary(&dictionary) ||
|
| - !dictionary->Get(kEntryField, &entry) ||
|
| - !feed->Parse(*entry)) {
|
| - LOG(ERROR) << "Unable to create: Invalid account metadata feed!";
|
| - return scoped_ptr<AccountMetadataFeed>(NULL);
|
| +bool AccountMetadataFeedDocumentList::Parse(const base::Value& value) {
|
| + base::JSONValueConverter<AccountMetadataFeedDocumentList> converter;
|
| + if (!converter.Convert(value, this)) {
|
| + LOG(ERROR) << "Unable to parse: Invalid account metadata feed!";
|
| + return false;
|
| }
|
| + return true;
|
| +}
|
|
|
| - return feed.Pass();
|
| +// static
|
| +void AccountMetadataFeedDriveAPI::RegisterJSONConverter(
|
| + base::JSONValueConverter<AccountMetadataFeedDriveAPI>* converter) {
|
| + converter->RegisterCustomField<int64>(
|
| + kQuotaBytesTotal,
|
| + &AccountMetadataFeedDriveAPI::quota_bytes_total_,
|
| + &base::StringToInt64);
|
| + converter->RegisterCustomField<int64>(
|
| + kQuotaBytesUsed,
|
| + &AccountMetadataFeedDriveAPI::quota_bytes_used_,
|
| + &base::StringToInt64);
|
| + converter->RegisterCustomField<int>(
|
| + kLargestChangeId,
|
| + &AccountMetadataFeedDriveAPI::largest_changestamp_,
|
| + &base::StringToInt);
|
| + // TODO(kochi): To get installed apps, Drive V2 API needs another API call.
|
| }
|
|
|
| -bool AccountMetadataFeed::Parse(const base::Value& value) {
|
| - base::JSONValueConverter<AccountMetadataFeed> converter;
|
| +bool AccountMetadataFeedDriveAPI::Parse(const base::Value& value) {
|
| + base::JSONValueConverter<AccountMetadataFeedDriveAPI> converter;
|
| if (!converter.Convert(value, this)) {
|
| LOG(ERROR) << "Unable to parse: Invalid account metadata feed!";
|
| return false;
|
|
|