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

Side by Side Diff: chrome/browser/download/save_file_manager.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/save_file_manager.h ('k') | chrome/browser/download/save_package.cc » ('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/save_file_manager.h" 8 #include "chrome/browser/download/save_file_manager.h"
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.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/save_file.h" 16 #include "chrome/browser/download/save_file.h"
17 #include "chrome/browser/download/save_package.h" 17 #include "chrome/browser/download/save_package.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_contents.h" 19 #include "chrome/browser/tab_contents/tab_contents.h"
20 #include "chrome/browser/tab_contents/tab_util.h" 20 #include "chrome/browser/tab_contents/tab_util.h"
21 #include "chrome/browser/tab_contents/web_contents.h" 21 #include "chrome/browser/tab_contents/web_contents.h"
22 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/stl_util-inl.h" 23 #include "chrome/common/stl_util-inl.h"
24 #include "chrome/common/win_util.h" 24 #include "chrome/common/win_util.h"
25 #include "chrome/common/win_safe_util.h" 25 #include "chrome/common/win_safe_util.h"
26 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
27 #include "net/base/net_util.h" 27 #include "net/base/net_util.h"
28 #include "net/base/io_buffer.h"
28 #include "net/url_request/url_request_context.h" 29 #include "net/url_request/url_request_context.h"
29 30
30 SaveFileManager::SaveFileManager(MessageLoop* ui_loop, 31 SaveFileManager::SaveFileManager(MessageLoop* ui_loop,
31 MessageLoop* io_loop, 32 MessageLoop* io_loop,
32 ResourceDispatcherHost* rdh) 33 ResourceDispatcherHost* rdh)
33 : next_id_(0), 34 : next_id_(0),
34 ui_loop_(ui_loop), 35 ui_loop_(ui_loop),
35 io_loop_(io_loop), 36 io_loop_(io_loop),
36 resource_dispatcher_host_(rdh) { 37 resource_dispatcher_host_(rdh) {
37 DCHECK(ui_loop_); 38 DCHECK(ui_loop_);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 NewRunnableMethod(this, 265 NewRunnableMethod(this,
265 &SaveFileManager::OnStartSave, 266 &SaveFileManager::OnStartSave,
266 info)); 267 info));
267 } 268 }
268 269
269 // We do forward an update to the UI thread here, since we do not use timer to 270 // We do forward an update to the UI thread here, since we do not use timer to
270 // update the UI. If the user has canceled the saving action (in the UI 271 // update the UI. If the user has canceled the saving action (in the UI
271 // thread). We may receive a few more updates before the IO thread gets the 272 // thread). We may receive a few more updates before the IO thread gets the
272 // cancel message. We just delete the data since the SaveFile has been deleted. 273 // cancel message. We just delete the data since the SaveFile has been deleted.
273 void SaveFileManager::UpdateSaveProgress(int save_id, 274 void SaveFileManager::UpdateSaveProgress(int save_id,
274 char* data, 275 net::IOBuffer* data,
275 int data_len) { 276 int data_len) {
276 DCHECK(MessageLoop::current() == GetSaveLoop()); 277 DCHECK(MessageLoop::current() == GetSaveLoop());
277 SaveFile* save_file = LookupSaveFile(save_id); 278 SaveFile* save_file = LookupSaveFile(save_id);
278 if (save_file) { 279 if (save_file) {
279 bool write_success = save_file->AppendDataToFile(data, data_len); 280 bool write_success = save_file->AppendDataToFile(data->data(), data_len);
280 ui_loop_->PostTask(FROM_HERE, 281 ui_loop_->PostTask(FROM_HERE,
281 NewRunnableMethod(this, 282 NewRunnableMethod(this,
282 &SaveFileManager::OnUpdateSaveProgress, 283 &SaveFileManager::OnUpdateSaveProgress,
283 save_file->save_id(), 284 save_file->save_id(),
284 save_file->bytes_so_far(), 285 save_file->bytes_so_far(),
285 write_success)); 286 write_success));
286 } 287 }
287 delete [] data; 288 data->Release();
288 } 289 }
289 290
290 // The IO thread will call this when saving is completed or it got error when 291 // The IO thread will call this when saving is completed or it got error when
291 // fetching data. In the former case, we forward the message to OnSaveFinished 292 // fetching data. In the former case, we forward the message to OnSaveFinished
292 // in UI thread. In the latter case, the save ID will be -1, which means the 293 // in UI thread. In the latter case, the save ID will be -1, which means the
293 // saving action did not even start, so we need to call OnErrorFinished in UI 294 // saving action did not even start, so we need to call OnErrorFinished in UI
294 // thread, which will use the save URL to find corresponding request record and 295 // thread, which will use the save URL to find corresponding request record and
295 // delete it. 296 // delete it.
296 void SaveFileManager::SaveFinished(int save_id, 297 void SaveFileManager::SaveFinished(int save_id,
297 std::wstring save_url, 298 std::wstring save_url,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 if (it != save_file_map_.end()) { 573 if (it != save_file_map_.end()) {
573 SaveFile* save_file = it->second; 574 SaveFile* save_file = it->second;
574 DCHECK(!save_file->in_progress()); 575 DCHECK(!save_file->in_progress());
575 DeleteFile(save_file->full_path().c_str()); 576 DeleteFile(save_file->full_path().c_str());
576 delete save_file; 577 delete save_file;
577 save_file_map_.erase(it); 578 save_file_map_.erase(it);
578 } 579 }
579 } 580 }
580 } 581 }
581 582
OLDNEW
« no previous file with comments | « chrome/browser/download/save_file_manager.h ('k') | chrome/browser/download/save_package.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698