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

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

Issue 8372073: Merge 8401001 r107836 into branch 912: Fix history importing by delaying DownloadManager creation. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/912/src/
Patch Set: Created 9 years, 1 month 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) 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 "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/task.h" 10 #include "base/task.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Life of |info| ends here. No more references to it after this method. 59 // Life of |info| ends here. No more references to it after this method.
60 scoped_ptr<DownloadCreateInfo> infop(info); 60 scoped_ptr<DownloadCreateInfo> infop(info);
61 61
62 scoped_ptr<DownloadFile> 62 scoped_ptr<DownloadFile>
63 download_file(new DownloadFile(info, download_manager)); 63 download_file(new DownloadFile(info, download_manager));
64 if (net::OK != download_file->Initialize(get_hash)) { 64 if (net::OK != download_file->Initialize(get_hash)) {
65 info->request_handle.CancelRequest(); 65 info->request_handle.CancelRequest();
66 return; 66 return;
67 } 67 }
68 68
69 DownloadId global_id(download_manager, info->download_id); 69 DCHECK(GetDownloadFile(info->download_id) == NULL);
70 DCHECK(GetDownloadFile(global_id) == NULL); 70 downloads_[info->download_id] = download_file.release();
71 downloads_[global_id] = download_file.release();
72 71
73 // The file is now ready, we can un-pause the request and start saving data. 72 // The file is now ready, we can un-pause the request and start saving data.
74 info->request_handle.ResumeRequest(); 73 info->request_handle.ResumeRequest();
75 74
76 StartUpdateTimer(); 75 StartUpdateTimer();
77 76
78 BrowserThread::PostTask( 77 BrowserThread::PostTask(
79 BrowserThread::UI, FROM_HERE, 78 BrowserThread::UI, FROM_HERE,
80 NewRunnableMethod(download_manager, 79 NewRunnableMethod(download_manager,
81 &DownloadManager::StartDownload, info->download_id)); 80 &DownloadManager::StartDownload,
81 info->download_id.local()));
82 } 82 }
83 83
84 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) { 84 DownloadFile* DownloadFileManager::GetDownloadFile(DownloadId global_id) {
85 DownloadFileMap::iterator it = downloads_.find(global_id); 85 DownloadFileMap::iterator it = downloads_.find(global_id);
86 return it == downloads_.end() ? NULL : it->second; 86 return it == downloads_.end() ? NULL : it->second;
87 } 87 }
88 88
89 void DownloadFileManager::StartUpdateTimer() { 89 void DownloadFileManager::StartUpdateTimer() {
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
91 if (!update_timer_.IsRunning()) { 91 if (!update_timer_.IsRunning()) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 i != downloads_.end(); ++i) { 293 i != downloads_.end(); ++i) {
294 DownloadFile* download_file = i->second; 294 DownloadFile* download_file = i->second;
295 if (download_file->GetDownloadManager() == manager) { 295 if (download_file->GetDownloadManager() == manager) {
296 download_file->CancelDownloadRequest(); 296 download_file->CancelDownloadRequest();
297 to_remove.insert(download_file); 297 to_remove.insert(download_file);
298 } 298 }
299 } 299 }
300 300
301 for (std::set<DownloadFile*>::iterator i = to_remove.begin(); 301 for (std::set<DownloadFile*>::iterator i = to_remove.begin();
302 i != to_remove.end(); ++i) { 302 i != to_remove.end(); ++i) {
303 downloads_.erase(DownloadId((*i)->GetDownloadManager(), (*i)->id())); 303 downloads_.erase((*i)->global_id());
304 delete *i; 304 delete *i;
305 } 305 }
306 } 306 }
307 307
308 // Actions from the UI thread and run on the download thread 308 // Actions from the UI thread and run on the download thread
309 309
310 // The DownloadManager in the UI thread has provided an intermediate .crdownload 310 // The DownloadManager in the UI thread has provided an intermediate .crdownload
311 // name for the download specified by 'id'. Rename the in progress download. 311 // name for the download specified by 'id'. Rename the in progress download.
312 // 312 //
313 // There are 2 possible rename cases where this method can be called: 313 // There are 2 possible rename cases where this method can be called:
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 << " id = " << global_id 440 << " id = " << global_id
441 << " download_file = " << download_file->DebugString(); 441 << " download_file = " << download_file->DebugString();
442 442
443 downloads_.erase(global_id); 443 downloads_.erase(global_id);
444 444
445 delete download_file; 445 delete download_file;
446 446
447 if (downloads_.empty()) 447 if (downloads_.empty())
448 StopUpdateTimer(); 448 StopUpdateTimer();
449 } 449 }
OLDNEW
« no previous file with comments | « content/browser/download/download_file.cc ('k') | content/browser/download/download_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698