OLD | NEW |
1 // Copyright (c) 2011 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 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 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "content/browser/power_save_blocker.h" | 16 #include "content/browser/power_save_blocker.h" |
17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 #include "net/base/file_stream.h" | 19 #include "net/base/file_stream.h" |
20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/net_log.h" |
21 | 22 |
22 namespace crypto { | 23 namespace crypto { |
23 class SecureHash; | 24 class SecureHash; |
24 } | 25 } |
25 namespace net { | 26 namespace net { |
26 class FileStream; | 27 class FileStream; |
27 } | 28 } |
28 | 29 |
29 // File being downloaded and saved to disk. This is a base class | 30 // File being downloaded and saved to disk. This is a base class |
30 // for DownloadFile and SaveFile, which keep more state information. | 31 // for DownloadFile and SaveFile, which keep more state information. |
31 class CONTENT_EXPORT BaseFile { | 32 class CONTENT_EXPORT BaseFile { |
32 public: | 33 public: |
33 BaseFile(const FilePath& full_path, | 34 BaseFile(const FilePath& full_path, |
34 const GURL& source_url, | 35 const GURL& source_url, |
35 const GURL& referrer_url, | 36 const GURL& referrer_url, |
36 int64 received_bytes, | 37 int64 received_bytes, |
37 bool calculate_hash, | 38 bool calculate_hash, |
38 const std::string& hash_state, | 39 const std::string& hash_state, |
39 const linked_ptr<net::FileStream>& file_stream); | 40 const linked_ptr<net::FileStream>& file_stream, |
| 41 const net::BoundNetLog& bound_net_log); |
40 virtual ~BaseFile(); | 42 virtual ~BaseFile(); |
41 | 43 |
42 // Returns net::OK on success, or a network error code on failure. | 44 // Returns net::OK on success, or a network error code on failure. |
43 net::Error Initialize(); | 45 net::Error Initialize(); |
44 | 46 |
45 // Write a new chunk of data to the file. | 47 // Write a new chunk of data to the file. |
46 // Returns net::OK on success (all bytes written to the file), | 48 // Returns net::OK on success (all bytes written to the file), |
47 // or a network error code on failure. | 49 // or a network error code on failure. |
48 net::Error AppendDataToFile(const char* data, size_t data_len); | 50 net::Error AppendDataToFile(const char* data, size_t data_len); |
49 | 51 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 private: | 98 private: |
97 friend class BaseFileTest; | 99 friend class BaseFileTest; |
98 FRIEND_TEST_ALL_PREFIXES(BaseFileTest, IsEmptyHash); | 100 FRIEND_TEST_ALL_PREFIXES(BaseFileTest, IsEmptyHash); |
99 | 101 |
100 // Split out from CurrentSpeed to enable testing. | 102 // Split out from CurrentSpeed to enable testing. |
101 int64 CurrentSpeedAtTime(base::TimeTicks current_time) const; | 103 int64 CurrentSpeedAtTime(base::TimeTicks current_time) const; |
102 | 104 |
103 // Resets the current state of the hash to the contents of |hash_state_bytes|. | 105 // Resets the current state of the hash to the contents of |hash_state_bytes|. |
104 virtual bool SetHashState(const std::string& hash_state_bytes); | 106 virtual bool SetHashState(const std::string& hash_state_bytes); |
105 | 107 |
| 108 net::Error AbortOpen(net::Error error); |
| 109 |
106 static const size_t kSha256HashLen = 32; | 110 static const size_t kSha256HashLen = 32; |
107 static const unsigned char kEmptySha256Hash[kSha256HashLen]; | 111 static const unsigned char kEmptySha256Hash[kSha256HashLen]; |
108 | 112 |
109 // Source URL for the file being downloaded. | 113 // Source URL for the file being downloaded. |
110 GURL source_url_; | 114 GURL source_url_; |
111 | 115 |
112 // The URL where the download was initiated. | 116 // The URL where the download was initiated. |
113 GURL referrer_url_; | 117 GURL referrer_url_; |
114 | 118 |
115 // OS file stream for writing | 119 // OS file stream for writing |
(...skipping 14 matching lines...) Expand all Loading... |
130 // Used to calculate hash for the file when calculate_hash_ | 134 // Used to calculate hash for the file when calculate_hash_ |
131 // is set. | 135 // is set. |
132 scoped_ptr<crypto::SecureHash> secure_hash_; | 136 scoped_ptr<crypto::SecureHash> secure_hash_; |
133 | 137 |
134 unsigned char sha256_hash_[kSha256HashLen]; | 138 unsigned char sha256_hash_[kSha256HashLen]; |
135 | 139 |
136 // Indicates that this class no longer owns the associated file, and so | 140 // Indicates that this class no longer owns the associated file, and so |
137 // won't delete it on destruction. | 141 // won't delete it on destruction. |
138 bool detached_; | 142 bool detached_; |
139 | 143 |
| 144 net::BoundNetLog bound_net_log_; |
| 145 |
140 DISALLOW_COPY_AND_ASSIGN(BaseFile); | 146 DISALLOW_COPY_AND_ASSIGN(BaseFile); |
141 }; | 147 }; |
142 | 148 |
143 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ | 149 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ |
OLD | NEW |