blob: bce1785169fec609ff0ba6b261c5971f791c6bb2 [file] [log] [blame]
[email protected]583d46f2012-11-15 03:22:321// 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]2b9e59a72013-06-20 03:32:165#ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
6#define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
[email protected]583d46f2012-11-15 03:22:327
[email protected]002aec6a2013-04-18 15:14:388#include <string>
9
[email protected]71cdf6b2013-08-01 19:20:2910#include "base/memory/scoped_ptr.h"
[email protected]09f0c3b2013-10-21 05:29:4111#include "chrome/browser/drive/drive_service_interface.h"
[email protected]71cdf6b2013-08-01 19:20:2912#include "chrome/browser/google_apis/drive_common_callbacks.h"
[email protected]8445510e2013-09-13 13:27:0713#include "chrome/browser/google_apis/drive_entry_kinds.h"
[email protected]71cdf6b2013-08-01 19:20:2914#include "chrome/browser/google_apis/gdata_errorcode.h"
15
[email protected]f5aed022013-05-21 03:39:1016class GURL;
17
[email protected]71cdf6b2013-08-01 19:20:2918namespace base {
[email protected]47494272013-11-07 12:36:4019class FilePath;
[email protected]71cdf6b2013-08-01 19:20:2920class Value;
21} // namespace base
22
[email protected]b3c66ee2013-09-09 11:31:1823namespace google_apis {
[email protected]8445510e2013-09-13 13:27:0724class AccountMetadata;
25class AppIcon;
26class AppList;
27class AppResource;
[email protected]ed4a72a2013-09-12 11:11:5028class ChangeList;
29class ChangeResource;
[email protected]8445510e2013-09-13 13:27:0730class DriveAppIcon;
[email protected]ed4a72a2013-09-12 11:11:5031class FileList;
[email protected]b3c66ee2013-09-09 11:31:1832class FileResource;
[email protected]8445510e2013-09-13 13:27:0733class InstalledApp;
[email protected]b3c66ee2013-09-09 11:31:1834class ResourceEntry;
[email protected]ed4a72a2013-09-12 11:11:5035class ResourceList;
[email protected]b3c66ee2013-09-09 11:31:1836} // namespace google_apis
37
[email protected]e50af7652013-06-20 06:39:3138namespace drive {
[email protected]583d46f2012-11-15 03:22:3239namespace util {
40
41// Returns true if Drive v2 API is enabled via commandline switch.
42bool IsDriveV2ApiEnabled();
43
[email protected]002aec6a2013-04-18 15:14:3844// 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
47std::string EscapeQueryStringValue(const std::string& str);
48
[email protected]c39ee69e2013-04-19 12:57:2149// 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
57std::string TranslateQuery(const std::string& original_query);
58
[email protected]f5aed022013-05-21 03:39:1059// Extracts resource_id out of edit url.
60std::string ExtractResourceIdFromUrl(const GURL& url);
61
[email protected]7b697872013-05-23 16:39:1862// If |resource_id| is in the old resource ID format used by WAPI, converts it
63// into the new format.
64std::string CanonicalizeResourceId(const std::string& resource_id);
65
[email protected]09f0c3b2013-10-21 05:29:4166// Returns a ResourceIdCanonicalizer which returns the argument.
67ResourceIdCanonicalizer GetIdentityResourceIdCanonicalizer();
68
[email protected]71cdf6b2013-08-01 19:20:2969// 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.
77extern const char kDocsListScope[];
78extern 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.
82void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback,
83 google_apis::GDataErrorCode error,
84 scoped_ptr<base::Value> value);
85
[email protected]8445510e2013-09-13 13:27:0786// Converts AccountMetadata to AboutResource.
87// Here, |root_resource_id| is also needed, as it is contained by AboutResource
88// but not by AccountMetadata.
89scoped_ptr<google_apis::AboutResource>
90ConvertAccountMetadataToAboutResource(
91 const google_apis::AccountMetadata& account_metadata,
92 const std::string& root_resource_id);
93
94// Converts AccountMetadata to AppList.
95scoped_ptr<google_apis::AppList>
96ConvertAccountMetadataToAppList(
97 const google_apis::AccountMetadata& account_metadata);
98
[email protected]b3c66ee2013-09-09 11:31:1899// Converts ResourceEntry to FileResource.
100scoped_ptr<google_apis::FileResource>
101ConvertResourceEntryToFileResource(const google_apis::ResourceEntry& entry);
102
[email protected]8445510e2013-09-13 13:27:07103// Returns the GData WAPI's Kind of the FileResource.
104google_apis::DriveEntryKind GetKind(
105 const google_apis::FileResource& file_resource);
106
[email protected]ed4a72a2013-09-12 11:11:50107// Converts FileResource to ResourceEntry.
108scoped_ptr<google_apis::ResourceEntry>
109ConvertFileResourceToResourceEntry(
110 const google_apis::FileResource& file_resource);
111
112// Converts ChangeResource to ResourceEntry.
113scoped_ptr<google_apis::ResourceEntry>
114ConvertChangeResourceToResourceEntry(
115 const google_apis::ChangeResource& change_resource);
116
117// Converts FileList to ResourceList.
118scoped_ptr<google_apis::ResourceList>
119ConvertFileListToResourceList(const google_apis::FileList& file_list);
120
121// Converts ChangeList to ResourceList.
122scoped_ptr<google_apis::ResourceList>
123ConvertChangeListToResourceList(const google_apis::ChangeList& change_list);
124
[email protected]47494272013-11-07 12:36:40125// Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
126// or an empty string if an error is found.
127std::string GetMd5Digest(const base::FilePath& file_path);
128
[email protected]615c4172013-09-04 16:31:41129// The resource ID for the root directory for WAPI is defined in the spec:
130// https://developers.google.com/google-apps/documents-list/
131extern const char kWapiRootDirectoryResourceId[];
132
[email protected]002aec6a2013-04-18 15:14:38133} // namespace util
134} // namespace drive
[email protected]583d46f2012-11-15 03:22:32135
[email protected]2b9e59a72013-06-20 03:32:16136#endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_