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

Side by Side Diff: chrome/browser/download/download_file.cc

Issue 19004: Change URLRequest to use a ref-counted buffer for actual IO.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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
« no previous file with comments | « chrome/browser/download/download_file.h ('k') | chrome/browser/download/save_file_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <Windows.h> 5 #include <Windows.h>
6 #include <objbase.h> 6 #include <objbase.h>
7 7
8 #include "chrome/browser/download/download_file.h" 8 #include "chrome/browser/download/download_file.h"
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/scoped_ptr.h" 12 #include "base/scoped_ptr.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/task.h" 14 #include "base/task.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/download/download_manager.h" 16 #include "chrome/browser/download/download_manager.h"
17 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 18 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
19 #include "chrome/browser/tab_contents/tab_util.h" 19 #include "chrome/browser/tab_contents/tab_util.h"
20 #include "chrome/browser/tab_contents/web_contents.h" 20 #include "chrome/browser/tab_contents/web_contents.h"
21 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/stl_util-inl.h" 22 #include "chrome/common/stl_util-inl.h"
23 #include "chrome/common/win_util.h" 23 #include "chrome/common/win_util.h"
24 #include "chrome/common/win_safe_util.h" 24 #include "chrome/common/win_safe_util.h"
25 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
26 #include "net/base/io_buffer.h"
26 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
27 #include "net/url_request/url_request_context.h" 28 #include "net/url_request/url_request_context.h"
28 29
29 using base::TimeDelta; 30 using base::TimeDelta;
30 31
31 // Throttle updates to the UI thread so that a fast moving download doesn't 32 // Throttle updates to the UI thread so that a fast moving download doesn't
32 // cause it to become unresponsive (ins milliseconds). 33 // cause it to become unresponsive (ins milliseconds).
33 static const int kUpdatePeriodMs = 500; 34 static const int kUpdatePeriodMs = 500;
34 35
35 // Timer task for posting UI updates. This task is created and maintained by 36 // Timer task for posting UI updates. This task is created and maintained by
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) { 259 void DownloadFileManager::UpdateDownload(int id, DownloadBuffer* buffer) {
259 DCHECK(MessageLoop::current() == file_loop_); 260 DCHECK(MessageLoop::current() == file_loop_);
260 std::vector<DownloadBuffer::Contents> contents; 261 std::vector<DownloadBuffer::Contents> contents;
261 { 262 {
262 AutoLock auto_lock(buffer->lock); 263 AutoLock auto_lock(buffer->lock);
263 contents.swap(buffer->contents); 264 contents.swap(buffer->contents);
264 } 265 }
265 266
266 DownloadFile* download = LookupDownload(id); 267 DownloadFile* download = LookupDownload(id);
267 for (size_t i = 0; i < contents.size(); ++i) { 268 for (size_t i = 0; i < contents.size(); ++i) {
268 char* data = contents[i].first; 269 net::IOBuffer* data = contents[i].first;
269 const int data_len = contents[i].second; 270 const int data_len = contents[i].second;
270 if (download) 271 if (download)
271 download->AppendDataToFile(data, data_len); 272 download->AppendDataToFile(data->data(), data_len);
272 delete [] data; 273 data->Release();
273 } 274 }
274 275
275 if (download) { 276 if (download) {
276 AutoLock lock(progress_lock_); 277 AutoLock lock(progress_lock_);
277 ui_progress_[download->id()] = download->bytes_so_far(); 278 ui_progress_[download->id()] = download->bytes_so_far();
278 } 279 }
279 } 280 }
280 281
281 void DownloadFileManager::DownloadFinished(int id, DownloadBuffer* buffer) { 282 void DownloadFileManager::DownloadFinished(int id, DownloadBuffer* buffer) {
282 DCHECK(MessageLoop::current() == file_loop_); 283 DCHECK(MessageLoop::current() == file_loop_);
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod( 573 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(
573 this, &DownloadFileManager::StopUpdateTimer)); 574 this, &DownloadFileManager::StopUpdateTimer));
574 } 575 }
575 576
576 // static 577 // static
577 void DownloadFileManager::DeleteFile(const FilePath& path) { 578 void DownloadFileManager::DeleteFile(const FilePath& path) {
578 // Make sure we only delete files. 579 // Make sure we only delete files.
579 if (!file_util::DirectoryExists(path)) 580 if (!file_util::DirectoryExists(path))
580 file_util::Delete(path, false); 581 file_util::Delete(path, false);
581 } 582 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_file.h ('k') | chrome/browser/download/save_file_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698