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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_
6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_
8 #include "base/basictypes.h"
9 #include "base/files/file_path.h"
10 #include "content/browser/download/save_types.h"
11 #include "content/public/common/referrer.h"
17 // One SaveItem per save file. This is the model class that stores all the
18 // state for one save file.
28 SaveItem(const GURL
& url
,
29 const Referrer
& referrer
,
31 SaveFileCreateInfo::SaveFileSource save_source
);
37 // Received a new chunk of data.
38 void Update(int64 bytes_so_far
);
40 // Cancel saving item.
43 // Saving operation completed.
44 void Finish(int64 size
, bool is_success
);
46 // Rough percent complete, -1 means we don't know (since we didn't receive a
48 int PercentComplete() const;
50 // Update path for SaveItem, the actual file is renamed on the file thread.
51 void Rename(const base::FilePath
& full_path
);
53 void SetSaveId(int32 save_id
);
55 void SetTotalBytes(int64 total_bytes
);
58 SaveState
state() const { return state_
; }
59 const base::FilePath
& full_path() const { return full_path_
; }
60 const base::FilePath
& file_name() const { return file_name_
; }
61 const GURL
& url() const { return url_
; }
62 const Referrer
& referrer() const { return referrer_
; }
63 int64
total_bytes() const { return total_bytes_
; }
64 int64
received_bytes() const { return received_bytes_
; }
65 int32
save_id() const { return save_id_
; }
66 bool has_final_name() const { return has_final_name_
; }
67 bool success() const { return is_success_
; }
68 SaveFileCreateInfo::SaveFileSource
save_source() const {
71 SavePackage
* package() const { return package_
; }
74 // Internal helper for maintaining consistent received and total sizes.
75 void UpdateSize(int64 size
);
77 // Request ID assigned by the ResourceDispatcherHost.
80 // Full path to the save item file.
81 base::FilePath full_path_
;
83 // Short display version of the file.
84 base::FilePath file_name_
;
86 // The URL for this save item.
90 // Total bytes expected.
93 // Current received bytes.
94 int64 received_bytes_
;
96 // The current state of this save item.
99 // Specifies if this name is a final or not.
100 bool has_final_name_
;
102 // Flag indicates whether SaveItem has error while in saving process.
105 SaveFileCreateInfo::SaveFileSource save_source_
;
107 // Our owning object.
108 SavePackage
* package_
;
110 DISALLOW_COPY_AND_ASSIGN(SaveItem
);
113 } // namespace content
115 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_ITEM_H_