1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// 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_PLUGINS_PLUGIN_INSTALLER_H_ 6#define CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_ 7 8#include "base/gtest_prod_util.h" 9#include "base/observer_list.h" 10#include "base/strings/string16.h" 11#include "base/version.h" 12#include "chrome/browser/plugins/plugin_metadata.h" 13#include "content/public/browser/download_interrupt_reasons.h" 14#include "content/public/browser/download_item.h" 15#include "url/gurl.h" 16 17class PluginInstallerObserver; 18class WeakPluginInstallerObserver; 19 20namespace content { 21class DownloadManager; 22class WebContents; 23struct WebPluginInfo; 24} 25 26class PluginInstaller : public content::DownloadItem::Observer { 27 public: 28 enum InstallerState { 29 INSTALLER_STATE_IDLE, 30 INSTALLER_STATE_DOWNLOADING, 31 }; 32 33 PluginInstaller(); 34 virtual ~PluginInstaller(); 35 36 virtual void OnDownloadUpdated(content::DownloadItem* download) OVERRIDE; 37 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE; 38 39 void AddObserver(PluginInstallerObserver* observer); 40 void RemoveObserver(PluginInstallerObserver* observer); 41 42 void AddWeakObserver(WeakPluginInstallerObserver* observer); 43 void RemoveWeakObserver(WeakPluginInstallerObserver* observer); 44 45 InstallerState state() const { return state_; } 46 47 // Opens the download URL in a new tab. 48 void OpenDownloadURL(const GURL& plugin_url, 49 content::WebContents* web_contents); 50 51 // Starts downloading the download URL and opens the downloaded file 52 // when finished. 53 void StartInstalling(const GURL& plugin_url, 54 content::WebContents* web_contents); 55 56 private: 57 void StartInstallingWithDownloadManager( 58 const GURL& plugin_url, 59 content::WebContents* web_contents, 60 content::DownloadManager* download_manager); 61 void DownloadStarted(content::DownloadItem* item, 62 content::DownloadInterruptReason interrupt_reason); 63 void DownloadError(const std::string& msg); 64 void DownloadCancelled(); 65 66 InstallerState state_; 67 ObserverList<PluginInstallerObserver> observers_; 68 int strong_observer_count_; 69 ObserverList<WeakPluginInstallerObserver> weak_observers_; 70 71 FRIEND_TEST_ALL_PREFIXES(PluginInstallerTest, 72 StartInstalling_SuccessfulDownload); 73 FRIEND_TEST_ALL_PREFIXES(PluginInstallerTest, StartInstalling_FailedStart); 74 FRIEND_TEST_ALL_PREFIXES(PluginInstallerTest, StartInstalling_Interrupted); 75 DISALLOW_COPY_AND_ASSIGN(PluginInstaller); 76}; 77 78#endif // CHROME_BROWSER_PLUGINS_PLUGIN_INSTALLER_H_ 79