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

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 11028131: Shift passage of FileStream in downloads system to be by scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Al's comments. 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 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // We're in a content_browsertest; we know that the DownloadManager 68 // We're in a content_browsertest; we know that the DownloadManager
69 // is a DownloadManagerImpl. 69 // is a DownloadManagerImpl.
70 return static_cast<DownloadManagerImpl*>( 70 return static_cast<DownloadManagerImpl*>(
71 BrowserContext::GetDownloadManager( 71 BrowserContext::GetDownloadManager(
72 shell->web_contents()->GetBrowserContext())); 72 shell->web_contents()->GetBrowserContext()));
73 } 73 }
74 74
75 class DownloadFileWithDelay : public DownloadFileImpl { 75 class DownloadFileWithDelay : public DownloadFileImpl {
76 public: 76 public:
77 DownloadFileWithDelay( 77 DownloadFileWithDelay(
78 const DownloadCreateInfo* info, 78 scoped_ptr<DownloadCreateInfo> info,
79 scoped_ptr<content::ByteStreamReader> stream, 79 scoped_ptr<content::ByteStreamReader> stream,
80 DownloadRequestHandleInterface* request_handle, 80 scoped_ptr<DownloadRequestHandleInterface> request_handle,
81 scoped_refptr<content::DownloadManager> download_manager, 81 scoped_refptr<content::DownloadManager> download_manager,
82 bool calculate_hash, 82 bool calculate_hash,
83 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, 83 scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
84 const net::BoundNetLog& bound_net_log, 84 const net::BoundNetLog& bound_net_log,
85 // |owner| is required to outlive the DownloadFileWithDelay. 85 // |owner| is required to outlive the DownloadFileWithDelay.
86 DownloadFileWithDelayFactory* owner); 86 DownloadFileWithDelayFactory* owner);
87 87
88 virtual ~DownloadFileWithDelay(); 88 virtual ~DownloadFileWithDelay();
89 89
90 // Wraps DownloadFileImpl::Rename and intercepts the return callback, 90 // Wraps DownloadFileImpl::Rename and intercepts the return callback,
(...skipping 25 matching lines...) Expand all
116 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay); 116 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay);
117 }; 117 };
118 118
119 class DownloadFileWithDelayFactory : public DownloadFileFactory { 119 class DownloadFileWithDelayFactory : public DownloadFileFactory {
120 public: 120 public:
121 DownloadFileWithDelayFactory(); 121 DownloadFileWithDelayFactory();
122 virtual ~DownloadFileWithDelayFactory(); 122 virtual ~DownloadFileWithDelayFactory();
123 123
124 // DownloadFileFactory interface. 124 // DownloadFileFactory interface.
125 virtual content::DownloadFile* CreateFile( 125 virtual content::DownloadFile* CreateFile(
126 DownloadCreateInfo* info, 126 scoped_ptr<DownloadCreateInfo> info,
127 scoped_ptr<content::ByteStreamReader> stream, 127 scoped_ptr<content::ByteStreamReader> stream,
128 DownloadManager* download_manager, 128 DownloadManager* download_manager,
129 bool calculate_hash, 129 bool calculate_hash,
130 const net::BoundNetLog& bound_net_log) OVERRIDE; 130 const net::BoundNetLog& bound_net_log) OVERRIDE;
131 131
132 // Must all be called on the UI thread. 132 // Must all be called on the UI thread.
133 void AddRenameCallback(base::Closure callback); 133 void AddRenameCallback(base::Closure callback);
134 void AddDetachCallback(base::Closure callback); 134 void AddDetachCallback(base::Closure callback);
135 void GetAllRenameCallbacks(std::vector<base::Closure>* results); 135 void GetAllRenameCallbacks(std::vector<base::Closure>* results);
136 void GetAllDetachCallbacks(std::vector<base::Closure>* results); 136 void GetAllDetachCallbacks(std::vector<base::Closure>* results);
137 137
138 // Do not return until either GetAllRenameCallbacks() or 138 // Do not return until either GetAllRenameCallbacks() or
139 // GetAllDetachCallbacks() will return a non-empty list. 139 // GetAllDetachCallbacks() will return a non-empty list.
140 void WaitForSomeCallback(); 140 void WaitForSomeCallback();
141 141
142 private: 142 private:
143 std::vector<base::Closure> rename_callbacks_; 143 std::vector<base::Closure> rename_callbacks_;
144 std::vector<base::Closure> detach_callbacks_; 144 std::vector<base::Closure> detach_callbacks_;
145 bool waiting_; 145 bool waiting_;
146 146
147 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); 147 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory);
148 }; 148 };
149 149
150 DownloadFileWithDelay::DownloadFileWithDelay( 150 DownloadFileWithDelay::DownloadFileWithDelay(
151 const DownloadCreateInfo* info, 151 scoped_ptr<DownloadCreateInfo> info,
152 scoped_ptr<content::ByteStreamReader> stream, 152 scoped_ptr<content::ByteStreamReader> stream,
153 DownloadRequestHandleInterface* request_handle, 153 scoped_ptr<DownloadRequestHandleInterface> request_handle,
154 scoped_refptr<content::DownloadManager> download_manager, 154 scoped_refptr<content::DownloadManager> download_manager,
155 bool calculate_hash, 155 bool calculate_hash,
156 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, 156 scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
157 const net::BoundNetLog& bound_net_log, 157 const net::BoundNetLog& bound_net_log,
158 DownloadFileWithDelayFactory* owner) 158 DownloadFileWithDelayFactory* owner)
159 : DownloadFileImpl(info, stream.Pass(), request_handle, download_manager, 159 : DownloadFileImpl(info.Pass(), stream.Pass(), request_handle.Pass(),
160 calculate_hash, power_save_blocker.Pass(), 160 download_manager, calculate_hash,
161 bound_net_log), 161 power_save_blocker.Pass(), bound_net_log),
162 owner_(owner) {} 162 owner_(owner) {}
163 163
164 DownloadFileWithDelay::~DownloadFileWithDelay() {} 164 DownloadFileWithDelay::~DownloadFileWithDelay() {}
165 165
166 void DownloadFileWithDelay::Rename(const FilePath& full_path, 166 void DownloadFileWithDelay::Rename(const FilePath& full_path,
167 bool overwrite_existing_file, 167 bool overwrite_existing_file,
168 const RenameCompletionCallback& callback) { 168 const RenameCompletionCallback& callback) {
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
170 DownloadFileImpl::Rename( 170 DownloadFileImpl::Rename(
171 full_path, overwrite_existing_file, 171 full_path, overwrite_existing_file,
(...skipping 24 matching lines...) Expand all
196 const base::Closure& original_callback) { 196 const base::Closure& original_callback) {
197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
198 factory->AddDetachCallback(original_callback); 198 factory->AddDetachCallback(original_callback);
199 } 199 }
200 200
201 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() 201 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory()
202 : waiting_(false) {} 202 : waiting_(false) {}
203 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} 203 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {}
204 204
205 DownloadFile* DownloadFileWithDelayFactory::CreateFile( 205 DownloadFile* DownloadFileWithDelayFactory::CreateFile(
206 DownloadCreateInfo* info, 206 scoped_ptr<DownloadCreateInfo> info,
207 scoped_ptr<content::ByteStreamReader> stream, 207 scoped_ptr<content::ByteStreamReader> stream,
208 DownloadManager* download_manager, 208 DownloadManager* download_manager,
209 bool calculate_hash, 209 bool calculate_hash,
210 const net::BoundNetLog& bound_net_log) { 210 const net::BoundNetLog& bound_net_log) {
211 // Ownership will be taken by DownloadFileWithDelay.
212 scoped_ptr<DownloadRequestHandleInterface> request_handle(
213 new DownloadRequestHandle(info->request_handle));
214
211 return new DownloadFileWithDelay( 215 return new DownloadFileWithDelay(
212 info, stream.Pass(), new DownloadRequestHandle(info->request_handle), 216 info.Pass(), stream.Pass(), request_handle.Pass(), download_manager,
213 download_manager, calculate_hash, 217 calculate_hash,
214 scoped_ptr<content::PowerSaveBlocker>( 218 scoped_ptr<content::PowerSaveBlocker>(
215 new content::PowerSaveBlocker( 219 new content::PowerSaveBlocker(
216 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 220 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
217 "Download in progress")).Pass(), 221 "Download in progress")).Pass(),
218 bound_net_log, this); 222 bound_net_log, this);
219 } 223 }
220 224
221 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { 225 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 rename_callbacks_.push_back(callback); 227 rename_callbacks_.push_back(callback);
(...skipping 30 matching lines...) Expand all
254 } 258 }
255 } 259 }
256 260
257 bool WasPersisted(DownloadItem* item) { 261 bool WasPersisted(DownloadItem* item) {
258 return item->IsPersisted(); 262 return item->IsPersisted();
259 } 263 }
260 264
261 class CountingDownloadFile : public DownloadFileImpl { 265 class CountingDownloadFile : public DownloadFileImpl {
262 public: 266 public:
263 CountingDownloadFile( 267 CountingDownloadFile(
264 const DownloadCreateInfo* info, 268 scoped_ptr<DownloadCreateInfo> info,
265 scoped_ptr<content::ByteStreamReader> stream, 269 scoped_ptr<content::ByteStreamReader> stream,
266 DownloadRequestHandleInterface* request_handle, 270 scoped_ptr<DownloadRequestHandleInterface> request_handle,
267 scoped_refptr<content::DownloadManager> download_manager, 271 scoped_refptr<content::DownloadManager> download_manager,
268 bool calculate_hash, 272 bool calculate_hash,
269 scoped_ptr<content::PowerSaveBlocker> power_save_blocker, 273 scoped_ptr<content::PowerSaveBlocker> power_save_blocker,
270 const net::BoundNetLog& bound_net_log) 274 const net::BoundNetLog& bound_net_log)
271 : DownloadFileImpl(info, stream.Pass(), request_handle, download_manager, 275 : DownloadFileImpl(info.Pass(), stream.Pass(), request_handle.Pass(),
272 calculate_hash, power_save_blocker.Pass(), 276 download_manager, calculate_hash,
273 bound_net_log) {} 277 power_save_blocker.Pass(), bound_net_log) {}
274 278
275 virtual ~CountingDownloadFile() { 279 virtual ~CountingDownloadFile() {
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
277 active_files_--; 281 active_files_--;
278 } 282 }
279 283
280 virtual content::DownloadInterruptReason Initialize() OVERRIDE { 284 virtual content::DownloadInterruptReason Initialize() OVERRIDE {
281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
282 active_files_++; 286 active_files_++;
283 return DownloadFileImpl::Initialize(); 287 return DownloadFileImpl::Initialize();
(...skipping 22 matching lines...) Expand all
306 310
307 int CountingDownloadFile::active_files_ = 0; 311 int CountingDownloadFile::active_files_ = 0;
308 312
309 class CountingDownloadFileFactory : public DownloadFileFactory { 313 class CountingDownloadFileFactory : public DownloadFileFactory {
310 public: 314 public:
311 CountingDownloadFileFactory() {} 315 CountingDownloadFileFactory() {}
312 virtual ~CountingDownloadFileFactory() {} 316 virtual ~CountingDownloadFileFactory() {}
313 317
314 // DownloadFileFactory interface. 318 // DownloadFileFactory interface.
315 virtual content::DownloadFile* CreateFile( 319 virtual content::DownloadFile* CreateFile(
316 DownloadCreateInfo* info, 320 scoped_ptr<DownloadCreateInfo> info,
317 scoped_ptr<content::ByteStreamReader> stream, 321 scoped_ptr<content::ByteStreamReader> stream,
318 DownloadManager* download_manager, 322 DownloadManager* download_manager,
319 bool calculate_hash, 323 bool calculate_hash,
320 const net::BoundNetLog& bound_net_log) OVERRIDE { 324 const net::BoundNetLog& bound_net_log) OVERRIDE {
325 scoped_ptr<DownloadRequestHandleInterface> request_handle(
326 new DownloadRequestHandle(info->request_handle));
327
321 return new CountingDownloadFile( 328 return new CountingDownloadFile(
322 info, stream.Pass(), new DownloadRequestHandle(info->request_handle), 329 info.Pass(), stream.Pass(),
330 request_handle.Pass(),
323 download_manager, calculate_hash, 331 download_manager, calculate_hash,
324 scoped_ptr<content::PowerSaveBlocker>( 332 scoped_ptr<content::PowerSaveBlocker>(
325 new content::PowerSaveBlocker( 333 new content::PowerSaveBlocker(
326 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 334 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
327 "Download in progress")).Pass(), 335 "Download in progress")).Pass(),
328 bound_net_log); 336 bound_net_log);
329 } 337 }
330 }; 338 };
331 339
332 } // namespace 340 } // namespace
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 // Shutdown the download manager. Mostly this is confirming a lack of 749 // Shutdown the download manager. Mostly this is confirming a lack of
742 // crashes. 750 // crashes.
743 DownloadManagerForShell(shell())->Shutdown(); 751 DownloadManagerForShell(shell())->Shutdown();
744 752
745 // Run the detach callback; shouldn't cause any problems. 753 // Run the detach callback; shouldn't cause any problems.
746 callbacks[0].Run(); 754 callbacks[0].Run();
747 callbacks.clear(); 755 callbacks.clear();
748 } 756 }
749 757
750 } // namespace content 758 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/base_file_unittest.cc ('k') | content/browser/download/download_create_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698