OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 bool in_progress() const { return file_stream_ != NULL; } | 58 bool in_progress() const { return file_stream_ != NULL; } |
59 int64 bytes_so_far() const { return bytes_so_far_; } | 59 int64 bytes_so_far() const { return bytes_so_far_; } |
60 | 60 |
61 // Set |hash| with sha256 digest for the file. | 61 // Set |hash| with sha256 digest for the file. |
62 // Returns true if digest is successfully calculated. | 62 // Returns true if digest is successfully calculated. |
63 virtual bool GetSha256Hash(std::string* hash); | 63 virtual bool GetSha256Hash(std::string* hash); |
64 | 64 |
65 virtual std::string DebugString() const; | 65 virtual std::string DebugString() const; |
66 | 66 |
67 protected: | 67 protected: |
| 68 virtual void CreateFileStream(); // For testing. |
68 bool Open(); | 69 bool Open(); |
69 void Close(); | 70 void Close(); |
70 | 71 |
71 // Full path to the file including the file name. | 72 // Full path to the file including the file name. |
72 FilePath full_path_; | 73 FilePath full_path_; |
73 | 74 |
74 private: | 75 private: |
| 76 friend class BaseFileTest; |
| 77 friend class DownloadFileWithMockStream; |
| 78 |
75 static const size_t kSha256HashLen = 32; | 79 static const size_t kSha256HashLen = 32; |
76 | 80 |
77 // Source URL for the file being downloaded. | 81 // Source URL for the file being downloaded. |
78 GURL source_url_; | 82 GURL source_url_; |
79 | 83 |
80 // The URL where the download was initiated. | 84 // The URL where the download was initiated. |
81 GURL referrer_url_; | 85 GURL referrer_url_; |
82 | 86 |
83 // OS file stream for writing | 87 // OS file stream for writing |
84 linked_ptr<net::FileStream> file_stream_; | 88 linked_ptr<net::FileStream> file_stream_; |
(...skipping 14 matching lines...) Expand all Loading... |
99 unsigned char sha256_hash_[kSha256HashLen]; | 103 unsigned char sha256_hash_[kSha256HashLen]; |
100 | 104 |
101 // Indicates that this class no longer owns the associated file, and so | 105 // Indicates that this class no longer owns the associated file, and so |
102 // won't delete it on destruction. | 106 // won't delete it on destruction. |
103 bool detached_; | 107 bool detached_; |
104 | 108 |
105 DISALLOW_COPY_AND_ASSIGN(BaseFile); | 109 DISALLOW_COPY_AND_ASSIGN(BaseFile); |
106 }; | 110 }; |
107 | 111 |
108 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ | 112 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ |
OLD | NEW |