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.
5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
6 #define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "google_apis/drive/drive_common_callbacks.h"
12 #include "google_apis/drive/gdata_errorcode.h"
21 namespace google_apis
{
28 } // namespace google_apis
33 // Google Apps MIME types:
34 const char kGoogleDocumentMimeType
[] = "application/vnd.google-apps.document";
35 const char kGoogleDrawingMimeType
[] = "application/vnd.google-apps.drawing";
36 const char kGooglePresentationMimeType
[] =
37 "application/vnd.google-apps.presentation";
38 const char kGoogleSpreadsheetMimeType
[] =
39 "application/vnd.google-apps.spreadsheet";
40 const char kGoogleTableMimeType
[] = "application/vnd.google-apps.table";
41 const char kGoogleFormMimeType
[] = "application/vnd.google-apps.form";
42 const char kGoogleMapMimeType
[] = "application/vnd.google-apps.map";
43 const char kDriveFolderMimeType
[] = "application/vnd.google-apps.folder";
45 // 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
48 std::string
EscapeQueryStringValue(const std::string
& str
);
50 // 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')
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
58 std::string
TranslateQuery(const std::string
& original_query
);
60 // Extracts resource_id out of edit url.
61 std::string
ExtractResourceIdFromUrl(const GURL
& url
);
63 // If |resource_id| is in the old resource ID format used by WAPI, converts it
64 // into the new format.
65 std::string
CanonicalizeResourceId(const std::string
& resource_id
);
67 // Converts FileResource to ResourceEntry.
68 scoped_ptr
<google_apis::ResourceEntry
>
69 ConvertFileResourceToResourceEntry(
70 const google_apis::FileResource
& file_resource
);
72 // Converts ChangeResource to ResourceEntry.
73 scoped_ptr
<google_apis::ResourceEntry
>
74 ConvertChangeResourceToResourceEntry(
75 const google_apis::ChangeResource
& change_resource
);
77 // Converts FileList to ResourceList.
78 scoped_ptr
<google_apis::ResourceList
>
79 ConvertFileListToResourceList(const google_apis::FileList
& file_list
);
81 // Converts ChangeList to ResourceList.
82 scoped_ptr
<google_apis::ResourceList
>
83 ConvertChangeListToResourceList(const google_apis::ChangeList
& change_list
);
85 // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
86 // or an empty string if an error is found.
87 std::string
GetMd5Digest(const base::FilePath
& file_path
);
89 // Returns preferred file extension for hosted documents which have given mime
91 std::string
GetHostedDocumentExtension(const std::string
& mime_type
);
93 // Returns true if the given mime type is corresponding to one of known hosted
95 bool IsKnownHostedDocumentMimeType(const std::string
& mime_type
);
97 // Returns true if the given file path has an extension corresponding to one of
98 // hosted document types.
99 bool HasHostedDocumentExtension(const base::FilePath
& path
);
104 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_