Directly download and open plug-in installer files.

[email protected]

BUG=62079
TEST=none


Review URL: http://codereview.chromium.org/9070001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116308 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/plugin_download_helper.h b/chrome/browser/plugin_download_helper.h
index 18d3f8f..83036a3b 100644
--- a/chrome/browser/plugin_download_helper.h
+++ b/chrome/browser/plugin_download_helper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
 
@@ -6,15 +6,15 @@
 #define CHROME_BROWSER_PLUGIN_DOWNLOAD_HELPER_H_
 #pragma once
 
-#include <string>
-
-#include "build/build_config.h"
+#include "base/callback.h"
 #include "base/file_path.h"
-#include "base/message_loop_proxy.h"
+#include "base/memory/scoped_ptr.h"
 #include "content/public/common/url_fetcher_delegate.h"
-#include "net/base/file_stream.h"
-#include "net/url_request/url_request.h"
-#include "ui/gfx/native_widget_types.h"
+#include "googleurl/src/gurl.h"
+
+namespace base {
+class MessageLoopProxy;
+}
 
 namespace net {
 class URLRequestContextGetter;
@@ -25,40 +25,33 @@
 // of this class.
 class PluginDownloadUrlHelper : public content::URLFetcherDelegate {
  public:
-  // The delegate receives notification about the status of downloads
-  // initiated.
-  class DownloadDelegate {
-   public:
-    virtual ~DownloadDelegate() {}
+  typedef base::Callback<void(const FilePath&)> DownloadFinishedCallback;
 
-    virtual void OnDownloadCompleted(const FilePath& download_path,
-                                     bool success) {}
-  };
+  PluginDownloadUrlHelper();
+  virtual ~PluginDownloadUrlHelper();
 
-  PluginDownloadUrlHelper(const std::string& download_url,
-                          gfx::NativeWindow caller_window,
-                          PluginDownloadUrlHelper::DownloadDelegate* delegate);
-  ~PluginDownloadUrlHelper();
-
-  void InitiateDownload(net::URLRequestContextGetter* request_context,
-                        base::MessageLoopProxy* file_thread_proxy);
+  void InitiateDownload(const GURL& download_url,
+                        net::URLRequestContextGetter* request_context,
+                        const DownloadFinishedCallback& callback);
 
   // content::URLFetcherDelegate
-  virtual void OnURLFetchComplete(const content::URLFetcher* source);
+  virtual void OnURLFetchComplete(const content::URLFetcher* source) OVERRIDE;
 
-  void OnDownloadCompleted(net::URLRequest* request);
+ private:
+  // Renames the file (which was downloaded to a temporary file) to the filename
+  // of the download URL.
+  void RenameDownloadedFile();
 
- protected:
+  // Runs the callback and deletes itself.
+  void RunCallback();
+
   // The download file request initiated by the plugin.
   scoped_ptr<content::URLFetcher> download_file_fetcher_;
-  // TODO(port): this comment doesn't describe the situation on Posix.
-  // The window handle for sending the WM_COPYDATA notification,
-  // indicating that the download completed.
-  gfx::NativeWindow download_file_caller_window_;
 
-  std::string download_url_;
+  GURL download_url_;
+  FilePath downloaded_file_;
 
-  PluginDownloadUrlHelper::DownloadDelegate* delegate_;
+  DownloadFinishedCallback callback_;
 
   DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper);
 };