diff options
Diffstat (limited to 'chrome/browser/plugin_installer.cc')
-rw-r--r-- | chrome/browser/plugin_installer.cc | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/chrome/browser/plugin_installer.cc b/chrome/browser/plugin_installer.cc index 00d6c49..bbdfa6e 100644 --- a/chrome/browser/plugin_installer.cc +++ b/chrome/browser/plugin_installer.cc @@ -1,9 +1,16 @@ -// 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. #include "chrome/browser/plugin_installer.h" +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/process.h" +#include "chrome/browser/platform_util.h" +#include "chrome/browser/plugin_download_helper.h" +#include "chrome/browser/plugin_installer_observer.h" + PluginInstaller::~PluginInstaller() { } @@ -12,9 +19,40 @@ PluginInstaller::PluginInstaller(const std::string& identifier, const GURL& help_url, const string16& name, bool url_for_display) - : identifier_(identifier), + : state_(kStateIdle), + identifier_(identifier), plugin_url_(plugin_url), help_url_(help_url), name_(name), url_for_display_(url_for_display) { } + +void PluginInstaller::AddObserver(PluginInstallerObserver* observer) { + observers_.AddObserver(observer); +} + +void PluginInstaller::RemoveObserver(PluginInstallerObserver* observer) { + observers_.RemoveObserver(observer); +} + +void PluginInstaller::StartInstalling( + net::URLRequestContextGetter* request_context) { + DCHECK(state_ == kStateIdle); + DCHECK(!url_for_display_); + state_ = kStateDownloading; + FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidStartDownload()); + // |downloader| will delete itself after running the callback. + PluginDownloadUrlHelper* downloader = new PluginDownloadUrlHelper(); + downloader->InitiateDownload( + plugin_url_, + request_context, + base::Bind(&PluginInstaller::DidFinishDownload, base::Unretained(this))); +} + +void PluginInstaller::DidFinishDownload(const FilePath& downloaded_file) { + DCHECK(state_ == kStateDownloading); + state_ = kStateIdle; + DVLOG(1) << "Plug-in installer is at \"" << downloaded_file.value() << "\""; + FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidFinishDownload()); + platform_util::OpenItem(downloaded_file); +} |