blob: 213a6a8266a487be1ead4cccfedf24e4f6f65de8 [file] [log] [blame]
[email protected]6be08ae2011-10-18 02:23:231// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// 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]6be08ae2011-10-18 02:23:2313#include "content/browser/plugin_service.h"
14#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.
52 void LoadPlugins(scoped_refptr<base::MessageLoopProxy> target_loop,
53 const PluginService::GetPluginsCallback& callback);
[email protected]6be08ae2011-10-18 02:23:2354
55 // UtilityProcessHost::Client:
56 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
58
[email protected]d4af1e72011-10-21 17:45:4359 // IPC::Message::Sender:
[email protected]edc64de2011-11-17 20:07:3860 virtual bool Send(IPC::Message* msg) OVERRIDE;
[email protected]d4af1e72011-10-21 17:45:4361
[email protected]6be08ae2011-10-18 02:23:2362 private:
[email protected]d4af1e72011-10-21 17:45:4363 struct PendingCallback {
64 PendingCallback(scoped_refptr<base::MessageLoopProxy> target_loop,
[email protected]6be08ae2011-10-18 02:23:2365 const PluginService::GetPluginsCallback& callback);
[email protected]d4af1e72011-10-21 17:45:4366 ~PendingCallback();
67
68 scoped_refptr<base::MessageLoopProxy> target_loop;
69 PluginService::GetPluginsCallback callback;
70 };
71
[email protected]6be08ae2011-10-18 02:23:2372 virtual ~PluginLoaderPosix();
73
[email protected]d4af1e72011-10-21 17:45:4374 // Called on the FILE thread to get the list of plugin paths to probe.
75 void GetPluginsToLoad();
76
77 // Must be called on the IO thread.
78 virtual void LoadPluginsInternal();
79
80 // Message handlers.
[email protected]d9b73c82011-11-09 23:17:2881 void OnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin);
82 void OnPluginLoadFailed(uint32 index, const FilePath& plugin_path);
[email protected]d4af1e72011-10-21 17:45:4383
84 // Checks if the plugin path is an internal plugin, and, if it is, adds it to
85 // |loaded_plugins_|.
86 bool MaybeAddInternalPlugin(const FilePath& plugin_path);
87
88 // Runs all the registered callbacks on each's target loop if the condition
89 // for ending the load process is done (i.e. the |next_load_index_| is outside
[email protected]5abe6302011-12-20 23:44:3290 // the range of the |canonical_list_|).
[email protected]6a0dc7a2011-11-02 14:37:0791 bool MaybeRunPendingCallbacks();
[email protected]d4af1e72011-10-21 17:45:4392
93 // The process host for which this is a client.
94 UtilityProcessHost* process_host_;
95
96 // A list of paths to plugins which will be loaded by the utility process, in
97 // the order specified by this vector.
98 std::vector<FilePath> canonical_list_;
99
100 // The index in |canonical_list_| of the plugin that the child process will
101 // attempt to load next.
102 size_t next_load_index_;
103
104 // Internal plugins that have been registered at the time of loading.
105 std::vector<webkit::WebPluginInfo> internal_plugins_;
106
107 // A vector of plugins that have been loaded successfully.
108 std::vector<webkit::WebPluginInfo> loaded_plugins_;
[email protected]6be08ae2011-10-18 02:23:23109
110 // The callback and message loop on which the callback will be run when the
111 // plugin loading process has been completed.
[email protected]d4af1e72011-10-21 17:45:43112 std::vector<PendingCallback> callbacks_;
[email protected]6be08ae2011-10-18 02:23:23113
[email protected]d4af1e72011-10-21 17:45:43114 // The time at which plugin loading started.
115 base::TimeTicks load_start_time_;
116
117 friend class MockPluginLoaderPosix;
[email protected]6be08ae2011-10-18 02:23:23118 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix);
119};
120
121#endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_