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_DOWNLOAD_ITEM_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/timer.h" | 16 #include "base/timer.h" |
| 17 #include "content/browser/download/download_net_log_parameters.h" |
17 #include "content/browser/download/download_request_handle.h" | 18 #include "content/browser/download/download_request_handle.h" |
18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
19 #include "content/public/browser/download_id.h" | 20 #include "content/public/browser/download_id.h" |
20 #include "content/public/browser/download_item.h" | 21 #include "content/public/browser/download_item.h" |
21 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_log.h" |
23 | 25 |
24 | 26 |
25 // See download_item.h for usage. | 27 // See download_item.h for usage. |
26 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem { | 28 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem { |
27 public: | 29 public: |
28 // Delegate is defined in DownloadItemImpl (rather than DownloadItem) | 30 // Delegate is defined in DownloadItemImpl (rather than DownloadItem) |
29 // as it's relevant to the class implementation (class methods need to | 31 // as it's relevant to the class implementation (class methods need to |
30 // call into it) and doesn't have anything to do with its interface. | 32 // call into it) and doesn't have anything to do with its interface. |
31 // Despite this, the delegate methods take DownloadItems as arguments | 33 // Despite this, the delegate methods take DownloadItems as arguments |
32 // (rather than DownloadItemImpls) so that classes that inherit from it | 34 // (rather than DownloadItemImpls) so that classes that inherit from it |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 private: | 76 private: |
75 // For "Outlives attached DownloadItemImpl" invariant assertion. | 77 // For "Outlives attached DownloadItemImpl" invariant assertion. |
76 int count_; | 78 int count_; |
77 }; | 79 }; |
78 | 80 |
79 // Note that it is the responsibility of the caller to ensure that a | 81 // Note that it is the responsibility of the caller to ensure that a |
80 // DownloadItemImpl::Delegate passed to a DownloadItemImpl constructor | 82 // DownloadItemImpl::Delegate passed to a DownloadItemImpl constructor |
81 // outlives the DownloadItemImpl. | 83 // outlives the DownloadItemImpl. |
82 | 84 |
83 // Constructing from persistent store: | 85 // Constructing from persistent store: |
| 86 // |bound_net_log| is constructed externally for our use. |
84 DownloadItemImpl(Delegate* delegate, | 87 DownloadItemImpl(Delegate* delegate, |
85 content::DownloadId download_id, | 88 content::DownloadId download_id, |
86 const DownloadPersistentStoreInfo& info); | 89 const DownloadPersistentStoreInfo& info, |
| 90 const net::BoundNetLog& bound_net_log); |
87 | 91 |
88 // Constructing for a regular download. | 92 // Constructing for a regular download. |
89 // Takes ownership of the object pointed to by |request_handle|. | 93 // Takes ownership of the object pointed to by |request_handle|. |
| 94 // |bound_net_log| is constructed externally for our use. |
90 DownloadItemImpl(Delegate* delegate, | 95 DownloadItemImpl(Delegate* delegate, |
91 const DownloadCreateInfo& info, | 96 const DownloadCreateInfo& info, |
92 DownloadRequestHandleInterface* request_handle, | 97 DownloadRequestHandleInterface* request_handle, |
93 bool is_otr); | 98 bool is_otr, |
| 99 const net::BoundNetLog& bound_net_log); |
94 | 100 |
95 // Constructing for the "Save Page As..." feature: | 101 // Constructing for the "Save Page As..." feature: |
| 102 // |bound_net_log| is constructed externally for our use. |
96 DownloadItemImpl(Delegate* delegate, | 103 DownloadItemImpl(Delegate* delegate, |
97 const FilePath& path, | 104 const FilePath& path, |
98 const GURL& url, | 105 const GURL& url, |
99 bool is_otr, | 106 bool is_otr, |
100 content::DownloadId download_id); | 107 content::DownloadId download_id, |
| 108 const net::BoundNetLog& bound_net_log); |
101 | 109 |
102 virtual ~DownloadItemImpl(); | 110 virtual ~DownloadItemImpl(); |
103 | 111 |
104 // Overridden from DownloadItem. | 112 // Overridden from DownloadItem. |
105 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; | 113 virtual void AddObserver(DownloadItem::Observer* observer) OVERRIDE; |
106 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; | 114 virtual void RemoveObserver(DownloadItem::Observer* observer) OVERRIDE; |
107 virtual void UpdateObservers() OVERRIDE; | 115 virtual void UpdateObservers() OVERRIDE; |
108 virtual bool CanShowInFolder() OVERRIDE; | 116 virtual bool CanShowInFolder() OVERRIDE; |
109 virtual bool CanOpenDownload() OVERRIDE; | 117 virtual bool CanOpenDownload() OVERRIDE; |
110 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; | 118 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 virtual bool NeedsRename() const OVERRIDE; | 205 virtual bool NeedsRename() const OVERRIDE; |
198 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; | 206 virtual void OffThreadCancel(DownloadFileManager* file_manager) OVERRIDE; |
199 virtual std::string DebugString(bool verbose) const OVERRIDE; | 207 virtual std::string DebugString(bool verbose) const OVERRIDE; |
200 virtual void MockDownloadOpenForTesting() OVERRIDE; | 208 virtual void MockDownloadOpenForTesting() OVERRIDE; |
201 virtual ExternalData* GetExternalData(const void* key) OVERRIDE; | 209 virtual ExternalData* GetExternalData(const void* key) OVERRIDE; |
202 virtual void SetExternalData(const void* key, ExternalData* data) OVERRIDE; | 210 virtual void SetExternalData(const void* key, ExternalData* data) OVERRIDE; |
203 | 211 |
204 private: | 212 private: |
205 // Construction common to all constructors. |active| should be true for new | 213 // Construction common to all constructors. |active| should be true for new |
206 // downloads and false for downloads from the history. | 214 // downloads and false for downloads from the history. |
207 void Init(bool active); | 215 // |download_type| indicates to the net log system what kind of download |
| 216 // this is. |
| 217 void Init(bool active, download_net_logs::DownloadType download_type); |
208 | 218 |
209 // Internal helper for maintaining consistent received and total sizes, and | 219 // Internal helper for maintaining consistent received and total sizes, and |
210 // hash state. | 220 // hash state. |
211 void UpdateProgress(int64 bytes_so_far, const std::string& hash_state); | 221 void UpdateProgress(int64 bytes_so_far, const std::string& hash_state); |
212 | 222 |
213 // Internal helper for maintaining consistent received and total sizes, and | 223 // Internal helper for maintaining consistent received and total sizes, and |
214 // setting the final hash. | 224 // setting the final hash. |
215 // Should only be called from |OnAllDataSaved|. | 225 // Should only be called from |OnAllDataSaved|. |
216 void ProgressComplete(int64 bytes_so_far, | 226 void ProgressComplete(int64 bytes_so_far, |
217 const std::string& final_hash); | 227 const std::string& final_hash); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 // only. | 374 // only. |
365 bool open_enabled_; | 375 bool open_enabled_; |
366 | 376 |
367 // Did the delegate delay calling Complete on this download? | 377 // Did the delegate delay calling Complete on this download? |
368 bool delegate_delayed_complete_; | 378 bool delegate_delayed_complete_; |
369 | 379 |
370 // External Data storage. All objects in the store | 380 // External Data storage. All objects in the store |
371 // are owned by the DownloadItemImpl. | 381 // are owned by the DownloadItemImpl. |
372 std::map<const void*, ExternalData*> external_data_map_; | 382 std::map<const void*, ExternalData*> external_data_map_; |
373 | 383 |
| 384 // Net log to use for this download. |
| 385 const net::BoundNetLog bound_net_log_; |
| 386 |
374 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); | 387 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); |
375 }; | 388 }; |
376 | 389 |
377 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ | 390 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ |
OLD | NEW |