Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ | 5 #ifndef CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ |
| 6 #define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ | 6 #define CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/md5.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "google_apis/drive/drive_api_error_codes.h" | 12 #include "google_apis/drive/drive_api_error_codes.h" |
| 12 #include "google_apis/drive/drive_common_callbacks.h" | 13 #include "google_apis/drive/drive_common_callbacks.h" |
| 13 | 14 |
| 14 class GURL; | 15 class GURL; |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 class FilePath; | 18 class FilePath; |
| 18 class Value; | 19 class Value; |
| 19 } // namespace base | 20 } // namespace base |
| 20 | 21 |
| 21 namespace google_apis { | 22 namespace google_apis { |
| 22 class ChangeList; | 23 class ChangeList; |
| 23 class ChangeResource; | 24 class ChangeResource; |
| 24 class FileList; | 25 class FileList; |
| 25 class FileResource; | 26 class FileResource; |
| 26 class ResourceEntry; | 27 class ResourceEntry; |
| 27 } // namespace google_apis | 28 } // namespace google_apis |
| 28 | 29 |
| 30 namespace net { | |
| 31 class IOBuffer; | |
| 32 } // namespace net | |
| 33 | |
| 34 namespace storage { | |
| 35 class FileStreamReader; | |
| 36 } // namespace storage | |
| 37 | |
| 29 namespace drive { | 38 namespace drive { |
| 30 namespace util { | 39 namespace util { |
| 31 | 40 |
| 32 // Google Apps MIME types: | 41 // Google Apps MIME types: |
| 33 const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document"; | 42 const char kGoogleDocumentMimeType[] = "application/vnd.google-apps.document"; |
| 34 const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing"; | 43 const char kGoogleDrawingMimeType[] = "application/vnd.google-apps.drawing"; |
| 35 const char kGooglePresentationMimeType[] = | 44 const char kGooglePresentationMimeType[] = |
| 36 "application/vnd.google-apps.presentation"; | 45 "application/vnd.google-apps.presentation"; |
| 37 const char kGoogleSpreadsheetMimeType[] = | 46 const char kGoogleSpreadsheetMimeType[] = |
| 38 "application/vnd.google-apps.spreadsheet"; | 47 "application/vnd.google-apps.spreadsheet"; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 57 std::string TranslateQuery(const std::string& original_query); | 66 std::string TranslateQuery(const std::string& original_query); |
| 58 | 67 |
| 59 // If |resource_id| is in the old resource ID format used by WAPI, converts it | 68 // If |resource_id| is in the old resource ID format used by WAPI, converts it |
| 60 // into the new format. | 69 // into the new format. |
| 61 std::string CanonicalizeResourceId(const std::string& resource_id); | 70 std::string CanonicalizeResourceId(const std::string& resource_id); |
| 62 | 71 |
| 63 // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|, | 72 // Returns the (base-16 encoded) MD5 digest of the file content at |file_path|, |
| 64 // or an empty string if an error is found. | 73 // or an empty string if an error is found. |
| 65 std::string GetMd5Digest(const base::FilePath& file_path); | 74 std::string GetMd5Digest(const base::FilePath& file_path); |
| 66 | 75 |
| 76 // Computes the (base-16 encoded) MD5 digest of data extracted from a file | |
| 77 // stream. | |
| 78 class FileStreamMd5Digester | |
| 79 : public base::RefCountedThreadSafe<FileStreamMd5Digester> { | |
| 80 public: | |
| 81 typedef base::Callback<void(const std::string&)> ResultCallback; | |
| 82 | |
| 83 FileStreamMd5Digester(); | |
| 84 | |
| 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); | |
| 92 | |
| 93 private: | |
| 94 // Private for RefCountedThreadSafe. | |
| 95 ~FileStreamMd5Digester(); | |
| 96 | |
| 97 // Kicks off a read of the next chunk from the stream. | |
| 98 void ReadNextChunk(); | |
| 99 // Handles the incoming chunk of data from a stream read. | |
| 100 void OnChunkRead(int result); | |
| 101 | |
| 102 // Maximum chunk size for read operations. | |
| 103 static const int kBufferSize_ = 512 * 1024; // 512 kB. | |
|
mtomasz
2015/02/02 23:47:08
nit: Yeah, I'd suggest to move it to an anonymous
Ben Kwa
2015/02/03 16:32:19
Done.
| |
| 104 scoped_ptr<storage::FileStreamReader> reader_; | |
| 105 ResultCallback callback_; | |
| 106 scoped_refptr<net::IOBuffer> buffer_; | |
| 107 base::MD5Context md5_context_; | |
| 108 | |
| 109 friend class base::RefCountedThreadSafe<FileStreamMd5Digester>; | |
| 110 DISALLOW_COPY_AND_ASSIGN(FileStreamMd5Digester); | |
| 111 }; | |
| 112 | |
| 67 // Returns preferred file extension for hosted documents which have given mime | 113 // Returns preferred file extension for hosted documents which have given mime |
| 68 // type. | 114 // type. |
| 69 std::string GetHostedDocumentExtension(const std::string& mime_type); | 115 std::string GetHostedDocumentExtension(const std::string& mime_type); |
| 70 | 116 |
| 71 // Returns true if the given mime type is corresponding to one of known hosted | 117 // Returns true if the given mime type is corresponding to one of known hosted |
| 72 // document types. | 118 // document types. |
| 73 bool IsKnownHostedDocumentMimeType(const std::string& mime_type); | 119 bool IsKnownHostedDocumentMimeType(const std::string& mime_type); |
| 74 | 120 |
| 75 // Returns true if the given file path has an extension corresponding to one of | 121 // Returns true if the given file path has an extension corresponding to one of |
| 76 // hosted document types. | 122 // hosted document types. |
| 77 bool HasHostedDocumentExtension(const base::FilePath& path); | 123 bool HasHostedDocumentExtension(const base::FilePath& path); |
| 78 | 124 |
| 79 } // namespace util | 125 } // namespace util |
| 80 } // namespace drive | 126 } // namespace drive |
| 81 | 127 |
| 82 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ | 128 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ |
| OLD | NEW |