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

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

Issue 10344024: Rewrite download manager unit to be actual unit tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modified creation comment. Created 8 years, 6 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 5
6 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 6 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
7 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 7 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
8 #pragma once 8 #pragma once
9 9
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 12
13 #include "base/hash_tables.h" 13 #include "base/hash_tables.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/message_loop_helpers.h" 17 #include "base/message_loop_helpers.h"
18 #include "base/observer_list.h" 18 #include "base/observer_list.h"
19 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
20 #include "content/browser/download/download_item_impl.h" 20 #include "content/browser/download/download_item_impl.h"
21 #include "content/common/content_export.h" 21 #include "content/common/content_export.h"
22 #include "content/public/browser/download_manager.h" 22 #include "content/public/browser/download_manager.h"
23 23
24 class DownloadFileManager;
25
24 class CONTENT_EXPORT DownloadManagerImpl 26 class CONTENT_EXPORT DownloadManagerImpl
25 : public content::DownloadManager, 27 : public content::DownloadManager,
26 public DownloadItemImpl::Delegate { 28 public DownloadItemImpl::Delegate {
27 public: 29 public:
30 class DownloadItemFactory {
jam 2012/06/07 03:21:45 nit: can this be put in new h/cc files for readabi
Randy Smith (Not in Mondays) 2012/06/07 23:27:21 I moved the declaration out into its own .h file.
31 public:
32 virtual ~DownloadItemFactory() {}
33
34 virtual content::DownloadItem* CreatePersistedItem(
35 DownloadItemImpl::Delegate* delegate,
36 content::DownloadId download_id,
37 const content::DownloadPersistentStoreInfo& info,
38 const net::BoundNetLog& bound_net_log) = 0;
39
40 virtual content::DownloadItem* CreateActiveItem(
41 DownloadItemImpl::Delegate* delegate,
42 const DownloadCreateInfo& info,
43 DownloadRequestHandleInterface* request_handle,
44 bool is_otr,
45 const net::BoundNetLog& bound_net_log) = 0;
46
47 virtual content::DownloadItem* CreateSavePageItem(
48 DownloadItemImpl::Delegate* delegate,
49 const FilePath& path,
50 const GURL& url,
51 bool is_otr,
52 content::DownloadId download_id,
53 const std::string& mime_type,
54 const net::BoundNetLog& bound_net_log) = 0;
55 };
56
28 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, 57 DownloadManagerImpl(content::DownloadManagerDelegate* delegate,
asanka 2012/06/07 17:04:53 Nit: Document ownership semantics?
Randy Smith (Not in Mondays) 2012/06/07 23:27:21 Delegate argument gone, file_manager (lack of) own
58 DownloadFileManager* file_manager,
59 DownloadItemFactory* factory,
29 net::NetLog* net_log); 60 net::NetLog* net_log);
30 61
31 // content::DownloadManager functions. 62 // content::DownloadManager functions.
32 virtual void Shutdown() OVERRIDE; 63 virtual void Shutdown() OVERRIDE;
33 virtual void GetTemporaryDownloads(const FilePath& dir_path, 64 virtual void GetTemporaryDownloads(const FilePath& dir_path,
34 DownloadVector* result) OVERRIDE; 65 DownloadVector* result) OVERRIDE;
35 virtual void GetAllDownloads(const FilePath& dir_path, 66 virtual void GetAllDownloads(const FilePath& dir_path,
36 DownloadVector* result) OVERRIDE; 67 DownloadVector* result) OVERRIDE;
37 virtual void SearchDownloads(const string16& query, 68 virtual void SearchDownloads(const string16& query,
38 DownloadVector* result) OVERRIDE; 69 DownloadVector* result) OVERRIDE;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 virtual void DownloadOpened( 135 virtual void DownloadOpened(
105 content::DownloadItem* download) OVERRIDE; 136 content::DownloadItem* download) OVERRIDE;
106 virtual void DownloadRemoved(content::DownloadItem* download) OVERRIDE; 137 virtual void DownloadRemoved(content::DownloadItem* download) OVERRIDE;
107 virtual void DownloadRenamedToIntermediateName( 138 virtual void DownloadRenamedToIntermediateName(
108 content::DownloadItem* download) OVERRIDE; 139 content::DownloadItem* download) OVERRIDE;
109 virtual void DownloadRenamedToFinalName( 140 virtual void DownloadRenamedToFinalName(
110 content::DownloadItem* download) OVERRIDE; 141 content::DownloadItem* download) OVERRIDE;
111 virtual void AssertStateConsistent( 142 virtual void AssertStateConsistent(
112 content::DownloadItem* download) const OVERRIDE; 143 content::DownloadItem* download) const OVERRIDE;
113 144
114 // For unit tests only.
115 void SetFileManagerForTesting(DownloadFileManager* file_manager);
116
117 private: 145 private:
118 typedef std::set<content::DownloadItem*> DownloadSet; 146 typedef std::set<content::DownloadItem*> DownloadSet;
119 typedef base::hash_map<int64, content::DownloadItem*> DownloadMap; 147 typedef base::hash_map<int64, content::DownloadItem*> DownloadMap;
120 148
121 // For testing. 149 // For testing.
122 friend class DownloadManagerTest; 150 friend class DownloadManagerTest;
123 friend class DownloadTest; 151 friend class DownloadTest;
124 152
125 friend class base::RefCountedThreadSafe<DownloadManagerImpl>; 153 friend class base::RefCountedThreadSafe<DownloadManagerImpl>;
126 154
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 202
175 // Remove from internal maps. 203 // Remove from internal maps.
176 int RemoveDownloadItems(const DownloadVector& pending_deletes); 204 int RemoveDownloadItems(const DownloadVector& pending_deletes);
177 205
178 // Called when a download entry is committed to the persistent store. 206 // Called when a download entry is committed to the persistent store.
179 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle); 207 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle);
180 208
181 // Called when Save Page As entry is committed to the persistent store. 209 // Called when Save Page As entry is committed to the persistent store.
182 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle); 210 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle);
183 211
212 // Factory for creation of downloads items.
213 scoped_ptr<DownloadItemFactory> factory_;
214
184 // |downloads_| is the owning set for all downloads known to the 215 // |downloads_| is the owning set for all downloads known to the
185 // DownloadManager. This includes downloads started by the user in 216 // DownloadManager. This includes downloads started by the user in
186 // this session, downloads initialized from the history system, and 217 // this session, downloads initialized from the history system, and
187 // "save page as" downloads. All other DownloadItem containers in 218 // "save page as" downloads. All other DownloadItem containers in
188 // the DownloadManager are maps; they do not own the DownloadItems. 219 // the DownloadManager are maps; they do not own the DownloadItems.
189 // Note that this is the only place (with any functional implications; 220 // Note that this is the only place (with any functional implications;
190 // see save_page_downloads_ below) that "save page as" downloads are 221 // see save_page_downloads_ below) that "save page as" downloads are
191 // kept, as the DownloadManager's only job is to hold onto those 222 // kept, as the DownloadManager's only job is to hold onto those
192 // until destruction. 223 // until destruction.
193 // 224 //
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 266
236 // Allows an embedder to control behavior. Guaranteed to outlive this object. 267 // Allows an embedder to control behavior. Guaranteed to outlive this object.
237 content::DownloadManagerDelegate* delegate_; 268 content::DownloadManagerDelegate* delegate_;
238 269
239 net::NetLog* net_log_; 270 net::NetLog* net_log_;
240 271
241 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); 272 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl);
242 }; 273 };
243 274
244 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 275 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698