Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: content/browser/download/base_file.h

Issue 8404049: Added member data to classes to support download resumption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DownloadSaveInfo::offset is now int64. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
26 } 26 }
27 27
28 // File being downloaded and saved to disk. This is a base class 28 // File being downloaded and saved to disk. This is a base class
29 // for DownloadFile and SaveFile, which keep more state information. 29 // for DownloadFile and SaveFile, which keep more state information.
30 class CONTENT_EXPORT BaseFile { 30 class CONTENT_EXPORT BaseFile {
31 public: 31 public:
32 BaseFile(const FilePath& full_path, 32 BaseFile(const FilePath& full_path,
33 const GURL& source_url, 33 const GURL& source_url,
34 const GURL& referrer_url, 34 const GURL& referrer_url,
35 int64 received_bytes, 35 int64 received_bytes,
36 const std::string& hash_state,
36 const linked_ptr<net::FileStream>& file_stream); 37 const linked_ptr<net::FileStream>& file_stream);
37 virtual ~BaseFile(); 38 virtual ~BaseFile();
38 39
39 // If calculate_hash is true, sha256 hash will be calculated. 40 // If calculate_hash is true, sha256 hash will be calculated.
40 // Returns net::OK on success, or a network error code on failure. 41 // Returns net::OK on success, or a network error code on failure.
41 net::Error Initialize(bool calculate_hash); 42 net::Error Initialize(bool calculate_hash);
42 43
43 // Write a new chunk of data to the file. 44 // Write a new chunk of data to the file.
44 // Returns net::OK on success (all bytes written to the file), 45 // Returns net::OK on success (all bytes written to the file),
45 // or a network error code on failure. 46 // or a network error code on failure.
(...skipping 12 matching lines...) Expand all
58 // Indicate that the download has finished. No new data will be received. 59 // Indicate that the download has finished. No new data will be received.
59 void Finish(); 60 void Finish();
60 61
61 // Informs the OS that this file came from the internet. 62 // Informs the OS that this file came from the internet.
62 void AnnotateWithSourceInformation(); 63 void AnnotateWithSourceInformation();
63 64
64 FilePath full_path() const { return full_path_; } 65 FilePath full_path() const { return full_path_; }
65 bool in_progress() const { return file_stream_ != NULL; } 66 bool in_progress() const { return file_stream_ != NULL; }
66 int64 bytes_so_far() const { return bytes_so_far_; } 67 int64 bytes_so_far() const { return bytes_so_far_; }
67 68
68 // Set |hash| with sha256 digest for the file. 69 // Fills |hash| with the sha256 digest for the file.
69 // Returns true if digest is successfully calculated. 70 // Returns true if digest is successfully calculated.
70 virtual bool GetSha256Hash(std::string* hash); 71 virtual bool GetSha256Hash(std::string* hash);
71 72
73 // Returns the current (intermediate) state of the hash as a byte string.
74 virtual std::string GetSha256HashState();
75
76 // Resets the current state of the hash to the contents of |hash_state_bytes|.
77 virtual bool SetSha256HashState(const std::string& hash_state_bytes);
78
72 // Returns true if the given hash is considered empty. An empty hash is 79 // Returns true if the given hash is considered empty. An empty hash is
73 // a string of size kSha256HashLen that contains only zeros (initial value 80 // a string of size kSha256HashLen that contains only zeros (initial value
74 // for the hash). 81 // for the hash).
75 static bool IsEmptySha256Hash(const std::string& hash); 82 static bool IsEmptySha256Hash(const std::string& hash);
76 83
77 virtual std::string DebugString() const; 84 virtual std::string DebugString() const;
78 85
79 protected: 86 protected:
80 virtual void CreateFileStream(); // For testing. 87 virtual void CreateFileStream(); // For testing.
81 // Returns net::OK on success, or a network error code on failure. 88 // Returns net::OK on success, or a network error code on failure.
(...skipping 25 matching lines...) Expand all
107 // RAII handle to keep the system from sleeping while we're downloading. 114 // RAII handle to keep the system from sleeping while we're downloading.
108 PowerSaveBlocker power_save_blocker_; 115 PowerSaveBlocker power_save_blocker_;
109 116
110 // Indicates if sha256 hash should be calculated for the file. 117 // Indicates if sha256 hash should be calculated for the file.
111 bool calculate_hash_; 118 bool calculate_hash_;
112 119
113 // Used to calculate sha256 hash for the file when calculate_hash_ 120 // Used to calculate sha256 hash for the file when calculate_hash_
114 // is set. 121 // is set.
115 scoped_ptr<crypto::SecureHash> secure_hash_; 122 scoped_ptr<crypto::SecureHash> secure_hash_;
116 123
124 // The hash state is stored here on creation.
125 std::string initial_hash_state_;
126
117 unsigned char sha256_hash_[kSha256HashLen]; 127 unsigned char sha256_hash_[kSha256HashLen];
118 128
119 // Indicates that this class no longer owns the associated file, and so 129 // Indicates that this class no longer owns the associated file, and so
120 // won't delete it on destruction. 130 // won't delete it on destruction.
121 bool detached_; 131 bool detached_;
122 132
123 DISALLOW_COPY_AND_ASSIGN(BaseFile); 133 DISALLOW_COPY_AND_ASSIGN(BaseFile);
124 }; 134 };
125 135
126 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ 136 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698