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 1d8e38cca6a325a26a1dce4668958b9fa438ce17..07fe427b2c0d56143ef8f90fd6142ab963b29da3 100644 |
--- a/chrome/browser/chromeos/gdata/gdata_parser.cc |
+++ b/chrome/browser/chromeos/gdata/gdata_parser.cc |
@@ -15,6 +15,7 @@ |
#include "base/string_util.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
+#include "chrome/browser/chromeos/gdata/gdata_util.h" |
#include "third_party/libxml/chromium/libxml_utils.h" |
using base::Value; |
@@ -134,6 +135,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 +1006,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 { |
satorux1
2012/07/10 18:10:33
What about creating a separate file like drive_api
kochi
2012/07/11 09:43:27
At first I tried to avoid that, but it seems the d
|
+ 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 +1052,80 @@ AccountMetadataFeed::~AccountMetadataFeed() { |
} |
// static |
-void AccountMetadataFeed::RegisterJSONConverter( |
- base::JSONValueConverter<AccountMetadataFeed>* converter) { |
+scoped_ptr<AccountMetadataFeed> AccountMetadataFeed::CreateFrom( |
+ const base::Value& value) { |
+ if (gdata::util::IsDriveV2ApiEnabled()) { |
+ 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; |