blob: 3bef862a73865718a33f1df75006c842ddc6234e [file] [log] [blame]
[email protected]583d46fb2012-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]583d46fb2012-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"
11#include "chrome/browser/google_apis/drive_common_callbacks.h"
[email protected]8445510e2013-09-13 13:27:0712#include "chrome/browser/google_apis/drive_entry_kinds.h"
[email protected]71cdf6b2013-08-01 19:20:2913#include "chrome/browser/google_apis/gdata_errorcode.h"
14
[email protected]f5aed022013-05-21 03:39:1015class GURL;
16
[email protected]71cdf6b2013-08-01 19:20:2917namespace base {
18class Value;
19} // namespace base
20
[email protected]b3c66ee2013-09-09 11:31:1821namespace google_apis {
[email protected]8445510e2013-09-13 13:27:0722class AccountMetadata;
23class AppIcon;
24class AppList;
25class AppResource;
[email protected]ed4a72a2013-09-12 11:11:5026class ChangeList;
27class ChangeResource;
[email protected]8445510e2013-09-13 13:27:0728class DriveAppIcon;
[email protected]ed4a72a2013-09-12 11:11:5029class FileList;
[email protected]b3c66ee2013-09-09 11:31:1830class FileResource;
[email protected]8445510e2013-09-13 13:27:0731class InstalledApp;
[email protected]b3c66ee2013-09-09 11:31:1832class ResourceEntry;
[email protected]ed4a72a2013-09-12 11:11:5033class ResourceList;
[email protected]b3c66ee2013-09-09 11:31:1834} // namespace google_apis
35
[email protected]e50af7652013-06-20 06:39:3136namespace drive {
[email protected]583d46fb2012-11-15 03:22:3237namespace util {
38
39// Returns true if Drive v2 API is enabled via commandline switch.
40bool IsDriveV2ApiEnabled();
41
[email protected]002aec6a2013-04-18 15:14:3842// Escapes ' to \' in the |str|. This is designed to use for string value of
43// search parameter on Drive API v2.
44// See also: https://developers.google.com/drive/search-parameters
45std::string EscapeQueryStringValue(const std::string& str);
46
[email protected]c39ee69e2013-04-19 12:57:2147// Parses the query, and builds a search query for Drive API v2.
48// This only supports:
49// Regular query (e.g. dog => fullText contains 'dog')
50// Conjunctions
51// (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat')
52// Exclusion query (e.g. -cat => not fullText contains 'cat').
53// Quoted query (e.g. "dog cat" => fullText contains 'dog cat').
54// See also: https://developers.google.com/drive/search-parameters
55std::string TranslateQuery(const std::string& original_query);
56
[email protected]f5aed022013-05-21 03:39:1057// Extracts resource_id out of edit url.
58std::string ExtractResourceIdFromUrl(const GURL& url);
59
[email protected]7b697872013-05-23 16:39:1860// If |resource_id| is in the old resource ID format used by WAPI, converts it
61// into the new format.
62std::string CanonicalizeResourceId(const std::string& resource_id);
63
[email protected]71cdf6b2013-08-01 19:20:2964// Note: Following constants and a function are used to support GetShareUrl on
65// Drive API v2. Unfortunately, there is no support on Drive API v2, so we need
66// to fall back to GData WAPI for the GetShareUrl. Thus, these are shared by
67// both GDataWapiService and DriveAPIService.
68// TODO(hidehiko): Remove these from here, when Drive API v2 supports
69// GetShareUrl.
70
71// OAuth2 scopes for the GData WAPI.
72extern const char kDocsListScope[];
73extern const char kDriveAppsScope[];
74
75// Extracts an url to the sharing dialog and returns it via |callback|. If
76// the share url doesn't exist, then an empty url is returned.
77void ParseShareUrlAndRun(const google_apis::GetShareUrlCallback& callback,
78 google_apis::GDataErrorCode error,
79 scoped_ptr<base::Value> value);
80
[email protected]8445510e2013-09-13 13:27:0781// Converts AccountMetadata to AboutResource.
82// Here, |root_resource_id| is also needed, as it is contained by AboutResource
83// but not by AccountMetadata.
84scoped_ptr<google_apis::AboutResource>
85ConvertAccountMetadataToAboutResource(
86 const google_apis::AccountMetadata& account_metadata,
87 const std::string& root_resource_id);
88
89// Converts AccountMetadata to AppList.
90scoped_ptr<google_apis::AppList>
91ConvertAccountMetadataToAppList(
92 const google_apis::AccountMetadata& account_metadata);
93
[email protected]b3c66ee2013-09-09 11:31:1894// Converts ResourceEntry to FileResource.
95scoped_ptr<google_apis::FileResource>
96ConvertResourceEntryToFileResource(const google_apis::ResourceEntry& entry);
97
[email protected]8445510e2013-09-13 13:27:0798// Returns the GData WAPI's Kind of the FileResource.
99google_apis::DriveEntryKind GetKind(
100 const google_apis::FileResource& file_resource);
101
[email protected]ed4a72a2013-09-12 11:11:50102// Converts FileResource to ResourceEntry.
103scoped_ptr<google_apis::ResourceEntry>
104ConvertFileResourceToResourceEntry(
105 const google_apis::FileResource& file_resource);
106
107// Converts ChangeResource to ResourceEntry.
108scoped_ptr<google_apis::ResourceEntry>
109ConvertChangeResourceToResourceEntry(
110 const google_apis::ChangeResource& change_resource);
111
112// Converts FileList to ResourceList.
113scoped_ptr<google_apis::ResourceList>
114ConvertFileListToResourceList(const google_apis::FileList& file_list);
115
116// Converts ChangeList to ResourceList.
117scoped_ptr<google_apis::ResourceList>
118ConvertChangeListToResourceList(const google_apis::ChangeList& change_list);
119
[email protected]615c4172013-09-04 16:31:41120// The resource ID for the root directory for WAPI is defined in the spec:
121// https://developers.google.com/google-apps/documents-list/
122extern const char kWapiRootDirectoryResourceId[];
123
[email protected]002aec6a2013-04-18 15:14:38124} // namespace util
125} // namespace drive
[email protected]583d46fb2012-11-15 03:22:32126
[email protected]2b9e59a72013-06-20 03:32:16127#endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_