download_file.cc revision ddb351dbec246cf1fab5ec20d2d5520909041de1
12949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project// Copyright (c) 2011 The Chromium Authors. All rights reserved.
22949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project// Use of this source code is governed by a BSD-style license that can be
32949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project// found in the LICENSE file.
42949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
52949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "chrome/browser/download/download_file.h"
62949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
72949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include <string>
82949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
92949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "base/file_util.h"
102949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "base/stringprintf.h"
112949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "chrome/browser/download/download_manager.h"
122949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "chrome/browser/download/download_util.h"
132949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "chrome/browser/history/download_create_info.h"
142949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project#include "content/browser/browser_thread.h"
152949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
162949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source ProjectDownloadFile::DownloadFile(const DownloadCreateInfo* info,
172949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                           DownloadManager* download_manager)
182949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project    : BaseFile(info->save_info.file_path,
192949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project               info->url(),
202949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project               info->referrer_url,
212949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project               info->received_bytes,
222949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project               info->save_info.file_stream),
232949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project      id_(info->download_id),
242949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project      child_id_(info->child_id),
252949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project      request_id_(info->request_id),
262949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project      download_manager_(download_manager) {
272949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
282949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
292949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project}
302949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
312949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source ProjectDownloadFile::~DownloadFile() {
322949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
332949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project}
342949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
352949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectvoid DownloadFile::CancelDownloadRequest(ResourceDispatcherHost* rdh) {
362949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
372949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project  BrowserThread::PostTask(
382949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project      BrowserThread::IO, FROM_HERE,
392949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project      NewRunnableFunction(&download_util::CancelDownloadRequest,
402949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                          rdh,
412949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                          child_id_,
422949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                          request_id_));
432949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project}
442949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
452949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source ProjectDownloadManager* DownloadFile::GetDownloadManager() {
462949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
472949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project  return download_manager_.get();
482949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project}
492949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project
502949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Projectstd::string DownloadFile::DebugString() const {
512949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project  return base::StringPrintf("{"
522949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            " full_path_ = " "\"%s\""
532949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            " id_ = " "%d"
542949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            " child_id_ = " "%d"
552949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            " request_id_ = " "%d"
562949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            " Base File = %s"
572949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            " }",
582949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            full_path_.value().c_str(),
592949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            id_,
602949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            child_id_,
612949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            request_id_,
622949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project                            BaseFile::DebugString().c_str());
632949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project}
642949f58a438f6fd85f66a8b7ed4708042cde4b37The Android Open Source Project