[email protected] | 583d46fb | 2012-11-15 03:22:32 | [diff] [blame] | 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 | |||||
[email protected] | 2b9e59a7 | 2013-06-20 03:32:16 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ |
6 | #define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ | ||||
[email protected] | 583d46fb | 2012-11-15 03:22:32 | [diff] [blame] | 7 | |
[email protected] | 002aec6a | 2013-04-18 15:14:38 | [diff] [blame] | 8 | #include <string> |
9 | |||||
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 10 | #include "base/memory/scoped_ptr.h" |
[email protected] | e196bef3 | 2013-12-03 05:33:13 | [diff] [blame] | 11 | #include "google_apis/drive/drive_common_callbacks.h" |
[email protected] | e196bef3 | 2013-12-03 05:33:13 | [diff] [blame] | 12 | #include "google_apis/drive/gdata_errorcode.h" |
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 13 | |
[email protected] | f5aed02 | 2013-05-21 03:39:10 | [diff] [blame] | 14 | class GURL; |
15 | |||||
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 16 | namespace base { |
[email protected] | 4749427 | 2013-11-07 12:36:40 | [diff] [blame] | 17 | class FilePath; |
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 18 | class Value; |
19 | } // namespace base | ||||
20 | |||||
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 21 | namespace google_apis { |
[email protected] | ed4a72a | 2013-09-12 11:11:50 | [diff] [blame] | 22 | class ChangeList; |
23 | class ChangeResource; | ||||
24 | class FileList; | ||||
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 25 | class FileResource; |
26 | class ResourceEntry; | ||||
[email protected] | ed4a72a | 2013-09-12 11:11:50 | [diff] [blame] | 27 | class ResourceList; |
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 28 | } // namespace google_apis |
29 | |||||
[email protected] | e50af765 | 2013-06-20 06:39:31 | [diff] [blame] | 30 | namespace drive { |
[email protected] | 583d46fb | 2012-11-15 03:22:32 | [diff] [blame] | 31 | namespace util { |
32 | |||||
[email protected] | 19f13a2 | 2014-04-23 08:19:02 | [diff] [blame] | 33 | // Google Apps MIME types: |
34 | const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document"; | ||||
35 | const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing"; | ||||
36 | const char kGooglePresentationMimeType[] = | ||||
37 | "application/vnd.google-apps.presentation"; | ||||
38 | const char kGoogleSpreadsheetMimeType[] = | ||||
39 | "application/vnd.google-apps.spreadsheet"; | ||||
40 | const char kGoogleTableMimeType[] = "application/vnd.google-apps.table"; | ||||
41 | const char kGoogleFormMimeType[] = "application/vnd.google-apps.form"; | ||||
fukino | 2270890 | 2014-11-04 09:00:07 | [diff] [blame^] | 42 | const char kGoogleMapMimeType[] = "application/vnd.google-apps.map"; |
[email protected] | 19f13a2 | 2014-04-23 08:19:02 | [diff] [blame] | 43 | const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder"; |
44 | |||||
[email protected] | 002aec6a | 2013-04-18 15:14:38 | [diff] [blame] | 45 | // Escapes ' to \' in the |str|. This is designed to use for string value of |
46 | // search parameter on Drive API v2. | ||||
47 | // See also: https://developers.google.com/drive/search-parameters | ||||
48 | std::string EscapeQueryStringValue(const std::string& str); | ||||
49 | |||||
[email protected] | c39ee69e | 2013-04-19 12:57:21 | [diff] [blame] | 50 | // Parses the query, and builds a search query for Drive API v2. |
51 | // This only supports: | ||||
52 | // Regular query (e.g. dog => fullText contains 'dog') | ||||
53 | // Conjunctions | ||||
54 | // (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat') | ||||
55 | // Exclusion query (e.g. -cat => not fullText contains 'cat'). | ||||
56 | // Quoted query (e.g. "dog cat" => fullText contains 'dog cat'). | ||||
57 | // See also: https://developers.google.com/drive/search-parameters | ||||
58 | std::string TranslateQuery(const std::string& original_query); | ||||
59 | |||||
[email protected] | f5aed02 | 2013-05-21 03:39:10 | [diff] [blame] | 60 | // Extracts resource_id out of edit url. |
61 | std::string ExtractResourceIdFromUrl(const GURL& url); | ||||
62 | |||||
[email protected] | 7b69787 | 2013-05-23 16:39:18 | [diff] [blame] | 63 | // If |resource_id| is in the old resource ID format used by WAPI, converts it |
64 | // into the new format. | ||||
65 | std::string CanonicalizeResourceId(const std::string& resource_id); | ||||
66 | |||||
[email protected] | ed4a72a | 2013-09-12 11:11:50 | [diff] [blame] | 67 | // Converts FileResource to ResourceEntry. |
68 | scoped_ptr<google_apis::ResourceEntry> | ||||
69 | ConvertFileResourceToResourceEntry( | ||||
70 | const google_apis::FileResource& file_resource); | ||||
71 | |||||
72 | // Converts ChangeResource to ResourceEntry. | ||||
73 | scoped_ptr<google_apis::ResourceEntry> | ||||
74 | ConvertChangeResourceToResourceEntry( | ||||
75 | const google_apis::ChangeResource& change_resource); | ||||
76 | |||||
77 | // Converts FileList to ResourceList. | ||||
78 | scoped_ptr<google_apis::ResourceList> | ||||
79 | ConvertFileListToResourceList(const google_apis::FileList& file_list); | ||||
80 | |||||
81 | // Converts ChangeList to ResourceList. | ||||
82 | scoped_ptr<google_apis::ResourceList> | ||||
83 | ConvertChangeListToResourceList(const google_apis::ChangeList& change_list); | ||||
84 | |||||
[email protected] | 4749427 | 2013-11-07 12:36:40 | [diff] [blame] | 85 | // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|, |
86 | // or an empty string if an error is found. | ||||
87 | std::string GetMd5Digest(const base::FilePath& file_path); | ||||
88 | |||||
[email protected] | 51ed7bd4 | 2014-07-14 13:58:22 | [diff] [blame] | 89 | // Returns preferred file extension for hosted documents which have given mime |
[email protected] | 4979eaf0 | 2014-07-31 11:34:20 | [diff] [blame] | 90 | // type. |
[email protected] | 51ed7bd4 | 2014-07-14 13:58:22 | [diff] [blame] | 91 | std::string GetHostedDocumentExtension(const std::string& mime_type); |
92 | |||||
[email protected] | 4979eaf0 | 2014-07-31 11:34:20 | [diff] [blame] | 93 | // Returns true if the given mime type is corresponding to one of known hosted |
94 | // document types. | ||||
95 | bool IsKnownHostedDocumentMimeType(const std::string& mime_type); | ||||
[email protected] | 51ed7bd4 | 2014-07-14 13:58:22 | [diff] [blame] | 96 | |
[email protected] | d8d9253 | 2014-07-25 10:06:26 | [diff] [blame] | 97 | // Returns true if the given file path has an extension corresponding to one of |
98 | // hosted document types. | ||||
99 | bool HasHostedDocumentExtension(const base::FilePath& path); | ||||
[email protected] | 51ed7bd4 | 2014-07-14 13:58:22 | [diff] [blame] | 100 | |
[email protected] | 002aec6a | 2013-04-18 15:14:38 | [diff] [blame] | 101 | } // namespace util |
102 | } // namespace drive | ||||
[email protected] | 583d46fb | 2012-11-15 03:22:32 | [diff] [blame] | 103 | |
[email protected] | 2b9e59a7 | 2013-06-20 03:32:16 | [diff] [blame] | 104 | #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ |