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