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