Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1740)

Unified Diff: chrome/browser/plugins/plugin_observer.cc

Issue 2154773002: Implement Just-In-Time Flash updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Through #39 + pepper_flash_component_installer compile fix Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/plugins/plugin_observer.cc
diff --git a/chrome/browser/plugins/plugin_observer.cc b/chrome/browser/plugins/plugin_observer.cc
index 605ca81f7bbd0f8738585177f75208f1d3db9541..a1870acb7eb6f749d114a9ac184fd1aefc3af8b1 100644
--- a/chrome/browser/plugins/plugin_observer.cc
+++ b/chrome/browser/plugins/plugin_observer.cc
@@ -9,6 +9,7 @@
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/debug/crash_logging.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
@@ -23,6 +24,7 @@
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/generated_resources.h"
+#include "components/component_updater/component_updater_service.h"
#include "components/content_settings/content/common/content_settings_messages.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
@@ -164,7 +166,7 @@ ReloadPluginInfoBarDelegate::ReloadPluginInfoBarDelegate(
: controller_(controller),
message_(message) {}
-ReloadPluginInfoBarDelegate::~ReloadPluginInfoBarDelegate(){ }
+ReloadPluginInfoBarDelegate::~ReloadPluginInfoBarDelegate() {}
infobars::InfoBarDelegate::InfoBarIdentifier
ReloadPluginInfoBarDelegate::GetIdentifier() const {
@@ -255,6 +257,39 @@ class PluginObserver::PluginPlaceholderHost : public PluginInstallerObserver {
};
#endif // defined(ENABLE_PLUGIN_INSTALLATION)
+PluginObserver::ComponentObserver::ComponentObserver(
+ PluginObserver* observer,
+ int routing_id,
+ const std::string& component_id)
+ : observer_(observer),
+ routing_id_(routing_id),
+ component_id_(component_id) {}
+
+void PluginObserver::ComponentObserver::OnEvent(Events event,
+ const std::string& id) {
+ if (id != component_id_)
+ return;
+ switch (event) {
+ case Events::COMPONENT_UPDATED:
+ observer_->Send(
+ new ChromeViewMsg_PluginComponentUpdateSuccess(routing_id_));
+ observer_->RemoveComponentObserver(routing_id_);
+ break;
+ case Events::COMPONENT_UPDATE_FOUND:
+ observer_->Send(
+ new ChromeViewMsg_PluginComponentUpdateDownloading(routing_id_));
+ break;
+ case Events::COMPONENT_NOT_UPDATED:
+ observer_->Send(
+ new ChromeViewMsg_PluginComponentUpdateFailure(routing_id_));
+ observer_->RemoveComponentObserver(routing_id_);
+ break;
+ default:
+ // No message to send.
+ break;
+ }
+}
+
PluginObserver::PluginObserver(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
weak_ptr_factory_(this) {
@@ -264,6 +299,10 @@ PluginObserver::~PluginObserver() {
#if defined(ENABLE_PLUGIN_INSTALLATION)
STLDeleteValues(&plugin_placeholders_);
#endif
+ auto cus = g_browser_process->component_updater();
+ for (const auto& observer : component_observers_) {
+ cus->RemoveObserver(observer.second.get());
Bernhard Bauer 2016/07/29 09:14:24 If you move this to the ComponentObserver destruct
waffles 2016/07/29 21:07:25 Good idea, thanks. Done.
+ }
}
void PluginObserver::PluginCrashed(const base::FilePath& plugin_path,
@@ -321,6 +360,8 @@ bool PluginObserver::OnMessageReceived(
IPC_BEGIN_MESSAGE_MAP(PluginObserver, message)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin,
OnBlockedOutdatedPlugin)
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedComponentUpdatedPlugin,
+ OnBlockedComponentUpdatedPlugin)
#if defined(ENABLE_PLUGIN_INSTALLATION)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost,
OnRemovePluginPlaceholderHost)
@@ -359,14 +400,30 @@ void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id,
#endif // defined(ENABLE_PLUGIN_INSTALLATION)
}
+void PluginObserver::OnBlockedComponentUpdatedPlugin(
+ int placeholder_id,
+ const std::string& identifier) {
+ component_updater::ComponentUpdateService* cus =
+ g_browser_process->component_updater();
+ auto observer =
+ base::MakeUnique<ComponentObserver>(this, placeholder_id, identifier);
+ cus->AddObserver(observer.get());
+ component_observers_[placeholder_id] = std::move(observer);
+ cus->GetOnDemandUpdater().OnDemandUpdate(identifier);
+}
+
+void PluginObserver::RemoveComponentObserver(int placeholder_id) {
+ auto it = component_observers_.find(placeholder_id);
+ DCHECK(it != component_observers_.end());
+ g_browser_process->component_updater()->RemoveObserver(it->second.get());
+ component_observers_.erase(it);
+}
+
#if defined(ENABLE_PLUGIN_INSTALLATION)
void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) {
std::map<int, PluginPlaceholderHost*>::iterator it =
plugin_placeholders_.find(placeholder_id);
- if (it == plugin_placeholders_.end()) {
- NOTREACHED();
- return;
- }
+ DCHECK(it != plugin_placeholders_.end());
delete it->second;
plugin_placeholders_.erase(it);
}

Powered by Google App Engine
This is Rietveld 408576698