| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ | 5 #ifndef CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ |
| 6 #define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ | 6 #define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include "base/callback.h" |
| 10 #include "base/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/common/url_fetcher_delegate.h" |
| 13 #include "googleurl/src/gurl.h" |
| 10 | 14 |
| 11 #include "build/build_config.h" | 15 namespace base { |
| 12 #include "base/file_path.h" | 16 class MessageLoopProxy; |
| 13 #include "base/message_loop_proxy.h" | 17 } |
| 14 #include "content/public/common/url_fetcher_delegate.h" | |
| 15 #include "net/base/file_stream.h" | |
| 16 #include "net/url_request/url_request.h" | |
| 17 #include "ui/gfx/native_widget_types.h" | |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 class URLRequestContextGetter; | 20 class URLRequestContextGetter; |
| 21 } | 21 } |
| 22 | 22 |
| 23 // The PluginDownloadUrlHelper is used to handle one download URL request | 23 // The PluginDownloadUrlHelper is used to handle one download URL request |
| 24 // from the plugin. Each download request is handled by a new instance | 24 // from the plugin. Each download request is handled by a new instance |
| 25 // of this class. | 25 // of this class. |
| 26 class PluginDownloadUrlHelper : public content::URLFetcherDelegate { | 26 class PluginDownloadUrlHelper : public content::URLFetcherDelegate { |
| 27 public: | 27 public: |
| 28 // The delegate receives notification about the status of downloads | 28 typedef base::Callback<void(FilePath)> DownloadFinishedCallback; |
| 29 // initiated. | |
| 30 class DownloadDelegate { | |
| 31 public: | |
| 32 virtual ~DownloadDelegate() {} | |
| 33 | 29 |
| 34 virtual void OnDownloadCompleted(const FilePath& download_path, | 30 PluginDownloadUrlHelper(); |
| 35 bool success) {} | 31 virtual ~PluginDownloadUrlHelper(); |
| 36 }; | |
| 37 | 32 |
| 38 PluginDownloadUrlHelper(const std::string& download_url, | 33 void InitiateDownload(const GURL& download_url, |
| 39 gfx::NativeWindow caller_window, | 34 net::URLRequestContextGetter* request_context, |
| 40 PluginDownloadUrlHelper::DownloadDelegate* delegate); | 35 const DownloadFinishedCallback& callback); |
| 41 ~PluginDownloadUrlHelper(); | |
| 42 | |
| 43 void InitiateDownload(net::URLRequestContextGetter* request_context, | |
| 44 base::MessageLoopProxy* file_thread_proxy); | |
| 45 | 36 |
| 46 // content::URLFetcherDelegate | 37 // content::URLFetcherDelegate |
| 47 virtual void OnURLFetchComplete(const content::URLFetcher* source); | 38 virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE; |
| 48 | 39 |
| 49 void OnDownloadCompleted(net::URLRequest* request); | 40 private: |
| 41 // Renames the file (which was downloaded to a temporary file) to the filename |
| 42 // of the download URL. |
| 43 void RenameDownloadedFile(); |
| 50 | 44 |
| 51 protected: | 45 // Runs the callback and deletes itself. |
| 46 void RunCallback(); |
| 47 |
| 52 // The download file request initiated by the plugin. | 48 // The download file request initiated by the plugin. |
| 53 scoped_ptr<content::URLFetcher> download_file_fetcher_; | 49 scoped_ptr<content::URLFetcher> download_file_fetcher_; |
| 54 // TODO(port): this comment doesn't describe the situation on Posix. | |
| 55 // The window handle for sending the WM_COPYDATA notification, | |
| 56 // indicating that the download completed. | |
| 57 gfx::NativeWindow download_file_caller_window_; | |
| 58 | 50 |
| 59 std::string download_url_; | 51 GURL download_url_; |
| 52 FilePath downloaded_file_; |
| 60 | 53 |
| 61 PluginDownloadUrlHelper::DownloadDelegate* delegate_; | 54 DownloadFinishedCallback callback_; |
| 62 | 55 |
| 63 DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper); | 56 DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper); |
| 64 }; | 57 }; |
| 65 | 58 |
| 66 #endif // CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ | 59 #endif // CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_ |
| OLD | NEW |