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.
5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
6 #define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/drive/drive_service_interface.h"
12 #include "google_apis/drive/drive_common_callbacks.h"
13 #include "google_apis/drive/drive_entry_kinds.h"
14 #include "google_apis/drive/gdata_errorcode.h"
23 namespace google_apis {
24 class AccountMetadata;
36 } // namespace google_apis
41 // Escapes ' to \' in the |str|. This is designed to use for string value of
42 // search parameter on Drive API v2.
43 // See also: https://developers.google.com/drive/search-parameters
44 std::string EscapeQueryStringValue(const std::string& str);
46 // Parses the query, and builds a search query for Drive API v2.
47 // This only supports:
48 // Regular query (e.g. dog => fullText contains 'dog')
50 // (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat')
51 // Exclusion query (e.g. -cat => not fullText contains 'cat').
52 // Quoted query (e.g. "dog cat" => fullText contains 'dog cat').
53 // See also: https://developers.google.com/drive/search-parameters
54 std::string TranslateQuery(const std::string& original_query);
56 // Extracts resource_id out of edit url.
57 std::string ExtractResourceIdFromUrl(const GURL& url);
59 // If |resource_id| is in the old resource ID format used by WAPI, converts it
60 // into the new format.
61 std::string CanonicalizeResourceId(const std::string& resource_id);
63 // Returns a ResourceIdCanonicalizer which returns the argument.
64 ResourceIdCanonicalizer GetIdentityResourceIdCanonicalizer();
66 // Note: Following constants and a function are used to support GetShareUrl on
67 // Drive API v2. Unfortunately, there is no support on Drive API v2, so we need
68 // to fall back to GData WAPI for the GetShareUrl. Thus, these are shared by
69 // both GDataWapiService and DriveAPIService.
70 // TODO(hidehiko): Remove these from here, when Drive API v2 supports
73 // OAuth2 scopes for the GData WAPI.
74 extern const char kDocsListScope[];
75 extern const char kDriveAppsScope[];
77 // Extracts an url to the sharing dialog and returns it via |callback|. If
78 // the share url doesn't exist, then an empty url is returned.
79 void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback,
80 google_apis::GDataErrorCode error,
81 scoped_ptr<base::Value> value);
83 // Converts AccountMetadata to AboutResource.
84 // Here, |root_resource_id| is also needed, as it is contained by AboutResource
85 // but not by AccountMetadata.
86 scoped_ptr<google_apis::AboutResource>
87 ConvertAccountMetadataToAboutResource(
88 const google_apis::AccountMetadata& account_metadata,
89 const std::string& root_resource_id);
91 // Converts AccountMetadata to AppList.
92 scoped_ptr<google_apis::AppList>
93 ConvertAccountMetadataToAppList(
94 const google_apis::AccountMetadata& account_metadata);
96 // Converts ResourceEntry to FileResource.
97 scoped_ptr<google_apis::FileResource>
98 ConvertResourceEntryToFileResource(const google_apis::ResourceEntry& entry);
100 // Returns the GData WAPI's Kind of the FileResource.
101 google_apis::DriveEntryKind GetKind(
102 const google_apis::FileResource& file_resource);
104 // Converts FileResource to ResourceEntry.
105 scoped_ptr<google_apis::ResourceEntry>
106 ConvertFileResourceToResourceEntry(
107 const google_apis::FileResource& file_resource);
109 // Converts ChangeResource to ResourceEntry.
110 scoped_ptr<google_apis::ResourceEntry>
111 ConvertChangeResourceToResourceEntry(
112 const google_apis::ChangeResource& change_resource);
114 // Converts FileList to ResourceList.
115 scoped_ptr<google_apis::ResourceList>
116 ConvertFileListToResourceList(const google_apis::FileList& file_list);
118 // Converts ChangeList to ResourceList.
119 scoped_ptr<google_apis::ResourceList>
120 ConvertChangeListToResourceList(const google_apis::ChangeList& change_list);
122 // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
123 // or an empty string if an error is found.
124 std::string GetMd5Digest(const base::FilePath& file_path);
126 // The resource ID for the root directory for WAPI is defined in the spec:
127 // https://developers.google.com/google-apps/documents-list/
128 extern const char kWapiRootDirectoryResourceId[];
133 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_