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: | |
| 80 FileStreamMd5Digester(); | |
| 81 ~FileStreamMd5Digester(); | |
| 82 // Computes an MD5 digest of data read from the given |streamReader|. The | |
|
mtomasz
2015/01/31 04:53:12
nit: \n\n after destructor?
Ben Kwa
2015/02/02 22:22:11
Done.
| |
| 83 // work occurs asynchronously, and the resulting hash is returned via the | |
| 84 // |callback|. If an error occurs, |callback| is called with an empty string. | |
| 85 // Only one stream can be processed at a time by each digester. Do not call | |
| 86 // GetMd5Digest before the results of a previous call have been returned. | |
| 87 void GetMd5Digest(scoped_ptr<storage::FileStreamReader> streamReader, | |
|
mtomasz
2015/01/31 04:53:12
nit: stream_reader
Ben Kwa
2015/02/02 22:22:11
Done.
| |
| 88 const base::Callback<void(const std::string&)>& callback); | |
|
mtomasz
2015/01/31 04:53:12
nit: How about typedefing the callback within File
Ben Kwa
2015/02/02 22:22:11
Done.
| |
| 89 | |
| 90 private: | |
| 91 // Kicks off a read of the next chunk from the stream. | |
| 92 void readNextChunk(); | |
|
mtomasz
2015/01/31 04:53:12
nit: read -> Read
Ben Kwa
2015/02/02 22:22:12
Done.
| |
| 93 // Handles the incoming chunk of data from a stream read. | |
| 94 void OnChunkRead(int result); | |
| 95 | |
| 96 private: | |
| 97 // Maximum chunk size for read operations. | |
| 98 static const int kBufferSize_ = 512 * 1024; // 512 kB. | |
|
mtomasz
2015/01/31 04:53:12
nit: Also, do we need it to be in the header file?
mtomasz
2015/01/31 04:53:12
nit: Isn't the chunk too large? We're doing it on
mtomasz
2015/01/31 04:53:12
nit: This may be new if initializing static member
Ben Kwa
2015/02/02 22:22:11
So... this happens on the IO thread now. I asked
Ben Kwa
2015/02/02 22:22:12
I figured that keeping this constant scoped within
Ben Kwa
2015/02/02 22:22:12
The style guides don't explicitly say anything abo
| |
| 99 scoped_ptr<storage::FileStreamReader> reader_; | |
| 100 base::Callback<void(const std::string&)> callback_; | |
| 101 scoped_refptr<net::IOBuffer> buffer_; | |
| 102 base::MD5Context md5Context_; | |
|
mtomasz
2015/01/31 04:53:12
nit: camelCase -> is_not_allowed
Ben Kwa
2015/02/02 22:22:12
Done.
| |
| 103 | |
| 104 base::WeakPtrFactory<FileStreamMd5Digester> weak_ptr_factory_; | |
| 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 |