blob: cc5408e5fb182f662afa4e1c4cb553c4f4b6ab7d [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]6be08ae2011-10-18 02:23:2311#include "base/memory/ref_counted.h"
[email protected]d4af1e72011-10-21 17:45:4312#include "base/time.h"
[email protected]e67385f2011-12-21 06:00:5613#include "content/browser/plugin_service_impl.h"
[email protected]6be08ae2011-10-18 02:23:2314#include "content/browser/utility_process_host.h"
[email protected]d4af1e72011-10-21 17:45:4315#include "ipc/ipc_message.h"
[email protected]6be08ae2011-10-18 02:23:2316#include "webkit/plugins/webplugininfo.h"
17
[email protected]d4af1e72011-10-21 17:45:4318class FilePath;
19class UtilityProcessHost;
20
[email protected]6be08ae2011-10-18 02:23:2321namespace base {
22class MessageLoopProxy;
23}
24
[email protected]d4af1e72011-10-21 17:45:4325// This class is responsible for managing the out-of-process plugin loading on
26// POSIX systems. It primarily lives on the IO thread, but has a brief stay on
27// the FILE thread to iterate over plugin directories when it is first
28// constructed.
29//
30// The following is the algorithm used to load plugins:
31// 1. This asks the PluginList for the list of all potential plugins to attempt
32// to load. This is referred to as the canonical list.
33// 2. The child process this hosts is forked and the canonical list is sent to
34// it.
35// 3. The child process iterates over the canonical list, attempting to load
36// each plugin in the order specified by the list. It sends an IPC message
37// to the browser after each load, indicating success or failure. The two
38// processes synchronize the position in the vector that will be used to
39// attempt to load the next plugin.
40// 4. If the child dies during this process, the host forks another child and
41// resumes loading at the position past the plugin that it just attempted to
42// load, bypassing the problematic plugin.
43// 5. This algorithm continues until the canonical list has been walked to the
44// end, after which the list of loaded plugins is set on the PluginList and
45// the completion callback is run.
[email protected]f7e91ea4b2011-11-01 20:17:1946class CONTENT_EXPORT PluginLoaderPosix : public UtilityProcessHost::Client,
47 IPC::Message::Sender {
[email protected]6be08ae2011-10-18 02:23:2348 public:
[email protected]d4af1e72011-10-21 17:45:4349 PluginLoaderPosix();
50
51 // Must be called from the IO thread.
[email protected]e67385f2011-12-21 06:00:5652 void LoadPlugins(
53 scoped_refptr<base::MessageLoopProxy> target_loop,
54 const content::PluginService::GetPluginsCallback& callback);
[email protected]6be08ae2011-10-18 02:23:2355
56 // UtilityProcessHost::Client:
57 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
59
[email protected]d4af1e72011-10-21 17:45:4360 // IPC::Message::Sender:
[email protected]edc64de2011-11-17 20:07:3861 virtual bool Send(IPC::Message* msg) OVERRIDE;
[email protected]d4af1e72011-10-21 17:45:4362
[email protected]6be08ae2011-10-18 02:23:2363 private:
[email protected]d4af1e72011-10-21 17:45:4364 struct PendingCallback {
65 PendingCallback(scoped_refptr<base::MessageLoopProxy> target_loop,
[email protected]e67385f2011-12-21 06:00:5666 const content::PluginService::GetPluginsCallback& callback);
[email protected]d4af1e72011-10-21 17:45:4367 ~PendingCallback();
68
69 scoped_refptr<base::MessageLoopProxy> target_loop;
[email protected]e67385f2011-12-21 06:00:5670 content::PluginService::GetPluginsCallback callback;
[email protected]d4af1e72011-10-21 17:45:4371 };
72
[email protected]6be08ae2011-10-18 02:23:2373 virtual ~PluginLoaderPosix();
74
[email protected]d4af1e72011-10-21 17:45:4375 // Called on the FILE thread to get the list of plugin paths to probe.
76 void GetPluginsToLoad();
77
78 // Must be called on the IO thread.
79 virtual void LoadPluginsInternal();
80
81 // Message handlers.
[email protected]d9b73c82011-11-09 23:17:2882 void OnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin);
83 void OnPluginLoadFailed(uint32 index, const FilePath& plugin_path);
[email protected]d4af1e72011-10-21 17:45:4384
85 // Checks if the plugin path is an internal plugin, and, if it is, adds it to
86 // |loaded_plugins_|.
87 bool MaybeAddInternalPlugin(const FilePath& plugin_path);
88
89 // Runs all the registered callbacks on each's target loop if the condition
90 // for ending the load process is done (i.e. the |next_load_index_| is outside
[email protected]5abe6302011-12-20 23:44:3291 // the range of the |canonical_list_|).
[email protected]6a0dc7a2011-11-02 14:37:0792 bool MaybeRunPendingCallbacks();
[email protected]d4af1e72011-10-21 17:45:4393
94 // The process host for which this is a client.
[email protected]a3b85d852012-01-27 02:04:4895 base::WeakPtr<UtilityProcessHost> process_host_;
[email protected]d4af1e72011-10-21 17:45:4396
97 // A list of paths to plugins which will be loaded by the utility process, in
98 // the order specified by this vector.
99 std::vector<FilePath> canonical_list_;
100
101 // The index in |canonical_list_| of the plugin that the child process will
102 // attempt to load next.
103 size_t next_load_index_;
104
105 // Internal plugins that have been registered at the time of loading.
106 std::vector<webkit::WebPluginInfo> internal_plugins_;
107
108 // A vector of plugins that have been loaded successfully.
109 std::vector<webkit::WebPluginInfo> loaded_plugins_;
[email protected]6be08ae2011-10-18 02:23:23110
111 // The callback and message loop on which the callback will be run when the
112 // plugin loading process has been completed.
[email protected]d4af1e72011-10-21 17:45:43113 std::vector<PendingCallback> callbacks_;
[email protected]6be08ae2011-10-18 02:23:23114
[email protected]d4af1e72011-10-21 17:45:43115 // The time at which plugin loading started.
116 base::TimeTicks load_start_time_;
117
118 friend class MockPluginLoaderPosix;
[email protected]6be08ae2011-10-18 02:23:23119 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix);
120};
121
122#endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_