Implement Just-In-Time Flash updates.

The basic approach is that every component supplies a list of MIME types that it can handle as a plugin during registration with the component updater. If plugin content is encountered that we do not have a plugin for, the filter will ask the component updater if an implementation is available. If so, it will initiate an on-demand update for the plugin and register an observer to watch for the update completion. In the meantime, the renderer will display a plugin placeholder indicating that a download is in progress. Once/if the update is successful, the placeholder is notified and will re-evaluate the presence of a suitable plugin for the content. This second pass should catch any blocked-by-policy, power-saver, etc restrictions.

BUG=624067

Review-Url: https://codereview.chromium.org/2154773002
Cr-Commit-Position: refs/heads/master@{#409217}
diff --git a/components/component_updater/component_updater_service.cc b/components/component_updater/component_updater_service.cc
index ab4ad19..4964bb0 100644
--- a/components/component_updater/component_updater_service.cc
+++ b/components/component_updater/component_updater_service.cc
@@ -21,6 +21,7 @@
 #include "base/metrics/histogram_macros.h"
 #include "base/sequenced_task_runner.h"
 #include "base/single_thread_task_runner.h"
+#include "base/strings/utf_string_conversions.h"
 #include "base/threading/sequenced_worker_pool.h"
 #include "base/threading/thread_checker.h"
 #include "base/threading/thread_task_runner_handle.h"
@@ -49,6 +50,10 @@
 
 namespace component_updater {
 
+ComponentInfo::ComponentInfo(const std::string& id, const base::string16& name)
+    : id(id), name(name) {}
+ComponentInfo::~ComponentInfo() {}
+
 CrxUpdateService::CrxUpdateService(
     const scoped_refptr<Configurator>& config,
     const scoped_refptr<UpdateClient>& update_client)
@@ -122,6 +127,8 @@
 
   components_.insert(std::make_pair(id, component));
   components_order_.push_back(id);
+  for (const auto& mime_type : component.handled_mime_types)
+    component_ids_by_mime_type_[mime_type] = id;
 
   // Create an initial state for this component. The state is mutated in
   // response to events from the UpdateClient instance.
@@ -185,6 +192,19 @@
   return ids;
 }
 
+std::unique_ptr<ComponentInfo> CrxUpdateService::GetComponentForMimeType(
+    const std::string& mime_type) const {
+  DCHECK(thread_checker_.CalledOnValidThread());
+  const auto it = component_ids_by_mime_type_.find(mime_type);
+  if (it == component_ids_by_mime_type_.end())
+    return nullptr;
+  const auto component = GetComponent(it->second);
+  if (!component)
+    return nullptr;
+  return base::MakeUnique<ComponentInfo>(GetCrxComponentID(*component),
+                                         base::UTF8ToUTF16(component->name));
+}
+
 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() {
   DCHECK(thread_checker_.CalledOnValidThread());
   return *this;