Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/scoped_vector.h" | |
| 15 #include "base/string_piece.h" | |
| 16 #include "base/time.h" | |
| 17 #include "googleurl/src/gurl.h" | |
| 18 | |
| 19 namespace base { | |
| 20 class Value; | |
| 21 template <class StructType> | |
| 22 class JSONValueConverter; | |
| 23 | |
| 24 namespace internal { | |
| 25 template <class NestedType> | |
| 26 class RepeatedMessageConverter; | |
| 27 } // namespace internal | |
| 28 } // namespace base | |
| 29 | |
| 30 // TODO(kochi): Rename to namespace drive. http://crbug.com/136371 | |
| 31 namespace gdata { | |
| 32 | |
| 33 // About resource represents the account information about the current user. | |
| 34 // https://developers.google.com/drive/v2/reference/about | |
|
satorux1
2012/07/25 19:39:57
Nice to have a link like this!
| |
| 35 class AboutResource { | |
| 36 public: | |
| 37 ~AboutResource(); | |
| 38 | |
| 39 // Registers the mapping between JSON field names and the members in this | |
| 40 // class. | |
| 41 static void RegisterJSONConverter( | |
| 42 base::JSONValueConverter<AboutResource>* converter); | |
| 43 | |
| 44 // Creates about resource from parsed JSON. | |
| 45 static scoped_ptr<AboutResource> CreateFrom(const base::Value& value); | |
| 46 | |
| 47 // Returns root folder ID. | |
| 48 const std::string& root_folder_id() const { return root_folder_id_; } | |
| 49 // Returns total number of quta bytes. | |
| 50 int64 quota_bytes_total() const { return quota_bytes_total_; } | |
| 51 // Returns the number of quota bytes used. | |
| 52 int64 quota_bytes_used() const { return quota_bytes_used_; } | |
| 53 // Returns the largest change ID number. | |
| 54 int64 largest_change_id() const { return largest_change_id_; } | |
| 55 | |
| 56 private: | |
| 57 friend class DriveAPIParserTest; | |
| 58 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AboutResourceParser); | |
| 59 AboutResource(); | |
| 60 | |
| 61 // Parses and initializes data members from content of |value|. | |
| 62 // Return false if parsing fails. | |
| 63 bool Parse(const base::Value& value) OVERRIDE; | |
|
kochi
2012/07/25 13:40:51
no OVERRIDE.
| |
| 64 | |
| 65 std::string root_folder_id_; | |
| 66 int64 quota_bytes_total_; | |
| 67 int64 quota_bytes_used_; | |
| 68 int64 largest_change_id_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(AboutResource); | |
| 71 }; | |
| 72 | |
| 73 // DriveAppIcon represents an icon for Drive Application. | |
| 74 // https://developers.google.com/drive/v2/reference/apps/list | |
| 75 class DriveAppIcon { | |
| 76 public: | |
| 77 enum IconCategory { | |
| 78 UNKNOWN, // Uninitialized state | |
| 79 DOCUMENT, // Document icon for various MIME types | |
| 80 APPLICATION, // Application icon for various MIME types | |
| 81 SHARED_DOCUMENT, // Icon for documents that are shared from other users. | |
| 82 }; | |
| 83 | |
| 84 ~DriveAppIcon(); | |
| 85 | |
| 86 // Registers the mapping between JSON field names and the members in this | |
| 87 // class. | |
| 88 static void RegisterJSONConverter( | |
| 89 base::JSONValueConverter<DriveAppIcon>* converter); | |
| 90 | |
| 91 // Creates drive app icon instance from parsed JSON. | |
| 92 static scoped_ptr<DriveAppIcon> CreateFrom(const base::Value& value); | |
| 93 | |
| 94 // Category of the icon. | |
| 95 IconCategory category() const { return category_; } | |
| 96 | |
| 97 // Size in pixels of one side of the icon (icons are always square). | |
| 98 const int icon_side_length() const { return icon_side_length_; } | |
| 99 | |
| 100 // Returns URL for this icon. | |
| 101 const GURL& icon_url() const { return icon_url_; } | |
| 102 | |
| 103 private: | |
| 104 // Parses and initializes data members from content of |value|. | |
| 105 // Return false if parsing fails. | |
| 106 bool Parse(const base::Value& value); | |
| 107 | |
| 108 // Extracts the icon category from the given string. Returns false and does | |
| 109 // not change |result| when |scheme| has an unrecognizable value. | |
| 110 static bool GetIconCategory(const base::StringPiece& category, | |
| 111 IconCategory* result); | |
| 112 | |
| 113 friend class base::internal::RepeatedMessageConverter<DriveAppIcon>; | |
| 114 friend class AppResource; | |
| 115 DriveAppIcon(); | |
| 116 | |
| 117 IconCategory category_; | |
| 118 int icon_side_length_; | |
| 119 GURL icon_url_; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(DriveAppIcon); | |
| 122 }; | |
| 123 | |
| 124 // AppResource represents a Drive Application. | |
| 125 // https://developers.google.com/drive/v2/reference/apps/list | |
| 126 class AppResource { | |
| 127 public: | |
| 128 ~AppResource(); | |
| 129 | |
| 130 // Registers the mapping between JSON field names and the members in this | |
| 131 // class. | |
| 132 static void RegisterJSONConverter( | |
| 133 base::JSONValueConverter<AppResource>* converter); | |
| 134 | |
| 135 // Creates app resource from parsed JSON. | |
| 136 static scoped_ptr<AppResource> CreateFrom(const base::Value& value); | |
| 137 | |
| 138 // Returns application ID. | |
|
satorux1
2012/07/25 19:39:57
how does it look like? could you add an example he
kochi
2012/07/26 02:16:10
Done.
| |
| 139 const std::string& id() const { return id_; } | |
| 140 | |
| 141 // Returns application name. | |
| 142 const std::string& name() const { return name_; } | |
| 143 | |
| 144 // Returns the name of the type of object this application creates. | |
|
satorux1
2012/07/25 19:39:57
ditto.
kochi
2012/07/26 02:16:10
I thought this is mime-type, but it seems not.
I'l
| |
| 145 const std::string& object_type() const { return object_type_; } | |
| 146 | |
| 147 // Returns whether this application suuports creating new objects. | |
| 148 bool supports_create() const { return supports_create_; } | |
| 149 | |
| 150 // Returns whether this application supports importing Google Docs. | |
| 151 bool supports_import() const { return supports_import_; } | |
| 152 | |
| 153 // Returns whether this application is installed. | |
| 154 bool installed() const { return installed_; } | |
|
satorux1
2012/07/25 19:39:57
maybe add is_
kochi
2012/07/26 02:16:10
Done.
| |
| 155 | |
| 156 // Returns whether this application is authorized to access data on the | |
| 157 // user's Drive. | |
| 158 bool authorized() const { return authorized_; } | |
|
satorux1
2012/07/25 19:39:57
ditto.
kochi
2012/07/26 02:16:10
Done.
| |
| 159 | |
| 160 // Returns the product URL, e.g. at Chrmoe Web Store. | |
| 161 const GURL& product_url() const { return product_url_; } | |
| 162 | |
| 163 // List of primary mime types supported by this WebApp. Primary status should | |
| 164 // trigger this WebApp becoming the default handler of file instances that | |
| 165 // have these mime types. | |
| 166 const ScopedVector<std::string>& primary_mimetypes() const { | |
| 167 return primary_mimetypes_; | |
| 168 } | |
| 169 | |
| 170 // List of secondary mime types supported by this WebApp. Secondary status | |
| 171 // should make this WebApp show up in "Open with..." pop-up menu of the | |
| 172 // default action menu for file with matching mime types. | |
| 173 const ScopedVector<std::string>& secondary_mimetypes() const { | |
| 174 return secondary_mimetypes_; | |
| 175 } | |
| 176 | |
| 177 // List of primary file extensions supported by this WebApp. Primary status | |
| 178 // should trigger this WebApp becoming the default handler of file instances | |
| 179 // that match these extensions. | |
| 180 const ScopedVector<std::string>& primary_file_extensions() const { | |
| 181 return primary_file_extensions_; | |
| 182 } | |
| 183 | |
| 184 // List of secondary file extensions supported by this WebApp. Secondary | |
| 185 // status should make this WebApp show up in "Open with..." pop-up menu of the | |
| 186 // default action menu for file with matching extensions. | |
| 187 const ScopedVector<std::string>& secondary_file_extensions() const { | |
| 188 return secondary_file_extensions_; | |
| 189 } | |
| 190 | |
| 191 // Returns Icons for this application. An application can have multiple | |
| 192 // icons for different purpose (application, document, shared document) | |
| 193 // in several sizes. | |
| 194 const ScopedVector<DriveAppIcon>& icons() const { | |
| 195 return icons_; | |
| 196 } | |
| 197 | |
| 198 private: | |
| 199 friend class base::internal::RepeatedMessageConverter<AppResource>; | |
| 200 friend class AppList; | |
| 201 AppResource(); | |
| 202 | |
| 203 // Parses and initializes data members from content of |value|. | |
| 204 // Return false if parsing fails. | |
| 205 bool Parse(const base::Value& value); | |
| 206 | |
| 207 std::string id_; | |
| 208 std::string name_; | |
| 209 std::string object_type_; | |
| 210 bool supports_create_; | |
| 211 bool supports_import_; | |
| 212 bool installed_; | |
| 213 bool authorized_; | |
| 214 GURL product_url_; | |
| 215 ScopedVector<std::string> primary_mimetypes_; | |
| 216 ScopedVector<std::string> secondary_mimetypes_; | |
| 217 ScopedVector<std::string> primary_file_extensions_; | |
| 218 ScopedVector<std::string> secondary_file_extensions_; | |
| 219 ScopedVector<DriveAppIcon> icons_; | |
| 220 | |
| 221 DISALLOW_COPY_AND_ASSIGN(AppResource); | |
| 222 }; | |
| 223 | |
| 224 // AppList represents a list of Drive Applications. | |
| 225 // https://developers.google.com/drive/v2/reference/apps/list | |
| 226 class AppList { | |
| 227 public: | |
| 228 ~AppList(); | |
| 229 | |
| 230 // Registers the mapping between JSON field names and the members in this | |
| 231 // class. | |
| 232 static void RegisterJSONConverter( | |
| 233 base::JSONValueConverter<AppList>* converter); | |
| 234 | |
| 235 // Creates app list from parsed JSON. | |
| 236 static scoped_ptr<AppList> CreateFrom(const base::Value& value); | |
| 237 | |
| 238 // ETag for this resource. | |
| 239 const std::string& etag() const { return etag_; } | |
| 240 | |
| 241 // Returns a vector of applications. | |
| 242 const ScopedVector<AppResource>& items() const { return items_; } | |
| 243 | |
| 244 private: | |
| 245 friend class DriveAPIParserTest; | |
| 246 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AppListParser); | |
| 247 AppList(); | |
| 248 | |
| 249 // Parses and initializes data members from content of |value|. | |
| 250 // Return false if parsing fails. | |
| 251 bool Parse(const base::Value& value); | |
| 252 | |
| 253 std::string etag_; | |
| 254 ScopedVector<AppResource> items_; | |
| 255 | |
| 256 DISALLOW_COPY_AND_ASSIGN(AppList); | |
| 257 }; | |
| 258 | |
| 259 } // namespace gdata | |
| 260 | |
| 261 #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_PARSER_H_ | |
| OLD | NEW |