Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: content/browser/plugin_loader_posix.h

Issue 8318028: Gracefully handle child process death in out-of-process plugin loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Do not send the index Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/common.gypi ('k') | content/browser/plugin_loader_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_ 5 #ifndef CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_
6 #define CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_ 6 #define CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/time.h"
11 #include "content/browser/plugin_service.h" 12 #include "content/browser/plugin_service.h"
12 #include "content/browser/utility_process_host.h" 13 #include "content/browser/utility_process_host.h"
14 #include "ipc/ipc_message.h"
13 #include "webkit/plugins/webplugininfo.h" 15 #include "webkit/plugins/webplugininfo.h"
14 16
17 class FilePath;
18 class UtilityProcessHost;
19
15 namespace base { 20 namespace base {
16 class MessageLoopProxy; 21 class MessageLoopProxy;
17 } 22 }
18 23
19 class PluginLoaderPosix : public UtilityProcessHost::Client { 24 // This class is responsible for managing the out-of-process plugin loading on
25 // POSIX systems. It primarily lives on the IO thread, but has a brief stay on
26 // the FILE thread to iterate over plugin directories when it is first
27 // constructed.
28 //
29 // The following is the algorithm used to load plugins:
30 // 1. This asks the PluginList for the list of all potential plugins to attempt
31 // to load. This is referred to as the canonical list.
32 // 2. The child process this hosts is forked and the canonical list is sent to
33 // it.
34 // 3. The child process iterates over the canonical list, attempting to load
35 // each plugin in the order specified by the list. It sends an IPC message
36 // to the browser after each load, indicating success or failure. The two
37 // processes synchronize the position in the vector that will be used to
38 // attempt to load the next plugin.
39 // 4. If the child dies during this process, the host forks another child and
40 // resumes loading at the position past the plugin that it just attempted to
41 // load, bypassing the problematic plugin.
42 // 5. This algorithm continues until the canonical list has been walked to the
43 // end, after which the list of loaded plugins is set on the PluginList and
44 // the completion callback is run.
45 class PluginLoaderPosix : public UtilityProcessHost::Client,
46 IPC::Message::Sender {
20 public: 47 public:
21 // Must be called on the IO thread. 48 PluginLoaderPosix();
22 static void LoadPlugins(base::MessageLoopProxy* target_loop, 49
23 const PluginService::GetPluginsCallback& callback); 50 // Must be called from the IO thread.
51 void LoadPlugins(scoped_refptr<base::MessageLoopProxy> target_loop,
52 const PluginService::GetPluginsCallback& callback);
24 53
25 // UtilityProcessHost::Client: 54 // UtilityProcessHost::Client:
26 virtual void OnProcessCrashed(int exit_code) OVERRIDE; 55 virtual void OnProcessCrashed(int exit_code) OVERRIDE;
27 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 56 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
28 57
58 // IPC::Message::Sender:
59 virtual bool Send(IPC::Message* msg);
60
29 private: 61 private:
30 PluginLoaderPosix(base::MessageLoopProxy* target_loop, 62 struct PendingCallback {
63 PendingCallback(scoped_refptr<base::MessageLoopProxy> target_loop,
31 const PluginService::GetPluginsCallback& callback); 64 const PluginService::GetPluginsCallback& callback);
65 ~PendingCallback();
66
67 scoped_refptr<base::MessageLoopProxy> target_loop;
68 PluginService::GetPluginsCallback callback;
69 };
70
32 virtual ~PluginLoaderPosix(); 71 virtual ~PluginLoaderPosix();
33 72
34 void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins); 73 // Called on the FILE thread to get the list of plugin paths to probe.
74 void GetPluginsToLoad();
75
76 // Must be called on the IO thread.
77 virtual void LoadPluginsInternal();
78
79 // Message handlers.
80 void OnPluginLoaded(const webkit::WebPluginInfo& plugin);
81 void OnPluginLoadFailed(const FilePath& plugin_path);
82
83 // Checks if the plugin path is an internal plugin, and, if it is, adds it to
84 // |loaded_plugins_|.
85 bool MaybeAddInternalPlugin(const FilePath& plugin_path);
86
87 // Runs all the registered callbacks on each's target loop if the condition
88 // for ending the load process is done (i.e. the |next_load_index_| is outside
89 // the ranage of the |canonical_list_|).
90 void RunPendingCallbacks();
91
92 // The process host for which this is a client.
93 UtilityProcessHost* process_host_;
94
95 // A list of paths to plugins which will be loaded by the utility process, in
96 // the order specified by this vector.
97 std::vector<FilePath> canonical_list_;
98
99 // The index in |canonical_list_| of the plugin that the child process will
100 // attempt to load next.
101 size_t next_load_index_;
102
103 // Internal plugins that have been registered at the time of loading.
104 std::vector<webkit::WebPluginInfo> internal_plugins_;
105
106 // A vector of plugins that have been loaded successfully.
107 std::vector<webkit::WebPluginInfo> loaded_plugins_;
35 108
36 // The callback and message loop on which the callback will be run when the 109 // The callback and message loop on which the callback will be run when the
37 // plugin loading process has been completed. 110 // plugin loading process has been completed.
38 scoped_refptr<base::MessageLoopProxy> target_loop_; 111 std::vector<PendingCallback> callbacks_;
39 PluginService::GetPluginsCallback callback_;
40 112
113 // The time at which plugin loading started.
114 base::TimeTicks load_start_time_;
115
116 friend class MockPluginLoaderPosix;
41 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix); 117 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix);
42 }; 118 };
43 119
44 #endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_ 120 #endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_
OLDNEW
« no previous file with comments | « build/common.gypi ('k') | content/browser/plugin_loader_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698