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

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: Merged with trunk Created 9 years, 1 month 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
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/pickle.h"
15 #include "content/browser/power_save_blocker.h" 16 #include "content/browser/power_save_blocker.h"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
18 #include "net/base/file_stream.h" 19 #include "net/base/file_stream.h"
19 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
20 21
22 class Pickle;
Randy Smith (Not in Mondays) 2011/11/21 02:10:17 I don't think Pickle belongs in the interface to *
ahendrickson 2011/11/21 20:34:47 Done.
23
21 namespace crypto { 24 namespace crypto {
22 class SecureHash; 25 class SecureHash;
23 } 26 }
24 namespace net { 27 namespace net {
25 class FileStream; 28 class FileStream;
26 } 29 }
27 30
28 // File being downloaded and saved to disk. This is a base class 31 // File being downloaded and saved to disk. This is a base class
29 // for DownloadFile and SaveFile, which keep more state information. 32 // for DownloadFile and SaveFile, which keep more state information.
30 class CONTENT_EXPORT BaseFile { 33 class CONTENT_EXPORT BaseFile {
31 public: 34 public:
32 BaseFile(const FilePath& full_path, 35 BaseFile(const FilePath& full_path,
33 const GURL& source_url, 36 const GURL& source_url,
34 const GURL& referrer_url, 37 const GURL& referrer_url,
35 int64 received_bytes, 38 int64 received_bytes,
39 const Pickle& hash_state,
36 const linked_ptr<net::FileStream>& file_stream); 40 const linked_ptr<net::FileStream>& file_stream);
37 virtual ~BaseFile(); 41 virtual ~BaseFile();
38 42
39 // If calculate_hash is true, sha256 hash will be calculated. 43 // If calculate_hash is true, sha256 hash will be calculated.
40 // 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.
41 net::Error Initialize(bool calculate_hash); 45 net::Error Initialize(bool calculate_hash);
42 46
43 // Write a new chunk of data to the file. 47 // Write a new chunk of data to the file.
44 // Returns net::OK on success (all bytes written to the file), 48 // Returns net::OK on success (all bytes written to the file),
45 // or a network error code on failure. 49 // 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. 62 // Indicate that the download has finished. No new data will be received.
59 void Finish(); 63 void Finish();
60 64
61 // Informs the OS that this file came from the internet. 65 // Informs the OS that this file came from the internet.
62 void AnnotateWithSourceInformation(); 66 void AnnotateWithSourceInformation();
63 67
64 FilePath full_path() const { return full_path_; } 68 FilePath full_path() const { return full_path_; }
65 bool in_progress() const { return file_stream_ != NULL; } 69 bool in_progress() const { return file_stream_ != NULL; }
66 int64 bytes_so_far() const { return bytes_so_far_; } 70 int64 bytes_so_far() const { return bytes_so_far_; }
67 71
68 // Set |hash| with sha256 digest for the file. 72 // Fills |hash| with the sha256 digest for the file. May be partial.
69 // Returns true if digest is successfully calculated. 73 // Returns true if digest is successfully calculated.
70 virtual bool GetSha256Hash(std::string* hash); 74 virtual bool GetSha256Hash(std::string* hash);
71 75
76 // Retrieves the current (intermediate) state of the hash and puts it in
77 // |hash_state|.
78 virtual bool GetSha256HashState(Pickle* hash_state);
79
80 // Resets the current state of the hash to the contents of |hash_state|.
81 virtual bool SetSha256HashState(Pickle* hash_state);
82
72 // Returns true if the given hash is considered empty. An empty hash is 83 // 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 84 // a string of size kSha256HashLen that contains only zeros (initial value
74 // for the hash). 85 // for the hash).
75 static bool IsEmptySha256Hash(const std::string& hash); 86 static bool IsEmptySha256Hash(const std::string& hash);
76 87
77 virtual std::string DebugString() const; 88 virtual std::string DebugString() const;
78 89
79 protected: 90 protected:
80 virtual void CreateFileStream(); // For testing. 91 virtual void CreateFileStream(); // For testing.
81 // Returns net::OK on success, or a network error code on failure. 92 // 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. 118 // RAII handle to keep the system from sleeping while we're downloading.
108 PowerSaveBlocker power_save_blocker_; 119 PowerSaveBlocker power_save_blocker_;
109 120
110 // Indicates if sha256 hash should be calculated for the file. 121 // Indicates if sha256 hash should be calculated for the file.
111 bool calculate_hash_; 122 bool calculate_hash_;
112 123
113 // Used to calculate sha256 hash for the file when calculate_hash_ 124 // Used to calculate sha256 hash for the file when calculate_hash_
114 // is set. 125 // is set.
115 scoped_ptr<crypto::SecureHash> secure_hash_; 126 scoped_ptr<crypto::SecureHash> secure_hash_;
116 127
128 // The hash state is stored here on creation.
129 Pickle initial_hash_state_;
130
117 unsigned char sha256_hash_[kSha256HashLen]; 131 unsigned char sha256_hash_[kSha256HashLen];
118 132
119 // Indicates that this class no longer owns the associated file, and so 133 // Indicates that this class no longer owns the associated file, and so
120 // won't delete it on destruction. 134 // won't delete it on destruction.
121 bool detached_; 135 bool detached_;
122 136
123 DISALLOW_COPY_AND_ASSIGN(BaseFile); 137 DISALLOW_COPY_AND_ASSIGN(BaseFile);
124 }; 138 };
125 139
126 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_ 140 #endif // CONTENT_BROWSER_DOWNLOAD_BASE_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698