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

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: Incorporated John's 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 //
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 DownloadManagerImpl(content::DownloadManagerDelegate* delegate, 30 DownloadManagerImpl(content::DownloadManagerDelegate* delegate,
31 DownloadFileManager* file_manager,
32 content::DownloadItemFactory* factory,
29 net::NetLog* net_log); 33 net::NetLog* net_log);
30 34
31 // content::DownloadManager functions. 35 // content::DownloadManager functions.
32 virtual void Shutdown() OVERRIDE; 36 virtual void Shutdown() OVERRIDE;
33 virtual void GetTemporaryDownloads(const FilePath& dir_path, 37 virtual void GetTemporaryDownloads(const FilePath& dir_path,
34 DownloadVector* result) OVERRIDE; 38 DownloadVector* result) OVERRIDE;
35 virtual void GetAllDownloads(const FilePath& dir_path, 39 virtual void GetAllDownloads(const FilePath& dir_path,
36 DownloadVector* result) OVERRIDE; 40 DownloadVector* result) OVERRIDE;
37 virtual void SearchDownloads(const string16& query, 41 virtual void SearchDownloads(const string16& query,
38 DownloadVector* result) OVERRIDE; 42 DownloadVector* result) OVERRIDE;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 virtual void DownloadOpened( 108 virtual void DownloadOpened(
105 content::DownloadItem* download) OVERRIDE; 109 content::DownloadItem* download) OVERRIDE;
106 virtual void DownloadRemoved(content::DownloadItem* download) OVERRIDE; 110 virtual void DownloadRemoved(content::DownloadItem* download) OVERRIDE;
107 virtual void DownloadRenamedToIntermediateName( 111 virtual void DownloadRenamedToIntermediateName(
108 content::DownloadItem* download) OVERRIDE; 112 content::DownloadItem* download) OVERRIDE;
109 virtual void DownloadRenamedToFinalName( 113 virtual void DownloadRenamedToFinalName(
110 content::DownloadItem* download) OVERRIDE; 114 content::DownloadItem* download) OVERRIDE;
111 virtual void AssertStateConsistent( 115 virtual void AssertStateConsistent(
112 content::DownloadItem* download) const OVERRIDE; 116 content::DownloadItem* download) const OVERRIDE;
113 117
114 // For unit tests only.
115 void SetFileManagerForTesting(DownloadFileManager* file_manager);
116
117 private: 118 private:
118 typedef std::set<content::DownloadItem*> DownloadSet; 119 typedef std::set<content::DownloadItem*> DownloadSet;
119 typedef base::hash_map<int64, content::DownloadItem*> DownloadMap; 120 typedef base::hash_map<int64, content::DownloadItem*> DownloadMap;
120 121
121 // For testing. 122 // For testing.
122 friend class DownloadManagerTest; 123 friend class DownloadManagerTest;
123 friend class DownloadTest; 124 friend class DownloadTest;
124 125
125 friend class base::RefCountedThreadSafe<DownloadManagerImpl>; 126 friend class base::RefCountedThreadSafe<DownloadManagerImpl>;
126 127
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 175
175 // Remove from internal maps. 176 // Remove from internal maps.
176 int RemoveDownloadItems(const DownloadVector& pending_deletes); 177 int RemoveDownloadItems(const DownloadVector& pending_deletes);
177 178
178 // Called when a download entry is committed to the persistent store. 179 // Called when a download entry is committed to the persistent store.
179 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle); 180 void OnDownloadItemAddedToPersistentStore(int32 download_id, int64 db_handle);
180 181
181 // Called when Save Page As entry is committed to the persistent store. 182 // Called when Save Page As entry is committed to the persistent store.
182 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle); 183 void OnSavePageItemAddedToPersistentStore(int32 download_id, int64 db_handle);
183 184
185 // Factory for creation of downloads items.
186 scoped_ptr<content::DownloadItemFactory> factory_;
187
184 // |downloads_| is the owning set for all downloads known to the 188 // |downloads_| is the owning set for all downloads known to the
185 // DownloadManager. This includes downloads started by the user in 189 // DownloadManager. This includes downloads started by the user in
186 // this session, downloads initialized from the history system, and 190 // this session, downloads initialized from the history system, and
187 // "save page as" downloads. All other DownloadItem containers in 191 // "save page as" downloads. All other DownloadItem containers in
188 // the DownloadManager are maps; they do not own the DownloadItems. 192 // the DownloadManager are maps; they do not own the DownloadItems.
189 // Note that this is the only place (with any functional implications; 193 // Note that this is the only place (with any functional implications;
190 // see save_page_downloads_ below) that "save page as" downloads are 194 // see save_page_downloads_ below) that "save page as" downloads are
191 // kept, as the DownloadManager's only job is to hold onto those 195 // kept, as the DownloadManager's only job is to hold onto those
192 // until destruction. 196 // until destruction.
193 // 197 //
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 239
236 // Allows an embedder to control behavior. Guaranteed to outlive this object. 240 // Allows an embedder to control behavior. Guaranteed to outlive this object.
237 content::DownloadManagerDelegate* delegate_; 241 content::DownloadManagerDelegate* delegate_;
238 242
239 net::NetLog* net_log_; 243 net::NetLog* net_log_;
240 244
241 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); 245 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl);
242 }; 246 };
243 247
244 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ 248 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698