summaryrefslogtreecommitdiff
path: root/chromium/content/browser/download/download_request_handle.cc
blob: f5979b945ad8a0afa38a233ae426bc166f2b4c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/download/download_request_handle.h"

#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"

namespace content {

DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {}

DownloadRequestHandle::DownloadRequestHandle(
    const DownloadRequestHandle& other) = default;

DownloadRequestHandle::~DownloadRequestHandle() {}

DownloadRequestHandle::DownloadRequestHandle() {}

DownloadRequestHandle::DownloadRequestHandle(
    const base::WeakPtr<DownloadResourceHandler>& handler,
    const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter)
    : handler_(handler), web_contents_getter_(web_contents_getter) {
  DCHECK(handler_.get());
}

WebContents* DownloadRequestHandle::GetWebContents() const {
  return web_contents_getter_.is_null() ? nullptr : web_contents_getter_.Run();
}

DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
  WebContents* web_contents = GetWebContents();
  if (web_contents == nullptr)
    return nullptr;
  BrowserContext* context = web_contents->GetBrowserContext();
  if (context == nullptr)
    return nullptr;
  return BrowserContext::GetDownloadManager(context);
}

void DownloadRequestHandle::PauseRequest() const {
  BrowserThread::PostTask(
      BrowserThread::IO, FROM_HERE,
      base::Bind(&DownloadResourceHandler::PauseRequest, handler_));
}

void DownloadRequestHandle::ResumeRequest() const {
  BrowserThread::PostTask(
      BrowserThread::IO, FROM_HERE,
      base::Bind(&DownloadResourceHandler::ResumeRequest, handler_));
}

void DownloadRequestHandle::CancelRequest() const {
  BrowserThread::PostTask(
      BrowserThread::IO, FROM_HERE,
      base::Bind(&DownloadResourceHandler::CancelRequest, handler_));
}

}  // namespace content