download_file.cc revision 731df977c0511bca2206b5f333555b1205ff1f43
1// Copyright (c) 2010 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/download/download_file.h" 6 7#include "base/file_util.h" 8#include "chrome/browser/browser_thread.h" 9#include "chrome/browser/download/download_manager.h" 10#include "chrome/browser/download/download_util.h" 11#include "chrome/browser/history/download_create_info.h" 12 13DownloadFile::DownloadFile(const DownloadCreateInfo* info, 14 DownloadManager* download_manager) 15 : BaseFile(info->save_info.file_path, 16 info->url, 17 info->referrer_url, 18 info->received_bytes, 19 info->save_info.file_stream), 20 id_(info->download_id), 21 child_id_(info->child_id), 22 request_id_(info->request_id), 23 download_manager_(download_manager) { 24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 25 26} 27 28DownloadFile::~DownloadFile() { 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 30} 31 32void DownloadFile::DeleteCrDownload() { 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 34 FilePath crdownload = download_util::GetCrDownloadPath(full_path_); 35 file_util::Delete(crdownload, false); 36} 37 38void DownloadFile::CancelDownloadRequest(ResourceDispatcherHost* rdh) { 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 40 BrowserThread::PostTask( 41 BrowserThread::IO, FROM_HERE, 42 NewRunnableFunction(&download_util::CancelDownloadRequest, 43 rdh, 44 child_id_, 45 request_id_)); 46} 47 48DownloadManager* DownloadFile::GetDownloadManager() { 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 50 return download_manager_.get(); 51} 52