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 COMPONENTS_DRIVE_DRIVE_API_UTIL_H_
6 #define COMPONENTS_DRIVE_DRIVE_API_UTIL_H_
7 
8 #include <string>
9 
10 namespace base {
11 class AtomicFlag;
12 class FilePath;
13 }  // namespace base
14 
15 namespace drive {
16 namespace util {
17 
18 // Google Apps MIME types:
19 const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document";
20 const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing";
21 const char kGooglePresentationMimeType[] =
22     "application/vnd.google-apps.presentation";
23 const char kGoogleSpreadsheetMimeType[] =
24     "application/vnd.google-apps.spreadsheet";
25 const char kGoogleTableMimeType[] = "application/vnd.google-apps.table";
26 const char kGoogleFormMimeType[] = "application/vnd.google-apps.form";
27 const char kGoogleMapMimeType[] = "application/vnd.google-apps.map";
28 const char kGoogleSiteMimeType[] = "application/vnd.google-apps.site";
29 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
30 
31 // Escapes ' to \' in the |str|. This is designed to use for string value of
32 // search parameter on Drive API v2.
33 // See also: https://developers.google.com/drive/search-parameters
34 std::string EscapeQueryStringValue(const std::string& str);
35 
36 // Parses the query, and builds a search query for Drive API v2.
37 // This only supports:
38 //   Regular query (e.g. dog => fullText contains 'dog')
39 //   Conjunctions
40 //     (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat')
41 //   Exclusion query (e.g. -cat => not fullText contains 'cat').
42 //   Quoted query (e.g. "dog cat" => fullText contains 'dog cat').
43 // See also: https://developers.google.com/drive/search-parameters
44 std::string TranslateQuery(const std::string& original_query);
45 
46 // If |resource_id| is in the old resource ID format used by WAPI, converts it
47 // into the new format.
48 std::string CanonicalizeResourceId(const std::string& resource_id);
49 
50 // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
51 // or an empty string if an error is found.
52 std::string GetMd5Digest(const base::FilePath& file_path,
53                          const base::AtomicFlag* cancellation_flag);
54 
55 // Returns true if the given mime type is corresponding to one of known hosted
56 // document types.
57 bool IsKnownHostedDocumentMimeType(const std::string& mime_type);
58 
59 // Returns true if the given file path has an extension corresponding to one of
60 // hosted document types.
61 bool HasHostedDocumentExtension(const base::FilePath& path);
62 
63 }  // namespace util
64 }  // namespace drive
65 
66 #endif  // COMPONENTS_DRIVE_DRIVE_API_UTIL_H_
67