blob: 834088874f953101dc4c1050b6818e74fda72243 [file] [log] [blame]
[email protected]0dd9e8b2012-01-04 13:36:161// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]fd3ad512010-09-25 14:08:512// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_
6#define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_
7#pragma once
8
[email protected]0dd9e8b2012-01-04 13:36:169#include "base/callback.h"
[email protected]fd3ad512010-09-25 14:08:5110#include "base/file_path.h"
[email protected]0dd9e8b2012-01-04 13:36:1611#include "base/memory/scoped_ptr.h"
[email protected]c530c852011-10-24 18:18:3412#include "content/public/common/url_fetcher_delegate.h"
[email protected]0dd9e8b2012-01-04 13:36:1613#include "googleurl/src/gurl.h"
14
15namespace base {
16class MessageLoopProxy;
17}
[email protected]fd3ad512010-09-25 14:08:5118
[email protected]c530c852011-10-24 18:18:3419namespace net {
20class URLRequestContextGetter;
21}
22
[email protected]fd3ad512010-09-25 14:08:5123// The PluginDownloadUrlHelper is used to handle one download URL request
24// from the plugin. Each download request is handled by a new instance
25// of this class.
[email protected]c530c852011-10-24 18:18:3426class PluginDownloadUrlHelper : public content::URLFetcherDelegate {
[email protected]fd3ad512010-09-25 14:08:5127 public:
[email protected]0dd9e8b2012-01-04 13:36:1628 typedef base::Callback<void(const FilePath&)> DownloadFinishedCallback;
[email protected]725f6882012-01-13 18:50:0629 typedef base::Callback<void(const std::string&)> ErrorCallback;
[email protected]fd3ad512010-09-25 14:08:5130
[email protected]0dd9e8b2012-01-04 13:36:1631 PluginDownloadUrlHelper();
32 virtual ~PluginDownloadUrlHelper();
[email protected]fd3ad512010-09-25 14:08:5133
[email protected]0dd9e8b2012-01-04 13:36:1634 void InitiateDownload(const GURL& download_url,
35 net::URLRequestContextGetter* request_context,
[email protected]725f6882012-01-13 18:50:0636 const DownloadFinishedCallback& callback,
37 const ErrorCallback& error_callback);
[email protected]fd3ad512010-09-25 14:08:5138
[email protected]c530c852011-10-24 18:18:3439 // content::URLFetcherDelegate
[email protected]0dd9e8b2012-01-04 13:36:1640 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
[email protected]fd3ad512010-09-25 14:08:5141
[email protected]0dd9e8b2012-01-04 13:36:1642 private:
43 // Renames the file (which was downloaded to a temporary file) to the filename
44 // of the download URL.
45 void RenameDownloadedFile();
[email protected]fd3ad512010-09-25 14:08:5146
[email protected]725f6882012-01-13 18:50:0647 // Runs the success callback and deletes itself.
48 void RunFinishedCallback();
49
50 // Runs the error callback and deletes itself.
51 void RunErrorCallback(const std::string& error);
[email protected]0dd9e8b2012-01-04 13:36:1652
[email protected]fd3ad512010-09-25 14:08:5153 // The download file request initiated by the plugin.
[email protected]7cc6e5632011-10-25 17:56:1254 scoped_ptr<content::URLFetcher> download_file_fetcher_;
[email protected]fd3ad512010-09-25 14:08:5155
[email protected]0dd9e8b2012-01-04 13:36:1656 GURL download_url_;
57 FilePath downloaded_file_;
[email protected]fd3ad512010-09-25 14:08:5158
[email protected]725f6882012-01-13 18:50:0659 DownloadFinishedCallback download_finished_callback_;
60 ErrorCallback error_callback_;
[email protected]fd3ad512010-09-25 14:08:5161
62 DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper);
63};
64
[email protected]fd3ad512010-09-25 14:08:5165#endif // CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_