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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_parser.cc

Issue 10693109: Use Drive v2 API: enable behind --enable-drive-api flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove boolean use_drive_api Created 8 years, 5 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
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 #include "chrome/browser/chromeos/gdata/gdata_parser.h" 5 #include "chrome/browser/chromeos/gdata/gdata_parser.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/json/json_value_converter.h" 11 #include "base/json/json_value_converter.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/string_piece.h" 14 #include "base/string_piece.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/chromeos/gdata/gdata_util.h"
18 #include "third_party/libxml/chromium/libxml_utils.h" 19 #include "third_party/libxml/chromium/libxml_utils.h"
19 20
20 using base::Value; 21 using base::Value;
21 using base::DictionaryValue; 22 using base::DictionaryValue;
22 using base::ListValue; 23 using base::ListValue;
23 24
24 namespace gdata { 25 namespace gdata {
25 26
26 namespace { 27 namespace {
27 28
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 const char kSchemeAttr[] = "scheme"; 128 const char kSchemeAttr[] = "scheme";
128 const char kSrcAttr[] = "src"; 129 const char kSrcAttr[] = "src";
129 const char kTermAttr[] = "term"; 130 const char kTermAttr[] = "term";
130 const char kTypeAttr[] = "type"; 131 const char kTypeAttr[] = "type";
131 const char kValueAttr[] = "value"; 132 const char kValueAttr[] = "value";
132 133
133 // Link Prefixes 134 // Link Prefixes
134 const char kOpenWithPrefix[] = "http://schemas.google.com/docs/2007#open-with-"; 135 const char kOpenWithPrefix[] = "http://schemas.google.com/docs/2007#open-with-";
135 const size_t kOpenWithPrefixSize = arraysize(kOpenWithPrefix) - 1; 136 const size_t kOpenWithPrefixSize = arraysize(kOpenWithPrefix) - 1;
136 137
138 // Drive API JSON names.
139 const char kQuotaBytesTotal[] = "quotaBytesTotal";
140 const char kQuotaBytesUsed[] = "quotaBytesUsed";
141 const char kLargestChangeId[] = "largestChangeId";
142
137 struct EntryKindMap { 143 struct EntryKindMap {
138 DocumentEntry::EntryKind kind; 144 DocumentEntry::EntryKind kind;
139 const char* entry; 145 const char* entry;
140 const char* extension; 146 const char* extension;
141 }; 147 };
142 148
143 const EntryKindMap kEntryKindMap[] = { 149 const EntryKindMap kEntryKindMap[] = {
144 { DocumentEntry::ITEM, "item", NULL}, 150 { DocumentEntry::ITEM, "item", NULL},
145 { DocumentEntry::DOCUMENT, "document", ".gdoc"}, 151 { DocumentEntry::DOCUMENT, "document", ".gdoc"},
146 { DocumentEntry::SPREADSHEET, "spreadsheet", ".gsheet"}, 152 { DocumentEntry::SPREADSHEET, "spreadsheet", ".gsheet"},
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 converter->RegisterRepeatedCustomValue( 999 converter->RegisterRepeatedCustomValue(
994 kInstalledAppSecondaryFileExtensionField, 1000 kInstalledAppSecondaryFileExtensionField,
995 &InstalledApp::secondary_extensions_, 1001 &InstalledApp::secondary_extensions_,
996 &GetValueString); 1002 &GetValueString);
997 converter->RegisterRepeatedMessage(kLinkField, &InstalledApp::links_); 1003 converter->RegisterRepeatedMessage(kLinkField, &InstalledApp::links_);
998 } 1004 }
999 1005
1000 //////////////////////////////////////////////////////////////////////////////// 1006 ////////////////////////////////////////////////////////////////////////////////
1001 // AccountMetadataFeed implementation 1007 // AccountMetadataFeed implementation
1002 1008
1009 class AccountMetadataFeedDocumentList : public AccountMetadataFeed {
1010 public:
1011 AccountMetadataFeedDocumentList() : AccountMetadataFeed() {}
1012 virtual ~AccountMetadataFeedDocumentList() {}
1013
1014 // Registers the mapping between JSON field names and the members in this
1015 // class.
1016 static void RegisterJSONConverter(
1017 base::JSONValueConverter<AccountMetadataFeedDocumentList>* converter);
1018
1019 // Parses and initializes data members from content of |value|.
1020 // Return false if parsing fails.
1021 virtual bool Parse(const base::Value& value) OVERRIDE;
1022
1023 private:
1024 DISALLOW_COPY_AND_ASSIGN(AccountMetadataFeedDocumentList);
1025 };
1026
1027 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
1028 public:
1029 AccountMetadataFeedDriveAPI() : AccountMetadataFeed() {}
1030 virtual ~AccountMetadataFeedDriveAPI() {}
1031
1032 // Registers the mapping between JSON field names and the members in this
1033 // class.
1034 static void RegisterJSONConverter(
1035 base::JSONValueConverter<AccountMetadataFeedDriveAPI>* converter);
1036
1037 // Parses and initializes data members from content of |value|.
1038 // Return false if parsing fails.
1039 virtual bool Parse(const base::Value& value) OVERRIDE;
1040
1041 private:
1042 DISALLOW_COPY_AND_ASSIGN(AccountMetadataFeedDriveAPI);
1043 };
1044
1003 AccountMetadataFeed::AccountMetadataFeed() 1045 AccountMetadataFeed::AccountMetadataFeed()
1004 : quota_bytes_total_(0), 1046 : quota_bytes_total_(0),
1005 quota_bytes_used_(0), 1047 quota_bytes_used_(0),
1006 largest_changestamp_(0) { 1048 largest_changestamp_(0) {
1007 } 1049 }
1008 1050
1009 AccountMetadataFeed::~AccountMetadataFeed() { 1051 AccountMetadataFeed::~AccountMetadataFeed() {
1010 } 1052 }
1011 1053
1012 // static 1054 // static
1013 void AccountMetadataFeed::RegisterJSONConverter(
1014 base::JSONValueConverter<AccountMetadataFeed>* converter) {
1015 converter->RegisterCustomField<int64>(
1016 kQuotaBytesTotalField,
1017 &AccountMetadataFeed::quota_bytes_total_,
1018 &base::StringToInt64);
1019 converter->RegisterCustomField<int64>(
1020 kQuotaBytesUsedField,
1021 &AccountMetadataFeed::quota_bytes_used_,
1022 &base::StringToInt64);
1023 converter->RegisterCustomField<int>(
1024 kLargestChangestampField,
1025 &AccountMetadataFeed::largest_changestamp_,
1026 &base::StringToInt);
1027 converter->RegisterRepeatedMessage(kInstalledAppField,
1028 &AccountMetadataFeed::installed_apps_);
1029 }
1030
1031 // static
1032 scoped_ptr<AccountMetadataFeed> AccountMetadataFeed::CreateFrom( 1055 scoped_ptr<AccountMetadataFeed> AccountMetadataFeed::CreateFrom(
1033 const base::Value& value) { 1056 const base::Value& value) {
1034 scoped_ptr<AccountMetadataFeed> feed(new AccountMetadataFeed()); 1057 if (gdata::util::IsDriveV2ApiEnabled()) {
1058 scoped_ptr<AccountMetadataFeedDriveAPI> feed(
1059 new AccountMetadataFeedDriveAPI());
1060 if (!feed->Parse(value)) {
1061 LOG(ERROR) << "Unable to create: Invalid account metadata feed!";
1062 return scoped_ptr<AccountMetadataFeed>(NULL);
1063 }
1064 return feed.PassAs<AccountMetadataFeed>();
1065 }
1066
1067 scoped_ptr<AccountMetadataFeedDocumentList> feed(
1068 new AccountMetadataFeedDocumentList());
1035 const base::DictionaryValue* dictionary = NULL; 1069 const base::DictionaryValue* dictionary = NULL;
1036 base::Value* entry = NULL; 1070 base::Value* entry = NULL;
1037 if (!value.GetAsDictionary(&dictionary) || 1071 if (!value.GetAsDictionary(&dictionary) ||
1038 !dictionary->Get(kEntryField, &entry) || 1072 !dictionary->Get(kEntryField, &entry) ||
1039 !feed->Parse(*entry)) { 1073 !feed->Parse(*entry)) {
1040 LOG(ERROR) << "Unable to create: Invalid account metadata feed!"; 1074 LOG(ERROR) << "Unable to create: Invalid account metadata feed!";
1041 return scoped_ptr<AccountMetadataFeed>(NULL); 1075 return scoped_ptr<AccountMetadataFeed>(NULL);
1042 } 1076 }
1043 1077 return feed.PassAs<AccountMetadataFeed>();
1044 return feed.Pass();
1045 } 1078 }
1046 1079
1047 bool AccountMetadataFeed::Parse(const base::Value& value) { 1080 // static
1048 base::JSONValueConverter<AccountMetadataFeed> converter; 1081 void AccountMetadataFeedDocumentList::RegisterJSONConverter(
1082 base::JSONValueConverter<AccountMetadataFeedDocumentList>* converter) {
1083 converter->RegisterCustomField<int64>(
1084 kQuotaBytesTotalField,
1085 &AccountMetadataFeedDocumentList::quota_bytes_total_,
1086 &base::StringToInt64);
1087 converter->RegisterCustomField<int64>(
1088 kQuotaBytesUsedField,
1089 &AccountMetadataFeedDocumentList::quota_bytes_used_,
1090 &base::StringToInt64);
1091 converter->RegisterCustomField<int>(
1092 kLargestChangestampField,
1093 &AccountMetadataFeedDocumentList::largest_changestamp_,
1094 &base::StringToInt);
1095 converter->RegisterRepeatedMessage<InstalledApp>(
1096 kInstalledAppField,
1097 &AccountMetadataFeedDocumentList::installed_apps_);
1098 }
1099
1100 bool AccountMetadataFeedDocumentList::Parse(const base::Value& value) {
1101 base::JSONValueConverter<AccountMetadataFeedDocumentList> converter;
1049 if (!converter.Convert(value, this)) { 1102 if (!converter.Convert(value, this)) {
1050 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!"; 1103 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!";
1051 return false; 1104 return false;
1105 }
1106 return true;
1107 }
1108
1109 // static
1110 void AccountMetadataFeedDriveAPI::RegisterJSONConverter(
1111 base::JSONValueConverter<AccountMetadataFeedDriveAPI>* converter) {
1112 converter->RegisterCustomField<int64>(
1113 kQuotaBytesTotal,
1114 &AccountMetadataFeedDriveAPI::quota_bytes_total_,
1115 &base::StringToInt64);
1116 converter->RegisterCustomField<int64>(
1117 kQuotaBytesUsed,
1118 &AccountMetadataFeedDriveAPI::quota_bytes_used_,
1119 &base::StringToInt64);
1120 converter->RegisterCustomField<int>(
1121 kLargestChangeId,
1122 &AccountMetadataFeedDriveAPI::largest_changestamp_,
1123 &base::StringToInt);
1124 // TODO(kochi): To get installed apps, Drive V2 API needs another API call.
1125 }
1126
1127 bool AccountMetadataFeedDriveAPI::Parse(const base::Value& value) {
1128 base::JSONValueConverter<AccountMetadataFeedDriveAPI> converter;
1129 if (!converter.Convert(value, this)) {
1130 LOG(ERROR) << "Unable to parse: Invalid account metadata feed!";
1131 return false;
1052 } 1132 }
1053 return true; 1133 return true;
1054 } 1134 }
1055 1135
1056 } // namespace gdata 1136 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698