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

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

Issue 8770024: Added a download file factory to the download file manager, for testing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merged with trunk Created 9 years 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "content/browser/download/download_file_manager.h" 5 #include "content/browser/download/download_file_manager.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 16 matching lines...) Expand all
27 #include "net/base/io_buffer.h" 27 #include "net/base/io_buffer.h"
28 28
29 using content::BrowserThread; 29 using content::BrowserThread;
30 30
31 namespace { 31 namespace {
32 32
33 // Throttle updates to the UI thread so that a fast moving download doesn't 33 // Throttle updates to the UI thread so that a fast moving download doesn't
34 // cause it to become unresponsive (in milliseconds). 34 // cause it to become unresponsive (in milliseconds).
35 const int kUpdatePeriodMs = 500; 35 const int kUpdatePeriodMs = 500;
36 36
37 class DownloadFileFactoryImpl
38 : public DownloadFileManager::DownloadFileFactory {
39 public:
40 DownloadFileFactoryImpl() {}
41
42 virtual DownloadFile* CreateFile(DownloadCreateInfo* info,
43 const DownloadRequestHandle& request_handle,
44 DownloadManager* download_manager) OVERRIDE;
45 };
46
47 DownloadFile* DownloadFileFactoryImpl::CreateFile(
48 DownloadCreateInfo* info,
49 const DownloadRequestHandle& request_handle,
50 DownloadManager* download_manager) {
51 return new DownloadFileImpl(info,
52 new DownloadRequestHandle(request_handle),
53 download_manager);
54 }
55
37 } // namespace 56 } // namespace
38 57
39 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh) 58 DownloadFileManager::DownloadFileManager(ResourceDispatcherHost* rdh,
40 : resource_dispatcher_host_(rdh) { 59 DownloadFileFactory* factory)
60 : resource_dispatcher_host_(rdh), download_file_factory_(factory) {
61 if (download_file_factory_ == NULL)
62 download_file_factory_.reset(new DownloadFileFactoryImpl);
41 } 63 }
42 64
43 DownloadFileManager::~DownloadFileManager() { 65 DownloadFileManager::~DownloadFileManager() {
44 DCHECK(downloads_.empty()); 66 DCHECK(downloads_.empty());
45 } 67 }
46 68
47 void DownloadFileManager::Shutdown() { 69 void DownloadFileManager::Shutdown() {
48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
49 BrowserThread::PostTask( 71 BrowserThread::PostTask(
50 BrowserThread::FILE, FROM_HERE, 72 BrowserThread::FILE, FROM_HERE,
51 base::Bind(&DownloadFileManager::OnShutdown, this)); 73 base::Bind(&DownloadFileManager::OnShutdown, this));
52 } 74 }
53 75
54 void DownloadFileManager::OnShutdown() { 76 void DownloadFileManager::OnShutdown() {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
56 StopUpdateTimer(); 78 StopUpdateTimer();
57 STLDeleteValues(&downloads_); 79 STLDeleteValues(&downloads_);
58 } 80 }
59 81
60 void DownloadFileManager::CreateDownloadFile( 82 void DownloadFileManager::CreateDownloadFile(
61 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle, 83 DownloadCreateInfo* info, const DownloadRequestHandle& request_handle,
62 DownloadManager* download_manager, bool get_hash) { 84 DownloadManager* download_manager, bool get_hash) {
63 DCHECK(info); 85 DCHECK(info);
64 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString(); 86 VLOG(20) << __FUNCTION__ << "()" << " info = " << info->DebugString();
65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
66 88
67 // Life of |info| ends here. No more references to it after this method. 89 // Life of |info| ends here. No more references to it after this method.
68 scoped_ptr<DownloadCreateInfo> infop(info); 90 scoped_ptr<DownloadCreateInfo> infop(info);
69 91
70 scoped_ptr<DownloadFile> download_file( 92 scoped_ptr<DownloadFile> download_file(download_file_factory_->CreateFile(
71 new DownloadFileImpl(info, 93 info, request_handle, download_manager));
72 new DownloadRequestHandle(request_handle),
73 download_manager));
74 if (net::OK != download_file->Initialize(get_hash)) { 94 if (net::OK != download_file->Initialize(get_hash)) {
75 request_handle.CancelRequest(); 95 request_handle.CancelRequest();
76 return; 96 return;
77 } 97 }
78 98
79 DCHECK(GetDownloadFile(info->download_id) == NULL); 99 DCHECK(GetDownloadFile(info->download_id) == NULL);
80 downloads_[info->download_id] = download_file.release(); 100 downloads_[info->download_id] = download_file.release();
81 101
82 // The file is now ready, we can un-pause the request and start saving data. 102 // The file is now ready, we can un-pause the request and start saving data.
83 request_handle.ResumeRequest(); 103 request_handle.ResumeRequest();
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 << " id = " << global_id 446 << " id = " << global_id
427 << " download_file = " << download_file->DebugString(); 447 << " download_file = " << download_file->DebugString();
428 448
429 downloads_.erase(global_id); 449 downloads_.erase(global_id);
430 450
431 delete download_file; 451 delete download_file;
432 452
433 if (downloads_.empty()) 453 if (downloads_.empty())
434 StopUpdateTimer(); 454 StopUpdateTimer();
435 } 455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698