Chromium Code Reviews| 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..38639608a765d395287568c17f3c2815974ccfcb 100644 |
| --- a/chrome/browser/plugins/plugin_observer.cc |
| +++ b/chrome/browser/plugins/plugin_observer.cc |
| @@ -23,6 +23,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" |
| @@ -255,6 +256,50 @@ class PluginObserver::PluginPlaceholderHost : public PluginInstallerObserver { |
| }; |
| #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
| +class ComponentObserver : public update_client::UpdateClient::Observer { |
| + using Events = update_client::UpdateClient::Observer::Events; |
|
Bernhard Bauer
2016/07/28 10:25:10
Should this come inside of the public: section?
waffles
2016/07/28 20:06:27
Done.
|
| + |
| + public: |
| + ComponentObserver( |
| + PluginObserver* observer, |
| + int routing_id, |
| + const std::string& component_id) |
| + : observer_(observer), |
| + routing_id_(routing_id), |
|
Bernhard Bauer
2016/07/28 10:25:10
I think these should be aligned with |observer_|?
waffles
2016/07/28 20:06:27
Done.
|
| + component_id_(component_id) { |
| + } |
| + |
| + void OnEvent(Events event, const std::string& id) override { |
| + if (id != component_id_) { |
|
Bernhard Bauer
2016/07/28 10:25:10
Nit: no braces for single-line bodies.
waffles
2016/07/28 20:06:27
Done.
|
| + 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; |
| + } |
| + } |
| + |
| + private: |
| + PluginObserver* observer_; |
| + int routing_id_; |
| + std::string component_id_; |
|
Bernhard Bauer
2016/07/28 10:25:10
DISALLOW_COPY_AND_ASSIGN?
waffles
2016/07/28 20:06:27
Done.
|
| +}; |
| + |
| PluginObserver::PluginObserver(content::WebContents* web_contents) |
| : content::WebContentsObserver(web_contents), |
| weak_ptr_factory_(this) { |
| @@ -321,6 +366,8 @@ bool PluginObserver::OnMessageReceived( |
| IPC_BEGIN_MESSAGE_MAP(PluginObserver, message) |
| IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedOutdatedPlugin, |
| OnBlockedOutdatedPlugin) |
| + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_BlockedUpdatePlugin, |
| + OnBlockedUpdatePlugin) |
| #if defined(ENABLE_PLUGIN_INSTALLATION) |
| IPC_MESSAGE_HANDLER(ChromeViewHostMsg_RemovePluginPlaceholderHost, |
| OnRemovePluginPlaceholderHost) |
| @@ -359,6 +406,29 @@ void PluginObserver::OnBlockedOutdatedPlugin(int placeholder_id, |
| #endif // defined(ENABLE_PLUGIN_INSTALLATION) |
| } |
| +void PluginObserver::OnBlockedUpdatePlugin(int placeholder_id, |
| + const std::string& identifier) { |
| + ComponentObserver* observer = |
| + new ComponentObserver(this, placeholder_id, identifier); |
| + component_observers_[placeholder_id] = observer; |
| + component_updater::ComponentUpdateService* cus = |
| + g_browser_process->component_updater(); |
| + cus->AddObserver(observer); |
| + cus->GetOnDemandUpdater().OnDemandUpdate(identifier); |
| +} |
| + |
| +void PluginObserver::RemoveComponentObserver(int placeholder_id) { |
| + std::map<int, ComponentObserver*>::iterator it = |
| + component_observers_.find(placeholder_id); |
| + if (it == component_observers_.end()) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + g_browser_process->component_updater()->RemoveObserver(it->second); |
| + delete it->second; |
| + component_observers_.erase(it); |
| +} |
| + |
| #if defined(ENABLE_PLUGIN_INSTALLATION) |
| void PluginObserver::OnRemovePluginPlaceholderHost(int placeholder_id) { |
| std::map<int, PluginPlaceholderHost*>::iterator it = |