| 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 #include "chrome/browser/plugin_installer.h" | 5 #include "chrome/browser/plugin_installer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/process.h" |
| 10 #include "chrome/browser/platform_util.h" |
| 11 #include "chrome/browser/plugin_download_helper.h" |
| 12 #include "chrome/browser/plugin_installer_observer.h" |
| 13 |
| 7 PluginInstaller::~PluginInstaller() { | 14 PluginInstaller::~PluginInstaller() { |
| 8 } | 15 } |
| 9 | 16 |
| 10 PluginInstaller::PluginInstaller(const std::string& identifier, | 17 PluginInstaller::PluginInstaller(const std::string& identifier, |
| 11 const GURL& plugin_url, | 18 const GURL& plugin_url, |
| 12 const GURL& help_url, | 19 const GURL& help_url, |
| 13 const string16& name, | 20 const string16& name, |
| 14 bool url_for_display) | 21 bool url_for_display) |
| 15 : identifier_(identifier), | 22 : state_(kStateIdle), |
| 23 identifier_(identifier), |
| 16 plugin_url_(plugin_url), | 24 plugin_url_(plugin_url), |
| 17 help_url_(help_url), | 25 help_url_(help_url), |
| 18 name_(name), | 26 name_(name), |
| 19 url_for_display_(url_for_display) { | 27 url_for_display_(url_for_display) { |
| 20 } | 28 } |
| 29 |
| 30 void PluginInstaller::AddObserver(PluginInstallerObserver* observer) { |
| 31 observers_.AddObserver(observer); |
| 32 } |
| 33 |
| 34 void PluginInstaller::RemoveObserver(PluginInstallerObserver* observer) { |
| 35 observers_.RemoveObserver(observer); |
| 36 } |
| 37 |
| 38 void PluginInstaller::StartInstalling( |
| 39 net::URLRequestContextGetter* request_context) { |
| 40 DCHECK(state_ == kStateIdle); |
| 41 DCHECK(!url_for_display_); |
| 42 state_ = kStateDownloading; |
| 43 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidStartDownload()); |
| 44 PluginDownloadUrlHelper* downloader = new PluginDownloadUrlHelper(); |
| 45 downloader->InitiateDownload( |
| 46 plugin_url_, |
| 47 request_context, |
| 48 base::Bind(&PluginInstaller::DidFinishDownload, base::Unretained(this))); |
| 49 } |
| 50 |
| 51 void PluginInstaller::DidFinishDownload(const FilePath& downloaded_file) { |
| 52 DCHECK(state_ == kStateDownloading); |
| 53 state_ = kStateIdle; |
| 54 LOG(ERROR) << "Plug-in installer is at \"" << downloaded_file.value() << "\""; |
| 55 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DidFinishDownload()); |
| 56 base::ProcessHandle handle = base::kNullProcessHandle; |
| 57 platform_util::OpenItem(downloaded_file, &handle); |
| 58 #if defined(OS_WIN) |
| 59 if (handle != kNullProcessHandle) { |
| 60 installation_process_monitor_.Initialize( |
| 61 handle, |
| 62 base::Bind(&PluginInstaller::DidFinishInstallation, |
| 63 base::Unretained(this))); |
| 64 } |
| 65 #endif |
| 66 } |
| 67 |
| 68 void PluginInstaller::DidFinishInstallation() { |
| 69 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, |
| 70 DidFinishInstallation()); |
| 71 } |
| OLD | NEW |