blob: fc562ce9d365e7f8e697d619a7f612bc30cdb005 [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
lukasza8acc4eb2015-07-20 20:57:205#ifndef COMPONENTS_DRIVE_DRIVE_API_UTIL_H_
6#define COMPONENTS_DRIVE_DRIVE_API_UTIL_H_
[email protected]583d46fb2012-11-15 03:22:327
dchengf42750232016-04-12 04:12:278#include <memory>
[email protected]002aec6a2013-04-18 15:14:389#include <string>
10
tzikd5346b592017-05-02 16:48:1811#include "base/callback.h"
tzikd5346b592017-05-02 16:48:1812#include "components/drive/file_errors.h"
satorux1e04b422015-01-29 07:50:5313#include "google_apis/drive/drive_api_error_codes.h"
[email protected]e196bef32013-12-03 05:33:1314#include "google_apis/drive/drive_common_callbacks.h"
[email protected]71cdf6b2013-08-01 19:20:2915
[email protected]71cdf6b2013-08-01 19:20:2916namespace base {
hashimoto246e4a82015-04-17 07:44:4917class CancellationFlag;
Brett Wilsonabbb9602017-09-11 23:26:3918class Location;
[email protected]47494272013-11-07 12:36:4019class FilePath;
tzikd5346b592017-05-02 16:48:1820class TaskRunner;
[email protected]71cdf6b2013-08-01 19:20:2921} // namespace base
22
[email protected]e50af7652013-06-20 06:39:3123namespace drive {
[email protected]583d46fb2012-11-15 03:22:3224namespace util {
25
[email protected]19f13a22014-04-23 08:19:0226// Google Apps MIME types:
27const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document";
28const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing";
29const char kGooglePresentationMimeType[] =
30 "application/vnd.google-apps.presentation";
31const char kGoogleSpreadsheetMimeType[] =
32 "application/vnd.google-apps.spreadsheet";
33const char kGoogleTableMimeType[] = "application/vnd.google-apps.table";
34const char kGoogleFormMimeType[] = "application/vnd.google-apps.form";
fukino22708902014-11-04 09:00:0735const char kGoogleMapMimeType[] = "application/vnd.google-apps.map";
fukino672cd5a92016-07-01 01:35:0236const char kGoogleSiteMimeType[] = "application/vnd.google-apps.site";
[email protected]19f13a22014-04-23 08:19:0237const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
38
[email protected]002aec6a2013-04-18 15:14:3839// Escapes ' to \' in the |str|. This is designed to use for string value of
40// search parameter on Drive API v2.
41// See also: https://developers.google.com/drive/search-parameters
42std::string EscapeQueryStringValue(const std::string& str);
43
[email protected]c39ee69e2013-04-19 12:57:2144// Parses the query, and builds a search query for Drive API v2.
45// This only supports:
46// Regular query (e.g. dog => fullText contains 'dog')
47// Conjunctions
48// (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat')
49// Exclusion query (e.g. -cat => not fullText contains 'cat').
50// Quoted query (e.g. "dog cat" => fullText contains 'dog cat').
51// See also: https://developers.google.com/drive/search-parameters
52std::string TranslateQuery(const std::string& original_query);
53
[email protected]7b697872013-05-23 16:39:1854// If |resource_id| is in the old resource ID format used by WAPI, converts it
55// into the new format.
56std::string CanonicalizeResourceId(const std::string& resource_id);
57
[email protected]47494272013-11-07 12:36:4058// Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
59// or an empty string if an error is found.
hashimoto246e4a82015-04-17 07:44:4960std::string GetMd5Digest(const base::FilePath& file_path,
61 const base::CancellationFlag* cancellation_flag);
[email protected]47494272013-11-07 12:36:4062
[email protected]51ed7bd42014-07-14 13:58:2263// Returns preferred file extension for hosted documents which have given mime
[email protected]4979eaf02014-07-31 11:34:2064// type.
[email protected]51ed7bd42014-07-14 13:58:2265std::string GetHostedDocumentExtension(const std::string& mime_type);
66
[email protected]4979eaf02014-07-31 11:34:2067// Returns true if the given mime type is corresponding to one of known hosted
68// document types.
69bool IsKnownHostedDocumentMimeType(const std::string& mime_type);
[email protected]51ed7bd42014-07-14 13:58:2270
[email protected]d8d92532014-07-25 10:06:2671// Returns true if the given file path has an extension corresponding to one of
72// hosted document types.
73bool HasHostedDocumentExtension(const base::FilePath& path);
[email protected]51ed7bd42014-07-14 13:58:2274
tzikd5346b592017-05-02 16:48:1875// Runs |task| on |task_runner|, then runs |reply| on the original thread with
76// the resulting error code.
77void RunAsyncTask(base::TaskRunner* task_runner,
Brett Wilsonabbb9602017-09-11 23:26:3978 const base::Location& from_here,
tzikd5346b592017-05-02 16:48:1879 base::OnceCallback<FileError()> task,
80 base::OnceCallback<void(FileError)> reply);
81
[email protected]002aec6a2013-04-18 15:14:3882} // namespace util
83} // namespace drive
[email protected]583d46fb2012-11-15 03:22:3284
lukasza8acc4eb2015-07-20 20:57:2085#endif // COMPONENTS_DRIVE_DRIVE_API_UTIL_H_