blob: 7db8b8b0ac89003d38c07a00e6fa0fae2d417b5d [file] [log] [blame]
[email protected]a3b85d852012-01-27 02:04:481// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]6be08ae2011-10-18 02:23:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_
6#define CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_
7
8#include <vector>
9
[email protected]d9b73c82011-11-09 23:17:2810#include "base/basictypes.h"
[email protected]c4f883a2012-02-03 17:02:0711#include "base/compiler_specific.h"
[email protected]6be08ae2011-10-18 02:23:2312#include "base/memory/ref_counted.h"
[email protected]d4af1e72011-10-21 17:45:4313#include "base/time.h"
[email protected]e67385f2011-12-21 06:00:5614#include "content/browser/plugin_service_impl.h"
[email protected]c4f883a2012-02-03 17:02:0715#include "content/public/browser/utility_process_host_client.h"
[email protected]d4af1e72011-10-21 17:45:4316#include "ipc/ipc_message.h"
[email protected]6be08ae2011-10-18 02:23:2317#include "webkit/plugins/webplugininfo.h"
18
[email protected]6be08ae2011-10-18 02:23:2319namespace base {
20class MessageLoopProxy;
21}
22
[email protected]c4f883a2012-02-03 17:02:0723namespace content {
24class UtilityProcessHost;
25}
26
[email protected]d4af1e72011-10-21 17:45:4327// This class is responsible for managing the out-of-process plugin loading on
28// POSIX systems. It primarily lives on the IO thread, but has a brief stay on
29// the FILE thread to iterate over plugin directories when it is first
30// constructed.
31//
32// The following is the algorithm used to load plugins:
33// 1. This asks the PluginList for the list of all potential plugins to attempt
34// to load. This is referred to as the canonical list.
35// 2. The child process this hosts is forked and the canonical list is sent to
36// it.
37// 3. The child process iterates over the canonical list, attempting to load
38// each plugin in the order specified by the list. It sends an IPC message
39// to the browser after each load, indicating success or failure. The two
40// processes synchronize the position in the vector that will be used to
41// attempt to load the next plugin.
42// 4. If the child dies during this process, the host forks another child and
43// resumes loading at the position past the plugin that it just attempted to
44// load, bypassing the problematic plugin.
45// 5. This algorithm continues until the canonical list has been walked to the
46// end, after which the list of loaded plugins is set on the PluginList and
47// the completion callback is run.
[email protected]c4f883a2012-02-03 17:02:0748class CONTENT_EXPORT PluginLoaderPosix
49 : public NON_EXPORTED_BASE(content::UtilityProcessHostClient),
50 public IPC::Message::Sender {
[email protected]6be08ae2011-10-18 02:23:2351 public:
[email protected]d4af1e72011-10-21 17:45:4352 PluginLoaderPosix();
53
54 // Must be called from the IO thread.
[email protected]e67385f2011-12-21 06:00:5655 void LoadPlugins(
56 scoped_refptr<base::MessageLoopProxy> target_loop,
57 const content::PluginService::GetPluginsCallback& callback);
[email protected]6be08ae2011-10-18 02:23:2358
[email protected]c4f883a2012-02-03 17:02:0759 // UtilityProcessHostClient:
[email protected]6be08ae2011-10-18 02:23:2360 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
62
[email protected]d4af1e72011-10-21 17:45:4363 // IPC::Message::Sender:
[email protected]edc64de2011-11-17 20:07:3864 virtual bool Send(IPC::Message* msg) OVERRIDE;
[email protected]d4af1e72011-10-21 17:45:4365
[email protected]6be08ae2011-10-18 02:23:2366 private:
[email protected]d4af1e72011-10-21 17:45:4367 struct PendingCallback {
68 PendingCallback(scoped_refptr<base::MessageLoopProxy> target_loop,
[email protected]e67385f2011-12-21 06:00:5669 const content::PluginService::GetPluginsCallback& callback);
[email protected]d4af1e72011-10-21 17:45:4370 ~PendingCallback();
71
72 scoped_refptr<base::MessageLoopProxy> target_loop;
[email protected]e67385f2011-12-21 06:00:5673 content::PluginService::GetPluginsCallback callback;
[email protected]d4af1e72011-10-21 17:45:4374 };
75
[email protected]6be08ae2011-10-18 02:23:2376 virtual ~PluginLoaderPosix();
77
[email protected]d4af1e72011-10-21 17:45:4378 // Called on the FILE thread to get the list of plugin paths to probe.
79 void GetPluginsToLoad();
80
81 // Must be called on the IO thread.
82 virtual void LoadPluginsInternal();
83
84 // Message handlers.
[email protected]d9b73c82011-11-09 23:17:2885 void OnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin);
86 void OnPluginLoadFailed(uint32 index, const FilePath& plugin_path);
[email protected]d4af1e72011-10-21 17:45:4387
88 // Checks if the plugin path is an internal plugin, and, if it is, adds it to
89 // |loaded_plugins_|.
90 bool MaybeAddInternalPlugin(const FilePath& plugin_path);
91
92 // Runs all the registered callbacks on each's target loop if the condition
93 // for ending the load process is done (i.e. the |next_load_index_| is outside
[email protected]5abe6302011-12-20 23:44:3294 // the range of the |canonical_list_|).
[email protected]6a0dc7a2011-11-02 14:37:0795 bool MaybeRunPendingCallbacks();
[email protected]d4af1e72011-10-21 17:45:4396
97 // The process host for which this is a client.
[email protected]c4f883a2012-02-03 17:02:0798 base::WeakPtr<content::UtilityProcessHost> process_host_;
[email protected]d4af1e72011-10-21 17:45:4399
100 // A list of paths to plugins which will be loaded by the utility process, in
101 // the order specified by this vector.
102 std::vector<FilePath> canonical_list_;
103
104 // The index in |canonical_list_| of the plugin that the child process will
105 // attempt to load next.
106 size_t next_load_index_;
107
108 // Internal plugins that have been registered at the time of loading.
109 std::vector<webkit::WebPluginInfo> internal_plugins_;
110
111 // A vector of plugins that have been loaded successfully.
112 std::vector<webkit::WebPluginInfo> loaded_plugins_;
[email protected]6be08ae2011-10-18 02:23:23113
114 // The callback and message loop on which the callback will be run when the
115 // plugin loading process has been completed.
[email protected]d4af1e72011-10-21 17:45:43116 std::vector<PendingCallback> callbacks_;
[email protected]6be08ae2011-10-18 02:23:23117
[email protected]d4af1e72011-10-21 17:45:43118 // The time at which plugin loading started.
119 base::TimeTicks load_start_time_;
120
121 friend class MockPluginLoaderPosix;
[email protected]6be08ae2011-10-18 02:23:23122 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix);
123};
124
125#endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_