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 GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 5 #ifndef GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
6 #define GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 6 #define GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> |
13 | 14 |
14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
15 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/scoped_vector.h" | |
18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "url/gurl.h" | 20 #include "url/gurl.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class Value; | 23 class Value; |
24 template <class StructType> | 24 template <class StructType> |
25 class JSONValueConverter; | 25 class JSONValueConverter; |
26 | 26 |
27 namespace internal { | 27 namespace internal { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 // Returns whether this application is removable by apps.delete API. | 183 // Returns whether this application is removable by apps.delete API. |
184 bool is_removable() const { return removable_; } | 184 bool is_removable() const { return removable_; } |
185 | 185 |
186 // Returns the create URL, i.e., the URL for opening a new file by the app. | 186 // Returns the create URL, i.e., the URL for opening a new file by the app. |
187 const GURL& create_url() const { return create_url_; } | 187 const GURL& create_url() const { return create_url_; } |
188 | 188 |
189 // List of primary mime types supported by this WebApp. Primary status should | 189 // List of primary mime types supported by this WebApp. Primary status should |
190 // trigger this WebApp becoming the default handler of file instances that | 190 // trigger this WebApp becoming the default handler of file instances that |
191 // have these mime types. | 191 // have these mime types. |
192 const ScopedVector<std::string>& primary_mimetypes() const { | 192 const std::vector<std::unique_ptr<std::string>>& primary_mimetypes() const { |
193 return primary_mimetypes_; | 193 return primary_mimetypes_; |
194 } | 194 } |
195 | 195 |
196 // List of secondary mime types supported by this WebApp. Secondary status | 196 // List of secondary mime types supported by this WebApp. Secondary status |
197 // should make this WebApp show up in "Open with..." pop-up menu of the | 197 // should make this WebApp show up in "Open with..." pop-up menu of the |
198 // default action menu for file with matching mime types. | 198 // default action menu for file with matching mime types. |
199 const ScopedVector<std::string>& secondary_mimetypes() const { | 199 const std::vector<std::unique_ptr<std::string>>& secondary_mimetypes() const { |
200 return secondary_mimetypes_; | 200 return secondary_mimetypes_; |
201 } | 201 } |
202 | 202 |
203 // List of primary file extensions supported by this WebApp. Primary status | 203 // List of primary file extensions supported by this WebApp. Primary status |
204 // should trigger this WebApp becoming the default handler of file instances | 204 // should trigger this WebApp becoming the default handler of file instances |
205 // that match these extensions. | 205 // that match these extensions. |
206 const ScopedVector<std::string>& primary_file_extensions() const { | 206 const std::vector<std::unique_ptr<std::string>>& primary_file_extensions() |
| 207 const { |
207 return primary_file_extensions_; | 208 return primary_file_extensions_; |
208 } | 209 } |
209 | 210 |
210 // List of secondary file extensions supported by this WebApp. Secondary | 211 // List of secondary file extensions supported by this WebApp. Secondary |
211 // status should make this WebApp show up in "Open with..." pop-up menu of the | 212 // status should make this WebApp show up in "Open with..." pop-up menu of the |
212 // default action menu for file with matching extensions. | 213 // default action menu for file with matching extensions. |
213 const ScopedVector<std::string>& secondary_file_extensions() const { | 214 const std::vector<std::unique_ptr<std::string>>& secondary_file_extensions() |
| 215 const { |
214 return secondary_file_extensions_; | 216 return secondary_file_extensions_; |
215 } | 217 } |
216 | 218 |
217 // Returns Icons for this application. An application can have multiple | 219 // Returns Icons for this application. An application can have multiple |
218 // icons for different purpose (application, document, shared document) | 220 // icons for different purpose (application, document, shared document) |
219 // in several sizes. | 221 // in several sizes. |
220 const ScopedVector<DriveAppIcon>& icons() const { | 222 const std::vector<std::unique_ptr<DriveAppIcon>>& icons() const { |
221 return icons_; | 223 return icons_; |
222 } | 224 } |
223 | 225 |
224 void set_application_id(const std::string& application_id) { | 226 void set_application_id(const std::string& application_id) { |
225 application_id_ = application_id; | 227 application_id_ = application_id; |
226 } | 228 } |
227 void set_name(const std::string& name) { name_ = name; } | 229 void set_name(const std::string& name) { name_ = name; } |
228 void set_object_type(const std::string& object_type) { | 230 void set_object_type(const std::string& object_type) { |
229 object_type_ = object_type; | 231 object_type_ = object_type; |
230 } | 232 } |
231 void set_product_id(const std::string& id) { product_id_ = id; } | 233 void set_product_id(const std::string& id) { product_id_ = id; } |
232 void set_supports_create(bool supports_create) { | 234 void set_supports_create(bool supports_create) { |
233 supports_create_ = supports_create; | 235 supports_create_ = supports_create; |
234 } | 236 } |
235 void set_removable(bool removable) { removable_ = removable; } | 237 void set_removable(bool removable) { removable_ = removable; } |
236 void set_primary_mimetypes( | 238 void set_primary_mimetypes( |
237 ScopedVector<std::string> primary_mimetypes) { | 239 std::vector<std::unique_ptr<std::string>> primary_mimetypes) { |
238 primary_mimetypes_ = std::move(primary_mimetypes); | 240 primary_mimetypes_ = std::move(primary_mimetypes); |
239 } | 241 } |
240 void set_secondary_mimetypes( | 242 void set_secondary_mimetypes( |
241 ScopedVector<std::string> secondary_mimetypes) { | 243 std::vector<std::unique_ptr<std::string>> secondary_mimetypes) { |
242 secondary_mimetypes_ = std::move(secondary_mimetypes); | 244 secondary_mimetypes_ = std::move(secondary_mimetypes); |
243 } | 245 } |
244 void set_primary_file_extensions( | 246 void set_primary_file_extensions( |
245 ScopedVector<std::string> primary_file_extensions) { | 247 std::vector<std::unique_ptr<std::string>> primary_file_extensions) { |
246 primary_file_extensions_ = std::move(primary_file_extensions); | 248 primary_file_extensions_ = std::move(primary_file_extensions); |
247 } | 249 } |
248 void set_secondary_file_extensions( | 250 void set_secondary_file_extensions( |
249 ScopedVector<std::string> secondary_file_extensions) { | 251 std::vector<std::unique_ptr<std::string>> secondary_file_extensions) { |
250 secondary_file_extensions_ = std::move(secondary_file_extensions); | 252 secondary_file_extensions_ = std::move(secondary_file_extensions); |
251 } | 253 } |
252 void set_icons(ScopedVector<DriveAppIcon> icons) { | 254 void set_icons(std::vector<std::unique_ptr<DriveAppIcon>> icons) { |
253 icons_ = std::move(icons); | 255 icons_ = std::move(icons); |
254 } | 256 } |
255 void set_create_url(const GURL& url) { | 257 void set_create_url(const GURL& url) { |
256 create_url_ = url; | 258 create_url_ = url; |
257 } | 259 } |
258 | 260 |
259 private: | 261 private: |
260 friend class base::internal::RepeatedMessageConverter<AppResource>; | 262 friend class base::internal::RepeatedMessageConverter<AppResource>; |
261 friend class AppList; | 263 friend class AppList; |
262 | 264 |
263 // Parses and initializes data members from content of |value|. | 265 // Parses and initializes data members from content of |value|. |
264 // Return false if parsing fails. | 266 // Return false if parsing fails. |
265 bool Parse(const base::Value& value); | 267 bool Parse(const base::Value& value); |
266 | 268 |
267 std::string application_id_; | 269 std::string application_id_; |
268 std::string name_; | 270 std::string name_; |
269 std::string object_type_; | 271 std::string object_type_; |
270 std::string product_id_; | 272 std::string product_id_; |
271 bool supports_create_; | 273 bool supports_create_; |
272 bool removable_; | 274 bool removable_; |
273 GURL create_url_; | 275 GURL create_url_; |
274 ScopedVector<std::string> primary_mimetypes_; | 276 std::vector<std::unique_ptr<std::string>> primary_mimetypes_; |
275 ScopedVector<std::string> secondary_mimetypes_; | 277 std::vector<std::unique_ptr<std::string>> secondary_mimetypes_; |
276 ScopedVector<std::string> primary_file_extensions_; | 278 std::vector<std::unique_ptr<std::string>> primary_file_extensions_; |
277 ScopedVector<std::string> secondary_file_extensions_; | 279 std::vector<std::unique_ptr<std::string>> secondary_file_extensions_; |
278 ScopedVector<DriveAppIcon> icons_; | 280 std::vector<std::unique_ptr<DriveAppIcon>> icons_; |
279 | 281 |
280 DISALLOW_COPY_AND_ASSIGN(AppResource); | 282 DISALLOW_COPY_AND_ASSIGN(AppResource); |
281 }; | 283 }; |
282 | 284 |
283 // AppList represents a list of Drive Applications. | 285 // AppList represents a list of Drive Applications. |
284 // https://developers.google.com/drive/v2/reference/apps/list | 286 // https://developers.google.com/drive/v2/reference/apps/list |
285 class AppList { | 287 class AppList { |
286 public: | 288 public: |
287 AppList(); | 289 AppList(); |
288 ~AppList(); | 290 ~AppList(); |
289 | 291 |
290 // Registers the mapping between JSON field names and the members in this | 292 // Registers the mapping between JSON field names and the members in this |
291 // class. | 293 // class. |
292 static void RegisterJSONConverter( | 294 static void RegisterJSONConverter( |
293 base::JSONValueConverter<AppList>* converter); | 295 base::JSONValueConverter<AppList>* converter); |
294 | 296 |
295 // Creates app list from parsed JSON. | 297 // Creates app list from parsed JSON. |
296 static std::unique_ptr<AppList> CreateFrom(const base::Value& value); | 298 static std::unique_ptr<AppList> CreateFrom(const base::Value& value); |
297 | 299 |
298 // ETag for this resource. | 300 // ETag for this resource. |
299 const std::string& etag() const { return etag_; } | 301 const std::string& etag() const { return etag_; } |
300 | 302 |
301 // Returns a vector of applications. | 303 // Returns a vector of applications. |
302 const ScopedVector<AppResource>& items() const { return items_; } | 304 const std::vector<std::unique_ptr<AppResource>>& items() const { |
| 305 return items_; |
| 306 } |
303 | 307 |
304 void set_etag(const std::string& etag) { | 308 void set_etag(const std::string& etag) { |
305 etag_ = etag; | 309 etag_ = etag; |
306 } | 310 } |
307 void set_items(ScopedVector<AppResource> items) { items_ = std::move(items); } | 311 void set_items(std::vector<std::unique_ptr<AppResource>> items) { |
| 312 items_ = std::move(items); |
| 313 } |
308 | 314 |
309 private: | 315 private: |
310 friend class DriveAPIParserTest; | 316 friend class DriveAPIParserTest; |
311 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AppListParser); | 317 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, AppListParser); |
312 | 318 |
313 // Parses and initializes data members from content of |value|. | 319 // Parses and initializes data members from content of |value|. |
314 // Return false if parsing fails. | 320 // Return false if parsing fails. |
315 bool Parse(const base::Value& value); | 321 bool Parse(const base::Value& value); |
316 | 322 |
317 std::string etag_; | 323 std::string etag_; |
318 ScopedVector<AppResource> items_; | 324 std::vector<std::unique_ptr<AppResource>> items_; |
319 | 325 |
320 DISALLOW_COPY_AND_ASSIGN(AppList); | 326 DISALLOW_COPY_AND_ASSIGN(AppList); |
321 }; | 327 }; |
322 | 328 |
323 // ParentReference represents a directory. | 329 // ParentReference represents a directory. |
324 // https://developers.google.com/drive/v2/reference/parents | 330 // https://developers.google.com/drive/v2/reference/parents |
325 class ParentReference { | 331 class ParentReference { |
326 public: | 332 public: |
327 ParentReference(); | 333 ParentReference(); |
328 ~ParentReference(); | 334 ~ParentReference(); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 static bool HasFileListKind(const base::Value& value); | 612 static bool HasFileListKind(const base::Value& value); |
607 | 613 |
608 // Creates file list from parsed JSON. | 614 // Creates file list from parsed JSON. |
609 static std::unique_ptr<FileList> CreateFrom(const base::Value& value); | 615 static std::unique_ptr<FileList> CreateFrom(const base::Value& value); |
610 | 616 |
611 // Returns a link to the next page of files. The URL includes the next page | 617 // Returns a link to the next page of files. The URL includes the next page |
612 // token. | 618 // token. |
613 const GURL& next_link() const { return next_link_; } | 619 const GURL& next_link() const { return next_link_; } |
614 | 620 |
615 // Returns a set of files in this list. | 621 // Returns a set of files in this list. |
616 const ScopedVector<FileResource>& items() const { return items_; } | 622 const std::vector<std::unique_ptr<FileResource>>& items() const { |
617 ScopedVector<FileResource>* mutable_items() { return &items_; } | 623 return items_; |
| 624 } |
| 625 std::vector<std::unique_ptr<FileResource>>* mutable_items() { |
| 626 return &items_; |
| 627 } |
618 | 628 |
619 void set_next_link(const GURL& next_link) { | 629 void set_next_link(const GURL& next_link) { |
620 next_link_ = next_link; | 630 next_link_ = next_link; |
621 } | 631 } |
622 | 632 |
623 private: | 633 private: |
624 friend class DriveAPIParserTest; | 634 friend class DriveAPIParserTest; |
625 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, FileListParser); | 635 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, FileListParser); |
626 | 636 |
627 // Parses and initializes data members from content of |value|. | 637 // Parses and initializes data members from content of |value|. |
628 // Return false if parsing fails. | 638 // Return false if parsing fails. |
629 bool Parse(const base::Value& value); | 639 bool Parse(const base::Value& value); |
630 | 640 |
631 GURL next_link_; | 641 GURL next_link_; |
632 ScopedVector<FileResource> items_; | 642 std::vector<std::unique_ptr<FileResource>> items_; |
633 | 643 |
634 DISALLOW_COPY_AND_ASSIGN(FileList); | 644 DISALLOW_COPY_AND_ASSIGN(FileList); |
635 }; | 645 }; |
636 | 646 |
637 // ChangeResource represents a change in a file. | 647 // ChangeResource represents a change in a file. |
638 // https://developers.google.com/drive/v2/reference/changes | 648 // https://developers.google.com/drive/v2/reference/changes |
639 class ChangeResource { | 649 class ChangeResource { |
640 public: | 650 public: |
641 ChangeResource(); | 651 ChangeResource(); |
642 ~ChangeResource(); | 652 ~ChangeResource(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 static std::unique_ptr<ChangeList> CreateFrom(const base::Value& value); | 724 static std::unique_ptr<ChangeList> CreateFrom(const base::Value& value); |
715 | 725 |
716 // Returns a link to the next page of files. The URL includes the next page | 726 // Returns a link to the next page of files. The URL includes the next page |
717 // token. | 727 // token. |
718 const GURL& next_link() const { return next_link_; } | 728 const GURL& next_link() const { return next_link_; } |
719 | 729 |
720 // Returns the largest change ID number. | 730 // Returns the largest change ID number. |
721 int64_t largest_change_id() const { return largest_change_id_; } | 731 int64_t largest_change_id() const { return largest_change_id_; } |
722 | 732 |
723 // Returns a set of changes in this list. | 733 // Returns a set of changes in this list. |
724 const ScopedVector<ChangeResource>& items() const { return items_; } | 734 const std::vector<std::unique_ptr<ChangeResource>>& items() const { |
725 ScopedVector<ChangeResource>* mutable_items() { return &items_; } | 735 return items_; |
| 736 } |
| 737 std::vector<std::unique_ptr<ChangeResource>>* mutable_items() { |
| 738 return &items_; |
| 739 } |
726 | 740 |
727 void set_next_link(const GURL& next_link) { | 741 void set_next_link(const GURL& next_link) { |
728 next_link_ = next_link; | 742 next_link_ = next_link; |
729 } | 743 } |
730 void set_largest_change_id(int64_t largest_change_id) { | 744 void set_largest_change_id(int64_t largest_change_id) { |
731 largest_change_id_ = largest_change_id; | 745 largest_change_id_ = largest_change_id; |
732 } | 746 } |
733 | 747 |
734 private: | 748 private: |
735 friend class DriveAPIParserTest; | 749 friend class DriveAPIParserTest; |
736 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser); | 750 FRIEND_TEST_ALL_PREFIXES(DriveAPIParserTest, ChangeListParser); |
737 | 751 |
738 // Parses and initializes data members from content of |value|. | 752 // Parses and initializes data members from content of |value|. |
739 // Return false if parsing fails. | 753 // Return false if parsing fails. |
740 bool Parse(const base::Value& value); | 754 bool Parse(const base::Value& value); |
741 | 755 |
742 GURL next_link_; | 756 GURL next_link_; |
743 int64_t largest_change_id_; | 757 int64_t largest_change_id_; |
744 ScopedVector<ChangeResource> items_; | 758 std::vector<std::unique_ptr<ChangeResource>> items_; |
745 | 759 |
746 DISALLOW_COPY_AND_ASSIGN(ChangeList); | 760 DISALLOW_COPY_AND_ASSIGN(ChangeList); |
747 }; | 761 }; |
748 | 762 |
749 } // namespace google_apis | 763 } // namespace google_apis |
750 | 764 |
751 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ | 765 #endif // GOOGLE_APIS_DRIVE_DRIVE_API_PARSER_H_ |
OLD | NEW |