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

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

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r166491 Created 8 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) 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_MANAGER_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 scoped_ptr<DownloadCreateInfo> info, 57 scoped_ptr<DownloadCreateInfo> info,
58 scoped_ptr<ByteStreamReader> stream) OVERRIDE; 58 scoped_ptr<ByteStreamReader> stream) OVERRIDE;
59 virtual void CancelDownload(int32 download_id) OVERRIDE; 59 virtual void CancelDownload(int32 download_id) OVERRIDE;
60 virtual int RemoveDownloadsBetween(base::Time remove_begin, 60 virtual int RemoveDownloadsBetween(base::Time remove_begin,
61 base::Time remove_end) OVERRIDE; 61 base::Time remove_end) OVERRIDE;
62 virtual int RemoveDownloads(base::Time remove_begin) OVERRIDE; 62 virtual int RemoveDownloads(base::Time remove_begin) OVERRIDE;
63 virtual int RemoveAllDownloads() OVERRIDE; 63 virtual int RemoveAllDownloads() OVERRIDE;
64 virtual void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) OVERRIDE; 64 virtual void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) OVERRIDE;
65 virtual void AddObserver(Observer* observer) OVERRIDE; 65 virtual void AddObserver(Observer* observer) OVERRIDE;
66 virtual void RemoveObserver(Observer* observer) OVERRIDE; 66 virtual void RemoveObserver(Observer* observer) OVERRIDE;
67 virtual void OnPersistentStoreQueryComplete( 67 virtual content::DownloadItem* CreateDownloadItem(
68 std::vector<DownloadPersistentStoreInfo>* entries) OVERRIDE; 68 const FilePath& path,
69 virtual void OnItemAddedToPersistentStore(int32 download_id, 69 const GURL& url,
70 int64 db_handle) OVERRIDE; 70 const GURL& referrer_url,
71 const base::Time& start_time,
72 const base::Time& end_time,
73 int64 received_bytes,
74 int64 total_bytes,
75 content::DownloadItem::DownloadState state,
76 bool opened) OVERRIDE;
71 virtual int InProgressCount() const OVERRIDE; 77 virtual int InProgressCount() const OVERRIDE;
72 virtual BrowserContext* GetBrowserContext() const OVERRIDE; 78 virtual BrowserContext* GetBrowserContext() const OVERRIDE;
73 virtual void CheckForHistoryFilesRemoval() OVERRIDE; 79 virtual void CheckForHistoryFilesRemoval() OVERRIDE;
74 virtual DownloadItem* GetDownload(int id) OVERRIDE; 80 virtual DownloadItem* GetDownload(int id) OVERRIDE;
75 virtual void SavePageDownloadFinished(DownloadItem* download) OVERRIDE;
76 81
77 // For testing; specifically, accessed from TestFileErrorInjector. 82 // For testing; specifically, accessed from TestFileErrorInjector.
78 void SetDownloadItemFactoryForTesting( 83 void SetDownloadItemFactoryForTesting(
79 scoped_ptr<DownloadItemFactory> item_factory); 84 scoped_ptr<DownloadItemFactory> item_factory);
80 void SetDownloadFileFactoryForTesting( 85 void SetDownloadFileFactoryForTesting(
81 scoped_ptr<DownloadFileFactory> file_factory); 86 scoped_ptr<DownloadFileFactory> file_factory);
82 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); 87 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting();
83 88
84 private: 89 private:
85 typedef std::set<DownloadItem*> DownloadSet; 90 typedef std::set<DownloadItem*> DownloadSet;
86 typedef base::hash_map<int32, DownloadItemImpl*> DownloadMap; 91 typedef base::hash_map<int32, DownloadItemImpl*> DownloadMap;
87 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector; 92 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector;
88 93
89 // For testing. 94 // For testing.
90 friend class DownloadManagerTest; 95 friend class DownloadManagerTest;
91 friend class DownloadTest; 96 friend class DownloadTest;
92 97
93 friend class base::RefCountedThreadSafe<DownloadManagerImpl>; 98 friend class base::RefCountedThreadSafe<DownloadManagerImpl>;
94 99
95 virtual ~DownloadManagerImpl(); 100 virtual ~DownloadManagerImpl();
96 101
97 // Creates the download item. Must be called on the UI thread. 102 // Creates the download item. Must be called on the UI thread.
98 virtual DownloadItemImpl* CreateDownloadItem( 103 virtual DownloadItemImpl* CreateDownloadItem(
99 DownloadCreateInfo* info, const net::BoundNetLog& bound_net_log); 104 DownloadCreateInfo* info, const net::BoundNetLog& bound_net_log);
100 105
101 // Show the download in the browser.
102 void ShowDownloadInBrowser(DownloadItemImpl* download);
103
104 // Get next download id. 106 // Get next download id.
105 DownloadId GetNextId(); 107 DownloadId GetNextId();
106 108
107 // Called on the FILE thread to check the existence of a downloaded file. 109 // Called on the FILE thread to check the existence of a downloaded file.
108 void CheckForFileRemovalOnFileThread(int32 download_id, const FilePath& path); 110 void CheckForFileRemovalOnFileThread(int32 download_id, const FilePath& path);
109 111
110 // Called on the UI thread if the FILE thread detects the removal of 112 // Called on the UI thread if the FILE thread detects the removal of
111 // the downloaded file. The UI thread updates the state of the file 113 // the downloaded file. The UI thread updates the state of the file
112 // and then notifies this update to the file's observer. 114 // and then notifies this update to the file's observer.
113 void OnFileRemovalDetected(int32 download_id); 115 void OnFileRemovalDetected(int32 download_id);
114 116
115 // Removes |download| from the active and in progress maps. 117 // Removes |download| from the active and in progress maps.
116 // Called when the download is cancelled or has an error. 118 // Called when the download is cancelled or has an error.
117 // Does nothing if the download is not in the history DB. 119 // Does nothing if the download is not in the history DB.
118 void RemoveFromActiveList(DownloadItemImpl* download); 120 void RemoveFromActiveList(DownloadItemImpl* download);
119 121
120 // Debugging routine to confirm relationship between below 122 // Debugging routine to confirm relationship between below
121 // containers; no-op if NDEBUG. 123 // containers; no-op if NDEBUG.
122 void AssertContainersConsistent() const; 124 void AssertContainersConsistent() const;
123 125
124 // Add a DownloadItem to history_downloads_.
125 void AddDownloadItemToHistory(DownloadItemImpl* item, int64 db_handle);
126
127 // Remove from internal maps. 126 // Remove from internal maps.
128 int RemoveDownloadItems(const DownloadItemImplVector& pending_deletes); 127 int RemoveDownloadItems(const DownloadItemImplVector& pending_deletes);
129 128
130 // Called when a download entry is committed to the persistent store.
131 void OnDownloadItemAddedToPersistentStore(DownloadItemImpl* item);
132
133 // Called when Save Page As entry is committed to the persistent store.
134 void OnSavePageItemAddedToPersistentStore(DownloadItemImpl* item);
135
136 // Overridden from DownloadItemImplDelegate 129 // Overridden from DownloadItemImplDelegate
137 // (Note that |GetBrowserContext| are present in both interfaces.) 130 // (Note that |GetBrowserContext| are present in both interfaces.)
138 virtual void DetermineDownloadTarget( 131 virtual void DetermineDownloadTarget(
139 DownloadItemImpl* item, const DownloadTargetCallback& callback) OVERRIDE; 132 DownloadItemImpl* item, const DownloadTargetCallback& callback) OVERRIDE;
140 virtual void ReadyForDownloadCompletion( 133 virtual void ReadyForDownloadCompletion(
141 DownloadItemImpl* item, const base::Closure& complete_callback) OVERRIDE; 134 DownloadItemImpl* item, const base::Closure& complete_callback) OVERRIDE;
142 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE; 135 virtual bool ShouldOpenFileBasedOnExtension(const FilePath& path) OVERRIDE;
143 virtual bool ShouldOpenDownload(DownloadItemImpl* item) OVERRIDE; 136 virtual bool ShouldOpenDownload(DownloadItemImpl* item) OVERRIDE;
144 virtual void CheckForFileRemoval(DownloadItemImpl* download_item) OVERRIDE; 137 virtual void CheckForFileRemoval(DownloadItemImpl* download_item) OVERRIDE;
145 virtual void UpdatePersistence(DownloadItemImpl* download) OVERRIDE;
146 virtual void DownloadStopped(DownloadItemImpl* download) OVERRIDE; 138 virtual void DownloadStopped(DownloadItemImpl* download) OVERRIDE;
147 virtual void DownloadCompleted(DownloadItemImpl* download) OVERRIDE; 139 virtual void DownloadCompleted(DownloadItemImpl* download) OVERRIDE;
148 virtual void DownloadOpened(DownloadItemImpl* download) OVERRIDE; 140 virtual void DownloadOpened(DownloadItemImpl* download) OVERRIDE;
149 virtual void DownloadRemoved(DownloadItemImpl* download) OVERRIDE; 141 virtual void DownloadRemoved(DownloadItemImpl* download) OVERRIDE;
150 virtual void DownloadRenamedToIntermediateName( 142 virtual void ShowDownloadInBrowser(DownloadItemImpl* download) OVERRIDE;
151 DownloadItemImpl* download) OVERRIDE;
152 virtual void DownloadRenamedToFinalName(DownloadItemImpl* download) OVERRIDE;
153 virtual void AssertStateConsistent(DownloadItemImpl* download) const OVERRIDE; 143 virtual void AssertStateConsistent(DownloadItemImpl* download) const OVERRIDE;
154 144
155 // Factory for creation of downloads items. 145 // Factory for creation of downloads items.
156 scoped_ptr<DownloadItemFactory> item_factory_; 146 scoped_ptr<DownloadItemFactory> item_factory_;
157 147
158 // Factory for the creation of download files. 148 // Factory for the creation of download files.
159 scoped_ptr<DownloadFileFactory> file_factory_; 149 scoped_ptr<DownloadFileFactory> file_factory_;
160 150
161 // |downloads_| is the owning set for all downloads known to the 151 // |downloads_| is the owning set for all downloads known to the
162 // DownloadManager. This includes downloads started by the user in 152 // DownloadManager. This includes downloads started by the user in
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 DownloadManagerDelegate* delegate_; 187 DownloadManagerDelegate* delegate_;
198 188
199 net::NetLog* net_log_; 189 net::NetLog* net_log_;
200 190
201 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); 191 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl);
202 }; 192 };
203 193
204 } // namespace content 194 } // namespace content
205 195
206 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 196 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698