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.
4
5#ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
6#define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
7
8#include <string>
9
10#include "base/memory/scoped_ptr.h"
11#include "google_apis/drive/drive_common_callbacks.h"
12#include "google_apis/drive/gdata_errorcode.h"
13
14class GURL;
15
16namespace base {
17class FilePath;
18class Value;
19}  // namespace base
20
21namespace google_apis {
22class ChangeList;
23class ChangeResource;
24class FileList;
25class FileResource;
26class ResourceEntry;
27class ResourceList;
28}  // namespace google_apis
29
30namespace drive {
31namespace util {
32
33// 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";
42const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
43
44// 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
49// 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
59// Extracts resource_id out of edit url.
60std::string ExtractResourceIdFromUrl(const GURL& url);
61
62// 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
66// Converts FileResource to ResourceEntry.
67scoped_ptr<google_apis::ResourceEntry>
68ConvertFileResourceToResourceEntry(
69    const google_apis::FileResource& file_resource);
70
71// Converts ChangeResource to ResourceEntry.
72scoped_ptr<google_apis::ResourceEntry>
73ConvertChangeResourceToResourceEntry(
74    const google_apis::ChangeResource& change_resource);
75
76// Converts FileList to ResourceList.
77scoped_ptr<google_apis::ResourceList>
78ConvertFileListToResourceList(const google_apis::FileList& file_list);
79
80// Converts ChangeList to ResourceList.
81scoped_ptr<google_apis::ResourceList>
82ConvertChangeListToResourceList(const google_apis::ChangeList& change_list);
83
84// Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
85// or an empty string if an error is found.
86std::string GetMd5Digest(const base::FilePath& file_path);
87
88// Returns preferred file extension for hosted documents which have given mime
89// type.
90std::string GetHostedDocumentExtension(const std::string& mime_type);
91
92// Returns true if the given mime type is corresponding to one of known hosted
93// document types.
94bool IsKnownHostedDocumentMimeType(const std::string& mime_type);
95
96// Returns true if the given file path has an extension corresponding to one of
97// hosted document types.
98bool HasHostedDocumentExtension(const base::FilePath& path);
99
100}  // namespace util
101}  // namespace drive
102
103#endif  // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
104