1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
// 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() {
}
PluginInstaller::PluginInstaller(const std::string& identifier,
const GURL& plugin_url,
const GURL& help_url,
const string16& name,
bool url_for_display)
: 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)),
base::Bind(&PluginInstaller::DownloadError, 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);
}
void PluginInstaller::DownloadError(const std::string& msg) {
FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg));
}
|