blob: 008328b0c1f51fd5240343eee009ffcd0be62fce [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"
[email protected]e196bef32013-12-03 05:33:1311#include "google_apis/drive/drive_common_callbacks.h"
[email protected]e196bef32013-12-03 05:33:1312#include "google_apis/drive/gdata_errorcode.h"
[email protected]71cdf6b2013-08-01 19:20:2913
[email protected]f5aed022013-05-21 03:39:1014class GURL;
15
[email protected]71cdf6b2013-08-01 19:20:2916namespace base {
[email protected]47494272013-11-07 12:36:4017class FilePath;
[email protected]71cdf6b2013-08-01 19:20:2918class Value;
19} // namespace base
20
[email protected]b3c66ee2013-09-09 11:31:1821namespace google_apis {
[email protected]ed4a72a2013-09-12 11:11:5022class ChangeList;
23class ChangeResource;
24class FileList;
[email protected]b3c66ee2013-09-09 11:31:1825class FileResource;
26class ResourceEntry;
[email protected]ed4a72a2013-09-12 11:11:5027class ResourceList;
[email protected]b3c66ee2013-09-09 11:31:1828} // namespace google_apis
29
[email protected]e50af7652013-06-20 06:39:3130namespace drive {
[email protected]583d46fb2012-11-15 03:22:3231namespace util {
32
[email protected]19f13a22014-04-23 08:19:0233// Google Apps MIME types:
34const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document";
35const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing";
36const char kGooglePresentationMimeType[] =
37 "application/vnd.google-apps.presentation";
38const char kGoogleSpreadsheetMimeType[] =
39 "application/vnd.google-apps.spreadsheet";
40const char kGoogleTableMimeType[] = "application/vnd.google-apps.table";
41const char kGoogleFormMimeType[] = "application/vnd.google-apps.form";
fukino22708902014-11-04 09:00:0742const char kGoogleMapMimeType[] = "application/vnd.google-apps.map";
[email protected]19f13a22014-04-23 08:19:0243const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
44
[email protected]002aec6a2013-04-18 15:14:3845// Escapes ' to \' in the |str|. This is designed to use for string value of
46// search parameter on Drive API v2.
47// See also: https://developers.google.com/drive/search-parameters
48std::string EscapeQueryStringValue(const std::string& str);
49
[email protected]c39ee69e2013-04-19 12:57:2150// Parses the query, and builds a search query for Drive API v2.
51// This only supports:
52// Regular query (e.g. dog => fullText contains 'dog')
53// Conjunctions
54// (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat')
55// Exclusion query (e.g. -cat => not fullText contains 'cat').
56// Quoted query (e.g. "dog cat" => fullText contains 'dog cat').
57// See also: https://developers.google.com/drive/search-parameters
58std::string TranslateQuery(const std::string& original_query);
59
[email protected]f5aed022013-05-21 03:39:1060// Extracts resource_id out of edit url.
61std::string ExtractResourceIdFromUrl(const GURL& url);
62
[email protected]7b697872013-05-23 16:39:1863// If |resource_id| is in the old resource ID format used by WAPI, converts it
64// into the new format.
65std::string CanonicalizeResourceId(const std::string& resource_id);
66
[email protected]ed4a72a2013-09-12 11:11:5067// Converts FileResource to ResourceEntry.
68scoped_ptr<google_apis::ResourceEntry>
69ConvertFileResourceToResourceEntry(
70 const google_apis::FileResource& file_resource);
71
72// Converts ChangeResource to ResourceEntry.
73scoped_ptr<google_apis::ResourceEntry>
74ConvertChangeResourceToResourceEntry(
75 const google_apis::ChangeResource& change_resource);
76
77// Converts FileList to ResourceList.
78scoped_ptr<google_apis::ResourceList>
79ConvertFileListToResourceList(const google_apis::FileList& file_list);
80
81// Converts ChangeList to ResourceList.
82scoped_ptr<google_apis::ResourceList>
83ConvertChangeListToResourceList(const google_apis::ChangeList& change_list);
84
[email protected]47494272013-11-07 12:36:4085// Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
86// or an empty string if an error is found.
87std::string GetMd5Digest(const base::FilePath& file_path);
88
[email protected]51ed7bd42014-07-14 13:58:2289// Returns preferred file extension for hosted documents which have given mime
[email protected]4979eaf02014-07-31 11:34:2090// type.
[email protected]51ed7bd42014-07-14 13:58:2291std::string GetHostedDocumentExtension(const std::string& mime_type);
92
[email protected]4979eaf02014-07-31 11:34:2093// Returns true if the given mime type is corresponding to one of known hosted
94// document types.
95bool IsKnownHostedDocumentMimeType(const std::string& mime_type);
[email protected]51ed7bd42014-07-14 13:58:2296
[email protected]d8d92532014-07-25 10:06:2697// Returns true if the given file path has an extension corresponding to one of
98// hosted document types.
99bool HasHostedDocumentExtension(const base::FilePath& path);
[email protected]51ed7bd42014-07-14 13:58:22100
[email protected]002aec6a2013-04-18 15:14:38101} // namespace util
102} // namespace drive
[email protected]583d46fb2012-11-15 03:22:32103
[email protected]2b9e59a72013-06-20 03:32:16104#endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_