OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 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 LIBRARIES_NACL_IO_GOOGLEDRIVEFS_UTIL_H_ |
| 6 #define LIBRARIES_NACL_IO_GOOGLEDRIVEFS_UTIL_H_ |
| 7 |
| 8 #include <stdlib.h> |
| 9 |
| 10 #include "nacl_io/error.h" |
| 11 #include "nacl_io/filesystem.h" |
| 12 #include "nacl_io/path.h" |
| 13 #include "nacl_io/pepper_interface.h" |
| 14 |
| 15 namespace nacl_io { |
| 16 |
| 17 #define NACL_ARRAY_SIZE_UNSAFE(arr) ((sizeof arr) / sizeof arr[0]) |
| 18 |
| 19 static const char FOLDER_MIME_TYPE[] = "application/vnd.google-apps.folder"; |
| 20 |
| 21 static const char DRIVE_URL[] = "https://www.googleapis.com/drive/v3/files"; |
| 22 static const char UPLOAD_DRIVE_URL[] = |
| 23 "https://www.googleapis.com/upload/drive/v3/files"; |
| 24 static const char DOWNLOAD_DRIVE_URL[] = |
| 25 "https://www.googleapis.com/download/drive/v3/files"; |
| 26 |
| 27 struct RequestUrlParams { |
| 28 std::string url; |
| 29 std::string method; |
| 30 std::string headers; |
| 31 std::string body; |
| 32 }; |
| 33 |
| 34 std::string ParentEqualClause(const std::string& parent_dir_id); |
| 35 std::string NameEqualClause(const std::string& name); |
| 36 |
| 37 int ExtractYearFromRFC3339(const std::string& date_time); |
| 38 int ExtractMonthFromRFC3339(const std::string& date_time); |
| 39 int ExtractDayFromRFC3339(const std::string& date_time); |
| 40 int ExtractHourFromRFC3339(const std::string& date_time); |
| 41 int ExtractMinuteFromRFC3339(const std::string& date_time); |
| 42 int ExtractSecondFromRFC3339(const std::string& date_time); |
| 43 |
| 44 time_t ConvertDateTimeToEpochTime(int year, |
| 45 int month, |
| 46 int day, |
| 47 int hour, |
| 48 int minute, |
| 49 int second); |
| 50 |
| 51 void AddUrlPath(const std::string& path, std::string* out_url); |
| 52 void AddUrlQAttributeValue(std::string* array, |
| 53 size_t size, |
| 54 std::string* out_q_attribute_value); |
| 55 void AddUrlFirstQueryParameter(const std::string& attribute, |
| 56 const std::string& value, |
| 57 std::string* out_url); |
| 58 void AddUrlNextQueryParameter(const std::string& attribute, |
| 59 const std::string& value, |
| 60 std::string* out_url); |
| 61 void AddHeaders(const std::string& header_field_key, |
| 62 const std::string& header_field_value, |
| 63 std::string* out_headers); |
| 64 void AddBody(const std::string& data, std::string* out_body); |
| 65 Error LoadUrl(PepperInterface* ppapi, |
| 66 const RequestUrlParams& params, |
| 67 ScopedResource* out_url_response_info_resource); |
| 68 Error ReadResponseBody(PepperInterface* ppapi, |
| 69 PP_Resource url_response_info_object, |
| 70 uint32_t bytes_to_read, |
| 71 std::string* out_output); |
| 72 int32_t ReadStatusCode(PepperInterface* ppapi, |
| 73 PP_Resource url_response_info_object); |
| 74 Error GetValueStringAndValuePos(const std::string& json, |
| 75 const std::string& key, |
| 76 size_t key_search_pos, |
| 77 std::string* out_value_string, |
| 78 size_t* out_value_pos); |
| 79 Error RequestItemIdAndItemType(const std::string& parent_dir_id, |
| 80 const std::string& item_name, |
| 81 Filesystem* filesystem, |
| 82 std::string* out_item_id, |
| 83 bool* out_is_dir_type); |
| 84 Error RequestParentDirId(const Path& path, |
| 85 Filesystem* filesystem, |
| 86 std::string* out_parent_dir_id); |
| 87 } // namespace nacl_io |
| 88 |
| 89 #endif // LIBRARIES_NACL_IO_GOOGLEDRIVEFS_UTIL_H_ |
OLD | NEW |