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: |
| 80 typedef base::Callback<void(const std::string&)> ResultCallback; |
| 81 |
| 82 FileStreamMd5Digester(); |
| 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 // Kicks off a read of the next chunk from the stream. |
| 95 void ReadNextChunk(); |
| 96 // Handles the incoming chunk of data from a stream read. |
| 97 void OnChunkRead(int result); |
| 98 |
| 99 // Maximum chunk size for read operations. |
| 100 scoped_ptr<storage::FileStreamReader> reader_; |
| 101 ResultCallback callback_; |
| 102 scoped_refptr<net::IOBuffer> buffer_; |
| 103 base::MD5Context md5_context_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(FileStreamMd5Digester); |
| 106 }; |
| 107 |
67 // Returns preferred file extension for hosted documents which have given mime | 108 // Returns preferred file extension for hosted documents which have given mime |
68 // type. | 109 // type. |
69 std::string GetHostedDocumentExtension(const std::string& mime_type); | 110 std::string GetHostedDocumentExtension(const std::string& mime_type); |
70 | 111 |
71 // Returns true if the given mime type is corresponding to one of known hosted | 112 // Returns true if the given mime type is corresponding to one of known hosted |
72 // document types. | 113 // document types. |
73 bool IsKnownHostedDocumentMimeType(const std::string& mime_type); | 114 bool IsKnownHostedDocumentMimeType(const std::string& mime_type); |
74 | 115 |
75 // Returns true if the given file path has an extension corresponding to one of | 116 // Returns true if the given file path has an extension corresponding to one of |
76 // hosted document types. | 117 // hosted document types. |
77 bool HasHostedDocumentExtension(const base::FilePath& path); | 118 bool HasHostedDocumentExtension(const base::FilePath& path); |
78 | 119 |
79 } // namespace util | 120 } // namespace util |
80 } // namespace drive | 121 } // namespace drive |
81 | 122 |
82 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ | 123 #endif // CHROME_BROWSER_DRIVE_DRIVE_API_UTIL_H_ |
OLD | NEW |