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_DOWNLOAD_FILE_IMPL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_
8 #include "content/browser/download/download_file.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/time/time.h"
14 #include "base/timer/timer.h"
15 #include "content/browser/byte_stream.h"
16 #include "content/browser/download/base_file.h"
17 #include "content/browser/download/rate_estimator.h"
18 #include "content/public/browser/download_save_info.h"
19 #include "net/base/net_log.h"
22 class ByteStreamReader
;
23 class DownloadDestinationObserver
;
24 class DownloadManager
;
25 struct DownloadCreateInfo
;
27 class CONTENT_EXPORT DownloadFileImpl
: virtual public DownloadFile
{
29 // Takes ownership of the object pointed to by |request_handle|.
30 // |bound_net_log| will be used for logging the download file's events.
31 // May be constructed on any thread. All methods besides the constructor
32 // (including destruction) must occur on the FILE thread.
34 // Note that the DownloadFileImpl automatically reads from the passed in
35 // stream, and sends updates and status of those reads to the
36 // DownloadDestinationObserver.
38 scoped_ptr
<DownloadSaveInfo
> save_info
,
39 const base::FilePath
& default_downloads_directory
,
41 const GURL
& referrer_url
,
43 scoped_ptr
<ByteStreamReader
> stream
,
44 const net::BoundNetLog
& bound_net_log
,
45 base::WeakPtr
<DownloadDestinationObserver
> observer
);
47 virtual ~DownloadFileImpl();
49 // DownloadFile functions.
50 virtual void Initialize(const InitializeCallback
& callback
) OVERRIDE
;
51 virtual void RenameAndUniquify(
52 const base::FilePath
& full_path
,
53 const RenameCompletionCallback
& callback
) OVERRIDE
;
54 virtual void RenameAndAnnotate(
55 const base::FilePath
& full_path
,
56 const RenameCompletionCallback
& callback
) OVERRIDE
;
57 virtual void Detach() OVERRIDE
;
58 virtual void Cancel() OVERRIDE
;
59 virtual base::FilePath
FullPath() const OVERRIDE
;
60 virtual bool InProgress() const OVERRIDE
;
61 virtual int64
CurrentSpeed() const OVERRIDE
;
62 virtual bool GetHash(std::string
* hash
) OVERRIDE
;
63 virtual std::string
GetHashState() OVERRIDE
;
64 virtual void SetClientGuid(const std::string
& guid
) OVERRIDE
;
67 // For test class overrides.
68 virtual DownloadInterruptReason
AppendDataToFile(
69 const char* data
, size_t data_len
);
72 // Send an update on our progress.
75 // Called when there's some activity on stream_reader_ that needs to be
79 // The base file instance.
82 // The default directory for creating the download file.
83 base::FilePath default_download_directory_
;
85 // The stream through which data comes.
86 // TODO(rdsmith): Move this into BaseFile; requires using the same
87 // stream semantics in SavePackage. Alternatively, replace SaveFile
88 // with DownloadFile and get rid of BaseFile.
89 scoped_ptr
<ByteStreamReader
> stream_reader_
;
91 // Used to trigger progress updates.
92 scoped_ptr
<base::RepeatingTimer
<DownloadFileImpl
> > update_timer_
;
96 base::TimeDelta disk_writes_time_
;
97 base::TimeTicks download_start_
;
98 RateEstimator rate_estimator_
;
100 net::BoundNetLog bound_net_log_
;
102 base::WeakPtr
<DownloadDestinationObserver
> observer_
;
104 base::WeakPtrFactory
<DownloadFileImpl
> weak_factory_
;
106 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl
);
109 } // namespace content
111 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_