[email protected] | 583d46f | 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] | 583d46f | 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] | 09f0c3b | 2013-10-21 05:29:41 | [diff] [blame] | 11 | #include "chrome/browser/drive/drive_service_interface.h" |
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 12 | #include "chrome/browser/google_apis/drive_common_callbacks.h" |
[email protected] | 8445510e | 2013-09-13 13:27:07 | [diff] [blame] | 13 | #include "chrome/browser/google_apis/drive_entry_kinds.h" |
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 14 | #include "chrome/browser/google_apis/gdata_errorcode.h" |
| 15 | |
[email protected] | f5aed02 | 2013-05-21 03:39:10 | [diff] [blame] | 16 | class GURL; |
| 17 | |
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 18 | namespace base { |
[email protected] | 4749427 | 2013-11-07 12:36:40 | [diff] [blame^] | 19 | class FilePath; |
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 20 | class Value; |
| 21 | } // namespace base |
| 22 | |
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 23 | namespace google_apis { |
[email protected] | 8445510e | 2013-09-13 13:27:07 | [diff] [blame] | 24 | class AccountMetadata; |
| 25 | class AppIcon; |
| 26 | class AppList; |
| 27 | class AppResource; |
[email protected] | ed4a72a | 2013-09-12 11:11:50 | [diff] [blame] | 28 | class ChangeList; |
| 29 | class ChangeResource; |
[email protected] | 8445510e | 2013-09-13 13:27:07 | [diff] [blame] | 30 | class DriveAppIcon; |
[email protected] | ed4a72a | 2013-09-12 11:11:50 | [diff] [blame] | 31 | class FileList; |
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 32 | class FileResource; |
[email protected] | 8445510e | 2013-09-13 13:27:07 | [diff] [blame] | 33 | class InstalledApp; |
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 34 | class ResourceEntry; |
[email protected] | ed4a72a | 2013-09-12 11:11:50 | [diff] [blame] | 35 | class ResourceList; |
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 36 | } // namespace google_apis |
| 37 | |
[email protected] | e50af765 | 2013-06-20 06:39:31 | [diff] [blame] | 38 | namespace drive { |
[email protected] | 583d46f | 2012-11-15 03:22:32 | [diff] [blame] | 39 | namespace util { |
| 40 | |
| 41 | // Returns true if Drive v2 API is enabled via commandline switch. |
| 42 | bool IsDriveV2ApiEnabled(); |
| 43 | |
[email protected] | 002aec6a | 2013-04-18 15:14:38 | [diff] [blame] | 44 | // Escapes ' to \' in the |str|. This is designed to use for string value of |
| 45 | // search parameter on Drive API v2. |
| 46 | // See also: https://developers.google.com/drive/search-parameters |
| 47 | std::string EscapeQueryStringValue(const std::string& str); |
| 48 | |
[email protected] | c39ee69e | 2013-04-19 12:57:21 | [diff] [blame] | 49 | // Parses the query, and builds a search query for Drive API v2. |
| 50 | // This only supports: |
| 51 | // Regular query (e.g. dog => fullText contains 'dog') |
| 52 | // Conjunctions |
| 53 | // (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat') |
| 54 | // Exclusion query (e.g. -cat => not fullText contains 'cat'). |
| 55 | // Quoted query (e.g. "dog cat" => fullText contains 'dog cat'). |
| 56 | // See also: https://developers.google.com/drive/search-parameters |
| 57 | std::string TranslateQuery(const std::string& original_query); |
| 58 | |
[email protected] | f5aed02 | 2013-05-21 03:39:10 | [diff] [blame] | 59 | // Extracts resource_id out of edit url. |
| 60 | std::string ExtractResourceIdFromUrl(const GURL& url); |
| 61 | |
[email protected] | 7b69787 | 2013-05-23 16:39:18 | [diff] [blame] | 62 | // If |resource_id| is in the old resource ID format used by WAPI, converts it |
| 63 | // into the new format. |
| 64 | std::string CanonicalizeResourceId(const std::string& resource_id); |
| 65 | |
[email protected] | 09f0c3b | 2013-10-21 05:29:41 | [diff] [blame] | 66 | // Returns a ResourceIdCanonicalizer which returns the argument. |
| 67 | ResourceIdCanonicalizer GetIdentityResourceIdCanonicalizer(); |
| 68 | |
[email protected] | 71cdf6b | 2013-08-01 19:20:29 | [diff] [blame] | 69 | // Note: Following constants and a function are used to support GetShareUrl on |
| 70 | // Drive API v2. Unfortunately, there is no support on Drive API v2, so we need |
| 71 | // to fall back to GData WAPI for the GetShareUrl. Thus, these are shared by |
| 72 | // both GDataWapiService and DriveAPIService. |
| 73 | // TODO(hidehiko): Remove these from here, when Drive API v2 supports |
| 74 | // GetShareUrl. |
| 75 | |
| 76 | // OAuth2 scopes for the GData WAPI. |
| 77 | extern const char kDocsListScope[]; |
| 78 | extern const char kDriveAppsScope[]; |
| 79 | |
| 80 | // Extracts an url to the sharing dialog and returns it via |callback|. If |
| 81 | // the share url doesn't exist, then an empty url is returned. |
| 82 | void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback, |
| 83 | google_apis::GDataErrorCode error, |
| 84 | scoped_ptr<base::Value> value); |
| 85 | |
[email protected] | 8445510e | 2013-09-13 13:27:07 | [diff] [blame] | 86 | // Converts AccountMetadata to AboutResource. |
| 87 | // Here, |root_resource_id| is also needed, as it is contained by AboutResource |
| 88 | // but not by AccountMetadata. |
| 89 | scoped_ptr<google_apis::AboutResource> |
| 90 | ConvertAccountMetadataToAboutResource( |
| 91 | const google_apis::AccountMetadata& account_metadata, |
| 92 | const std::string& root_resource_id); |
| 93 | |
| 94 | // Converts AccountMetadata to AppList. |
| 95 | scoped_ptr<google_apis::AppList> |
| 96 | ConvertAccountMetadataToAppList( |
| 97 | const google_apis::AccountMetadata& account_metadata); |
| 98 | |
[email protected] | b3c66ee | 2013-09-09 11:31:18 | [diff] [blame] | 99 | // Converts ResourceEntry to FileResource. |
| 100 | scoped_ptr<google_apis::FileResource> |
| 101 | ConvertResourceEntryToFileResource(const google_apis::ResourceEntry& entry); |
| 102 | |
[email protected] | 8445510e | 2013-09-13 13:27:07 | [diff] [blame] | 103 | // Returns the GData WAPI's Kind of the FileResource. |
| 104 | google_apis::DriveEntryKind GetKind( |
| 105 | const google_apis::FileResource& file_resource); |
| 106 | |
[email protected] | ed4a72a | 2013-09-12 11:11:50 | [diff] [blame] | 107 | // Converts FileResource to ResourceEntry. |
| 108 | scoped_ptr<google_apis::ResourceEntry> |
| 109 | ConvertFileResourceToResourceEntry( |
| 110 | const google_apis::FileResource& file_resource); |
| 111 | |
| 112 | // Converts ChangeResource to ResourceEntry. |
| 113 | scoped_ptr<google_apis::ResourceEntry> |
| 114 | ConvertChangeResourceToResourceEntry( |
| 115 | const google_apis::ChangeResource& change_resource); |
| 116 | |
| 117 | // Converts FileList to ResourceList. |
| 118 | scoped_ptr<google_apis::ResourceList> |
| 119 | ConvertFileListToResourceList(const google_apis::FileList& file_list); |
| 120 | |
| 121 | // Converts ChangeList to ResourceList. |
| 122 | scoped_ptr<google_apis::ResourceList> |
| 123 | ConvertChangeListToResourceList(const google_apis::ChangeList& change_list); |
| 124 | |
[email protected] | 4749427 | 2013-11-07 12:36:40 | [diff] [blame^] | 125 | // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|, |
| 126 | // or an empty string if an error is found. |
| 127 | std::string GetMd5Digest(const base::FilePath& file_path); |
| 128 | |
[email protected] | 615c417 | 2013-09-04 16:31:41 | [diff] [blame] | 129 | // The resource ID for the root directory for WAPI is defined in the spec: |
| 130 | // https://developers.google.com/google-apps/documents-list/ |
| 131 | extern const char kWapiRootDirectoryResourceId[]; |
| 132 | |
[email protected] | 002aec6a | 2013-04-18 15:14:38 | [diff] [blame] | 133 | } // namespace util |
| 134 | } // namespace drive |
[email protected] | 583d46f | 2012-11-15 03:22:32 | [diff] [blame] | 135 | |
[email protected] | 2b9e59a7 | 2013-06-20 03:32:16 | [diff] [blame] | 136 | #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ |