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

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

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r159248 Created 8 years, 2 months 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) 2012 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 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 18 matching lines...) Expand all
29 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem { 29 class CONTENT_EXPORT DownloadItemImpl : public content::DownloadItem {
30 public: 30 public:
31 // Note that it is the responsibility of the caller to ensure that a 31 // Note that it is the responsibility of the caller to ensure that a
32 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor 32 // DownloadItemImplDelegate passed to a DownloadItemImpl constructor
33 // outlives the DownloadItemImpl. 33 // outlives the DownloadItemImpl.
34 34
35 // Constructing from persistent store: 35 // Constructing from persistent store:
36 // |bound_net_log| is constructed externally for our use. 36 // |bound_net_log| is constructed externally for our use.
37 DownloadItemImpl(DownloadItemImplDelegate* delegate, 37 DownloadItemImpl(DownloadItemImplDelegate* delegate,
38 content::DownloadId download_id, 38 content::DownloadId download_id,
39 const content::DownloadPersistentStoreInfo& info, 39 const FilePath& path,
40 const GURL& url,
41 const GURL& referrer_url,
42 const base::Time& start_time,
43 const base::Time& end_time,
44 int64 received_bytes,
45 int64 total_bytes,
46 DownloadItem::DownloadState state,
47 bool opened,
40 const net::BoundNetLog& bound_net_log); 48 const net::BoundNetLog& bound_net_log);
41 49
42 // Constructing for a regular download. 50 // Constructing for a regular download.
43 // |bound_net_log| is constructed externally for our use. 51 // |bound_net_log| is constructed externally for our use.
44 DownloadItemImpl(DownloadItemImplDelegate* delegate, 52 DownloadItemImpl(DownloadItemImplDelegate* delegate,
45 const DownloadCreateInfo& info, 53 const DownloadCreateInfo& info,
46 scoped_ptr<DownloadRequestHandleInterface> request_handle, 54 scoped_ptr<DownloadRequestHandleInterface> request_handle,
47 const net::BoundNetLog& bound_net_log); 55 const net::BoundNetLog& bound_net_log);
48 56
49 // Constructing for the "Save Page As..." feature: 57 // Constructing for the "Save Page As..." feature:
(...skipping 13 matching lines...) Expand all
63 virtual void UpdateObservers() OVERRIDE; 71 virtual void UpdateObservers() OVERRIDE;
64 virtual void DangerousDownloadValidated() OVERRIDE; 72 virtual void DangerousDownloadValidated() OVERRIDE;
65 virtual void TogglePause() OVERRIDE; 73 virtual void TogglePause() OVERRIDE;
66 virtual void Cancel(bool user_cancel) OVERRIDE; 74 virtual void Cancel(bool user_cancel) OVERRIDE;
67 virtual void Delete(DeleteReason reason) OVERRIDE; 75 virtual void Delete(DeleteReason reason) OVERRIDE;
68 virtual void Remove() OVERRIDE; 76 virtual void Remove() OVERRIDE;
69 virtual void OpenDownload() OVERRIDE; 77 virtual void OpenDownload() OVERRIDE;
70 virtual void ShowDownloadInShell() OVERRIDE; 78 virtual void ShowDownloadInShell() OVERRIDE;
71 virtual int32 GetId() const OVERRIDE; 79 virtual int32 GetId() const OVERRIDE;
72 virtual content::DownloadId GetGlobalId() const OVERRIDE; 80 virtual content::DownloadId GetGlobalId() const OVERRIDE;
73 virtual int64 GetDbHandle() const OVERRIDE;
74 virtual DownloadState GetState() const OVERRIDE; 81 virtual DownloadState GetState() const OVERRIDE;
75 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE; 82 virtual content::DownloadInterruptReason GetLastReason() const OVERRIDE;
76 virtual bool IsPaused() const OVERRIDE; 83 virtual bool IsPaused() const OVERRIDE;
77 virtual bool IsTemporary() const OVERRIDE; 84 virtual bool IsTemporary() const OVERRIDE;
78 virtual bool IsPersisted() const OVERRIDE;
79 virtual bool IsPartialDownload() const OVERRIDE; 85 virtual bool IsPartialDownload() const OVERRIDE;
80 virtual bool IsInProgress() const OVERRIDE; 86 virtual bool IsInProgress() const OVERRIDE;
81 virtual bool IsCancelled() const OVERRIDE; 87 virtual bool IsCancelled() const OVERRIDE;
82 virtual bool IsInterrupted() const OVERRIDE; 88 virtual bool IsInterrupted() const OVERRIDE;
83 virtual bool IsComplete() const OVERRIDE; 89 virtual bool IsComplete() const OVERRIDE;
84 virtual const GURL& GetURL() const OVERRIDE; 90 virtual const GURL& GetURL() const OVERRIDE;
85 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE; 91 virtual const std::vector<GURL>& GetUrlChain() const OVERRIDE;
86 virtual const GURL& GetOriginalUrl() const OVERRIDE; 92 virtual const GURL& GetOriginalUrl() const OVERRIDE;
87 virtual const GURL& GetReferrerUrl() const OVERRIDE; 93 virtual const GURL& GetReferrerUrl() const OVERRIDE;
88 virtual std::string GetSuggestedFilename() const OVERRIDE; 94 virtual std::string GetSuggestedFilename() const OVERRIDE;
(...skipping 25 matching lines...) Expand all
114 virtual int64 GetTotalBytes() const OVERRIDE; 120 virtual int64 GetTotalBytes() const OVERRIDE;
115 virtual int64 GetReceivedBytes() const OVERRIDE; 121 virtual int64 GetReceivedBytes() const OVERRIDE;
116 virtual base::Time GetStartTime() const OVERRIDE; 122 virtual base::Time GetStartTime() const OVERRIDE;
117 virtual base::Time GetEndTime() const OVERRIDE; 123 virtual base::Time GetEndTime() const OVERRIDE;
118 virtual bool CanShowInFolder() OVERRIDE; 124 virtual bool CanShowInFolder() OVERRIDE;
119 virtual bool CanOpenDownload() OVERRIDE; 125 virtual bool CanOpenDownload() OVERRIDE;
120 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE; 126 virtual bool ShouldOpenFileBasedOnExtension() OVERRIDE;
121 virtual bool GetOpenWhenComplete() const OVERRIDE; 127 virtual bool GetOpenWhenComplete() const OVERRIDE;
122 virtual bool GetAutoOpened() OVERRIDE; 128 virtual bool GetAutoOpened() OVERRIDE;
123 virtual bool GetOpened() const OVERRIDE; 129 virtual bool GetOpened() const OVERRIDE;
124 virtual content::DownloadPersistentStoreInfo
125 GetPersistentStoreInfo() const OVERRIDE;
126 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; 130 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
127 virtual content::WebContents* GetWebContents() const OVERRIDE; 131 virtual content::WebContents* GetWebContents() const OVERRIDE;
128 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE; 132 virtual void DelayedDownloadOpened(bool auto_opened) OVERRIDE;
129 virtual void OnContentCheckCompleted( 133 virtual void OnContentCheckCompleted(
130 content::DownloadDangerType danger_type) OVERRIDE; 134 content::DownloadDangerType danger_type) OVERRIDE;
131 virtual void SetOpenWhenComplete(bool open) OVERRIDE; 135 virtual void SetOpenWhenComplete(bool open) OVERRIDE;
132 virtual void SetIsTemporary(bool temporary) OVERRIDE; 136 virtual void SetIsTemporary(bool temporary) OVERRIDE;
133 virtual void SetOpened(bool opened) OVERRIDE; 137 virtual void SetOpened(bool opened) OVERRIDE;
134 virtual void SetDisplayName(const FilePath& name) OVERRIDE; 138 virtual void SetDisplayName(const FilePath& name) OVERRIDE;
135 virtual std::string DebugString(bool verbose) const OVERRIDE; 139 virtual std::string DebugString(bool verbose) const OVERRIDE;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 virtual void UpdateProgress(int64 bytes_so_far, 197 virtual void UpdateProgress(int64 bytes_so_far,
194 int64 bytes_per_sec, 198 int64 bytes_per_sec,
195 const std::string& hash_state); 199 const std::string& hash_state);
196 200
197 virtual void OnAllDataSaved(int64 size, const std::string& final_hash); 201 virtual void OnAllDataSaved(int64 size, const std::string& final_hash);
198 202
199 // Called by SavePackage to display progress when the DownloadItem 203 // Called by SavePackage to display progress when the DownloadItem
200 // should be considered complete. 204 // should be considered complete.
201 virtual void MarkAsComplete(); 205 virtual void MarkAsComplete();
202 206
203 // Interactions with persistence system --------------------------------------
204
205 // TODO(benjhayden): Remove when DownloadHistory becomes an observer.
206 virtual void SetIsPersisted();
207 virtual void SetDbHandle(int64 handle);
208
209 private: 207 private:
210 // Fine grained states of a download. 208 // Fine grained states of a download.
211 enum DownloadInternalState { 209 enum DownloadInternalState {
212 // Unless otherwise specified, state transitions are linear forward 210 // Unless otherwise specified, state transitions are linear forward
213 // in this list. 211 // in this list.
214 212
215 // Includes both before and after file name determination. 213 // Includes both before and after file name determination.
216 // TODO(rdsmith): Put in state variable for file name determination. 214 // TODO(rdsmith): Put in state variable for file name determination.
217 IN_PROGRESS_INTERNAL, 215 IN_PROGRESS_INTERNAL,
218 216
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 395
398 // The views of this item in the download shelf and download contents. 396 // The views of this item in the download shelf and download contents.
399 ObserverList<Observer> observers_; 397 ObserverList<Observer> observers_;
400 398
401 // Time the download was started. 399 // Time the download was started.
402 base::Time start_time_; 400 base::Time start_time_;
403 401
404 // Time the download completed. 402 // Time the download completed.
405 base::Time end_time_; 403 base::Time end_time_;
406 404
407 // Our persistent store handle.
408 int64 db_handle_;
409
410 // Our delegate. 405 // Our delegate.
411 DownloadItemImplDelegate* delegate_; 406 DownloadItemImplDelegate* delegate_;
412 407
413 // In progress downloads may be paused by the user, we note it here. 408 // In progress downloads may be paused by the user, we note it here.
414 bool is_paused_; 409 bool is_paused_;
415 410
416 // A flag for indicating if the download should be opened at completion. 411 // A flag for indicating if the download should be opened at completion.
417 bool open_when_complete_; 412 bool open_when_complete_;
418 413
419 // A flag for indicating if the downloaded file is externally removed. 414 // A flag for indicating if the downloaded file is externally removed.
420 bool file_externally_removed_; 415 bool file_externally_removed_;
421 416
422 // Indicates if the download is considered potentially safe or dangerous 417 // Indicates if the download is considered potentially safe or dangerous
423 // (executable files are typically considered dangerous). 418 // (executable files are typically considered dangerous).
424 SafetyState safety_state_; 419 SafetyState safety_state_;
425 420
426 // True if the download was auto-opened. We set this rather than using 421 // True if the download was auto-opened. We set this rather than using
427 // an observer as it's frequently possible for the download to be auto opened 422 // an observer as it's frequently possible for the download to be auto opened
428 // before the observer is added. 423 // before the observer is added.
429 bool auto_opened_; 424 bool auto_opened_;
430 425
431 bool is_persisted_;
432
433 // True if the item was downloaded temporarily. 426 // True if the item was downloaded temporarily.
434 bool is_temporary_; 427 bool is_temporary_;
435 428
436 // True if we've saved all the data for the download. 429 // True if we've saved all the data for the download.
437 bool all_data_saved_; 430 bool all_data_saved_;
438 431
439 // Did the user open the item either directly or indirectly (such as by 432 // Did the user open the item either directly or indirectly (such as by
440 // setting always open files of this type)? The shelf also sets this field 433 // setting always open files of this type)? The shelf also sets this field
441 // when the user closes the shelf before the item has been opened but should 434 // when the user closes the shelf before the item has been opened but should
442 // be treated as though the user opened it. 435 // be treated as though the user opened it.
443 bool opened_; 436 bool opened_;
444 437
445 // Do we actually open downloads when requested? For testing purposes only. 438 // Do we actually open downloads when requested? For testing purposes only.
446 bool open_enabled_; 439 bool open_enabled_;
447 440
448 // Did the delegate delay calling Complete on this download? 441 // Did the delegate delay calling Complete on this download?
449 bool delegate_delayed_complete_; 442 bool delegate_delayed_complete_;
450 443
451 // Net log to use for this download. 444 // Net log to use for this download.
452 const net::BoundNetLog bound_net_log_; 445 const net::BoundNetLog bound_net_log_;
453 446
454 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_; 447 base::WeakPtrFactory<DownloadItemImpl> weak_ptr_factory_;
455 448
456 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl); 449 DISALLOW_COPY_AND_ASSIGN(DownloadItemImpl);
457 }; 450 };
458 451
459 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_ 452 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698