Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / drive / drive_api_util.h
blob3dbdfb714411a44f489e25f2786ff0851a0fc54a
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_
8 #include <string>
10 #include "base/md5.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "google_apis/drive/drive_api_error_codes.h"
13 #include "google_apis/drive/drive_common_callbacks.h"
15 class GURL;
17 namespace base {
18 class FilePath;
19 class Value;
20 } // namespace base
22 namespace google_apis {
23 class ChangeList;
24 class ChangeResource;
25 class FileList;
26 class FileResource;
27 class ResourceEntry;
28 } // namespace google_apis
30 namespace net {
31 class IOBuffer;
32 } // namespace net
34 namespace storage {
35 class FileStreamReader;
36 } // namespace storage
38 namespace drive {
39 namespace util {
41 // Google Apps MIME types:
42 const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document";
43 const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing";
44 const char kGooglePresentationMimeType[] =
45 "application/vnd.google-apps.presentation";
46 const char kGoogleSpreadsheetMimeType[] =
47 "application/vnd.google-apps.spreadsheet";
48 const char kGoogleTableMimeType[] = "application/vnd.google-apps.table";
49 const char kGoogleFormMimeType[] = "application/vnd.google-apps.form";
50 const char kGoogleMapMimeType[] = "application/vnd.google-apps.map";
51 const char kDriveFolderMimeType[] = "application/vnd.google-apps.folder";
53 // Escapes ' to \' in the |str|. This is designed to use for string value of
54 // search parameter on Drive API v2.
55 // See also: https://developers.google.com/drive/search-parameters
56 std::string EscapeQueryStringValue(const std::string& str);
58 // Parses the query, and builds a search query for Drive API v2.
59 // This only supports:
60 // Regular query (e.g. dog => fullText contains 'dog')
61 // Conjunctions
62 // (e.g. dog cat => fullText contains 'dog' and fullText contains 'cat')
63 // Exclusion query (e.g. -cat => not fullText contains 'cat').
64 // Quoted query (e.g. "dog cat" => fullText contains 'dog cat').
65 // See also: https://developers.google.com/drive/search-parameters
66 std::string TranslateQuery(const std::string& original_query);
68 // If |resource_id| is in the old resource ID format used by WAPI, converts it
69 // into the new format.
70 std::string CanonicalizeResourceId(const std::string& resource_id);
72 // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|,
73 // or an empty string if an error is found.
74 std::string GetMd5Digest(const base::FilePath& file_path);
76 // Computes the (base-16 encoded) MD5 digest of data extracted from a file
77 // stream.
78 class FileStreamMd5Digester {
79 public:
80 typedef base::Callback<void(const std::string&)> ResultCallback;
82 FileStreamMd5Digester();
83 ~FileStreamMd5Digester();
85 // Computes an MD5 digest of data read from the given |streamReader|. The
86 // work occurs asynchronously, and the resulting hash is returned via the
87 // |callback|. If an error occurs, |callback| is called with an empty string.
88 // Only one stream can be processed at a time by each digester. Do not call
89 // GetMd5Digest before the results of a previous call have been returned.
90 void GetMd5Digest(scoped_ptr<storage::FileStreamReader> stream_reader,
91 const ResultCallback& callback);
93 private:
94 // Kicks off a read of the next chunk from the stream.
95 void ReadNextChunk(const ResultCallback& callback);
96 // Handles the incoming chunk of data from a stream read.
97 void OnChunkRead(const ResultCallback& callback, int bytes_read);
99 // Maximum chunk size for read operations.
100 scoped_ptr<storage::FileStreamReader> reader_;
101 scoped_refptr<net::IOBuffer> buffer_;
102 base::MD5Context md5_context_;
104 DISALLOW_COPY_AND_ASSIGN(FileStreamMd5Digester);
107 // Returns preferred file extension for hosted documents which have given mime
108 // type.
109 std::string GetHostedDocumentExtension(const std::string& mime_type);
111 // Returns true if the given mime type is corresponding to one of known hosted
112 // document types.
113 bool IsKnownHostedDocumentMimeType(const std::string& mime_type);
115 // Returns true if the given file path has an extension corresponding to one of
116 // hosted document types.
117 bool HasHostedDocumentExtension(const base::FilePath& path);
119 } // namespace util
120 } // namespace drive
122 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_