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

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: Sync'd to LKGR. 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 //
5 4
6 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
7 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
8 #pragma once 7 #pragma once
9 8
10 #include <map> 9 #include <map>
11 #include <set> 10 #include <set>
12 11
13 #include "base/hash_tables.h" 12 #include "base/hash_tables.h"
14 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
17 #include "base/message_loop_helpers.h" 16 #include "base/message_loop_helpers.h"
18 #include "base/observer_list.h" 17 #include "base/observer_list.h"
19 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
19 #include "content/browser/download/download_item_factory.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:
28 explicit DownloadManagerImpl(net::NetLog* net_log); 30 // Caller guarantees that |file_manager| and |net_log| will remain valid
31 // for the lifetime of DownloadManagerImpl (until Shutdown() is called).
32 // |factory| may be a default constructed (null) scoped_ptr; if so,
33 // the DownloadManagerImpl creates and takes ownership of the
34 // default DownloadItemFactory.
35 DownloadManagerImpl(DownloadFileManager* file_manager,
36 scoped_ptr<content::DownloadItemFactory> factory,
37 net::NetLog* net_log);
29 38
30 // content::DownloadManager functions. 39 // content::DownloadManager functions.
31 virtual void SetDelegate(content::DownloadManagerDelegate* delegate) OVERRIDE; 40 virtual void SetDelegate(content::DownloadManagerDelegate* delegate) OVERRIDE;
32 virtual content::DownloadManagerDelegate* GetDelegate() const OVERRIDE; 41 virtual content::DownloadManagerDelegate* GetDelegate() const OVERRIDE;
33 virtual void Shutdown() OVERRIDE; 42 virtual void Shutdown() OVERRIDE;
34 virtual void GetTemporaryDownloads(const FilePath& dir_path, 43 virtual void GetTemporaryDownloads(const FilePath& dir_path,
35 DownloadVector* result) OVERRIDE; 44 DownloadVector* result) OVERRIDE;
36 virtual void GetAllDownloads(const FilePath& dir_path, 45 virtual void GetAllDownloads(const FilePath& dir_path,
37 DownloadVector* result) OVERRIDE; 46 DownloadVector* result) OVERRIDE;
38 virtual void SearchDownloads(const string16& query, 47 virtual void SearchDownloads(const string16& query,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 virtual void DownloadOpened( 111 virtual void DownloadOpened(
103 content::DownloadItem* download) OVERRIDE; 112 content::DownloadItem* download) OVERRIDE;
104 virtual void DownloadRemoved(content::DownloadItem* download) OVERRIDE; 113 virtual void DownloadRemoved(content::DownloadItem* download) OVERRIDE;
105 virtual void DownloadRenamedToIntermediateName( 114 virtual void DownloadRenamedToIntermediateName(
106 content::DownloadItem* download) OVERRIDE; 115 content::DownloadItem* download) OVERRIDE;
107 virtual void DownloadRenamedToFinalName( 116 virtual void DownloadRenamedToFinalName(
108 content::DownloadItem* download) OVERRIDE; 117 content::DownloadItem* download) OVERRIDE;
109 virtual void AssertStateConsistent( 118 virtual void AssertStateConsistent(
110 content::DownloadItem* download) const OVERRIDE; 119 content::DownloadItem* download) const OVERRIDE;
111 120
112 // For unit tests only.
113 void SetFileManagerForTesting(DownloadFileManager* file_manager);
114
115 private: 121 private:
116 typedef std::set<content::DownloadItem*> DownloadSet; 122 typedef std::set<content::DownloadItem*> DownloadSet;
117 typedef base::hash_map<int64, content::DownloadItem*> DownloadMap; 123 typedef base::hash_map<int64, content::DownloadItem*> DownloadMap;
118 124
119 // For testing. 125 // For testing.
120 friend class DownloadManagerTest; 126 friend class DownloadManagerTest;
121 friend class DownloadTest; 127 friend class DownloadTest;
122 128
123 friend class base::RefCountedThreadSafe<DownloadManagerImpl>; 129 friend class base::RefCountedThreadSafe<DownloadManagerImpl>;
124 130
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 178
173 // Remove from internal maps. 179 // Remove from internal maps.
174 int RemoveDownloadItems(const DownloadVector& pending_deletes); 180 int RemoveDownloadItems(const DownloadVector& pending_deletes);
175 181
176 // Called when a download entry is committed to the persistent store. 182 // Called when a download entry is committed to the persistent store.
177 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle); 183 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle);
178 184
179 // Called when Save Page As entry is committed to the persistent store. 185 // Called when Save Page As entry is committed to the persistent store.
180 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle); 186 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle);
181 187
188 // Factory for creation of downloads items.
189 scoped_ptr<content::DownloadItemFactory> factory_;
190
182 // |downloads_| is the owning set for all downloads known to the 191 // |downloads_| is the owning set for all downloads known to the
183 // DownloadManager. This includes downloads started by the user in 192 // DownloadManager. This includes downloads started by the user in
184 // this session, downloads initialized from the history system, and 193 // this session, downloads initialized from the history system, and
185 // "save page as" downloads. All other DownloadItem containers in 194 // "save page as" downloads. All other DownloadItem containers in
186 // the DownloadManager are maps; they do not own the DownloadItems. 195 // the DownloadManager are maps; they do not own the DownloadItems.
187 // Note that this is the only place (with any functional implications; 196 // Note that this is the only place (with any functional implications;
188 // see save_page_downloads_ below) that "save page as" downloads are 197 // see save_page_downloads_ below) that "save page as" downloads are
189 // kept, as the DownloadManager's only job is to hold onto those 198 // kept, as the DownloadManager's only job is to hold onto those
190 // until destruction. 199 // until destruction.
191 // 200 //
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 242
234 // Allows an embedder to control behavior. Guaranteed to outlive this object. 243 // Allows an embedder to control behavior. Guaranteed to outlive this object.
235 content::DownloadManagerDelegate* delegate_; 244 content::DownloadManagerDelegate* delegate_;
236 245
237 net::NetLog* net_log_; 246 net::NetLog* net_log_;
238 247
239 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); 248 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl);
240 }; 249 };
241 250
242 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 251 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl_unittest.cc ('k') | content/browser/download/download_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698