OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "content/browser/plugin_service_impl.h" | 15 #include "content/browser/plugin_service_impl.h" |
16 #include "content/public/browser/utility_process_host_client.h" | 16 #include "content/public/browser/utility_process_host_client.h" |
17 #include "ipc/ipc_sender.h" | 17 #include "ipc/ipc_sender.h" |
18 #include "webkit/plugins/webplugininfo.h" | 18 #include "webkit/plugins/webplugininfo.h" |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 class MessageLoopProxy; | 21 class MessageLoopProxy; |
22 } | 22 } |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 class UtilityProcessHost; | 25 class UtilityProcessHost; |
26 } | |
27 | 26 |
28 // This class is responsible for managing the out-of-process plugin loading on | 27 // This class is responsible for managing the out-of-process plugin loading on |
29 // POSIX systems. It primarily lives on the IO thread, but has a brief stay on | 28 // POSIX systems. It primarily lives on the IO thread, but has a brief stay on |
30 // the FILE thread to iterate over plugin directories when it is first | 29 // the FILE thread to iterate over plugin directories when it is first |
31 // constructed. | 30 // constructed. |
32 // | 31 // |
33 // The following is the algorithm used to load plugins: | 32 // The following is the algorithm used to load plugins: |
34 // 1. This asks the PluginList for the list of all potential plugins to attempt | 33 // 1. This asks the PluginList for the list of all potential plugins to attempt |
35 // to load. This is referred to as the canonical list. | 34 // to load. This is referred to as the canonical list. |
36 // 2. The child process this hosts is forked and the canonical list is sent to | 35 // 2. The child process this hosts is forked and the canonical list is sent to |
37 // it. | 36 // it. |
38 // 3. The child process iterates over the canonical list, attempting to load | 37 // 3. The child process iterates over the canonical list, attempting to load |
39 // each plugin in the order specified by the list. It sends an IPC message | 38 // each plugin in the order specified by the list. It sends an IPC message |
40 // to the browser after each load, indicating success or failure. The two | 39 // to the browser after each load, indicating success or failure. The two |
41 // processes synchronize the position in the vector that will be used to | 40 // processes synchronize the position in the vector that will be used to |
42 // attempt to load the next plugin. | 41 // attempt to load the next plugin. |
43 // 4. If the child dies during this process, the host forks another child and | 42 // 4. If the child dies during this process, the host forks another child and |
44 // resumes loading at the position past the plugin that it just attempted to | 43 // resumes loading at the position past the plugin that it just attempted to |
45 // load, bypassing the problematic plugin. | 44 // load, bypassing the problematic plugin. |
46 // 5. This algorithm continues until the canonical list has been walked to the | 45 // 5. This algorithm continues until the canonical list has been walked to the |
47 // end, after which the list of loaded plugins is set on the PluginList and | 46 // end, after which the list of loaded plugins is set on the PluginList and |
48 // the completion callback is run. | 47 // the completion callback is run. |
49 class CONTENT_EXPORT PluginLoaderPosix | 48 class CONTENT_EXPORT PluginLoaderPosix |
50 : public NON_EXPORTED_BASE(content::UtilityProcessHostClient), | 49 : public NON_EXPORTED_BASE(UtilityProcessHostClient), |
51 public IPC::Sender { | 50 public IPC::Sender { |
52 public: | 51 public: |
53 PluginLoaderPosix(); | 52 PluginLoaderPosix(); |
54 | 53 |
55 // Must be called from the IO thread. | 54 // Must be called from the IO thread. |
56 void LoadPlugins( | 55 void LoadPlugins( |
57 scoped_refptr<base::MessageLoopProxy> target_loop, | 56 scoped_refptr<base::MessageLoopProxy> target_loop, |
58 const content::PluginService::GetPluginsCallback& callback); | 57 const PluginService::GetPluginsCallback& callback); |
59 | 58 |
60 // UtilityProcessHostClient: | 59 // UtilityProcessHostClient: |
61 virtual void OnProcessCrashed(int exit_code) OVERRIDE; | 60 virtual void OnProcessCrashed(int exit_code) OVERRIDE; |
62 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 61 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
63 | 62 |
64 // IPC::Sender: | 63 // IPC::Sender: |
65 virtual bool Send(IPC::Message* msg) OVERRIDE; | 64 virtual bool Send(IPC::Message* msg) OVERRIDE; |
66 | 65 |
67 private: | 66 private: |
68 struct PendingCallback { | 67 struct PendingCallback { |
69 PendingCallback(scoped_refptr<base::MessageLoopProxy> target_loop, | 68 PendingCallback(scoped_refptr<base::MessageLoopProxy> target_loop, |
70 const content::PluginService::GetPluginsCallback& callback); | 69 const PluginService::GetPluginsCallback& callback); |
71 ~PendingCallback(); | 70 ~PendingCallback(); |
72 | 71 |
73 scoped_refptr<base::MessageLoopProxy> target_loop; | 72 scoped_refptr<base::MessageLoopProxy> target_loop; |
74 content::PluginService::GetPluginsCallback callback; | 73 PluginService::GetPluginsCallback callback; |
75 }; | 74 }; |
76 | 75 |
77 virtual ~PluginLoaderPosix(); | 76 virtual ~PluginLoaderPosix(); |
78 | 77 |
79 // Called on the FILE thread to get the list of plugin paths to probe. | 78 // Called on the FILE thread to get the list of plugin paths to probe. |
80 void GetPluginsToLoad(); | 79 void GetPluginsToLoad(); |
81 | 80 |
82 // Must be called on the IO thread. | 81 // Must be called on the IO thread. |
83 virtual void LoadPluginsInternal(); | 82 virtual void LoadPluginsInternal(); |
84 | 83 |
85 // Message handlers. | 84 // Message handlers. |
86 void OnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin); | 85 void OnPluginLoaded(uint32 index, const webkit::WebPluginInfo& plugin); |
87 void OnPluginLoadFailed(uint32 index, const FilePath& plugin_path); | 86 void OnPluginLoadFailed(uint32 index, const FilePath& plugin_path); |
88 | 87 |
89 // Checks if the plugin path is an internal plugin, and, if it is, adds it to | 88 // Checks if the plugin path is an internal plugin, and, if it is, adds it to |
90 // |loaded_plugins_|. | 89 // |loaded_plugins_|. |
91 bool MaybeAddInternalPlugin(const FilePath& plugin_path); | 90 bool MaybeAddInternalPlugin(const FilePath& plugin_path); |
92 | 91 |
93 // Runs all the registered callbacks on each's target loop if the condition | 92 // Runs all the registered callbacks on each's target loop if the condition |
94 // for ending the load process is done (i.e. the |next_load_index_| is outside | 93 // for ending the load process is done (i.e. the |next_load_index_| is outside |
95 // the range of the |canonical_list_|). | 94 // the range of the |canonical_list_|). |
96 bool MaybeRunPendingCallbacks(); | 95 bool MaybeRunPendingCallbacks(); |
97 | 96 |
98 // The process host for which this is a client. | 97 // The process host for which this is a client. |
99 base::WeakPtr<content::UtilityProcessHost> process_host_; | 98 base::WeakPtr<UtilityProcessHost> process_host_; |
100 | 99 |
101 // A list of paths to plugins which will be loaded by the utility process, in | 100 // A list of paths to plugins which will be loaded by the utility process, in |
102 // the order specified by this vector. | 101 // the order specified by this vector. |
103 std::vector<FilePath> canonical_list_; | 102 std::vector<FilePath> canonical_list_; |
104 | 103 |
105 // The index in |canonical_list_| of the plugin that the child process will | 104 // The index in |canonical_list_| of the plugin that the child process will |
106 // attempt to load next. | 105 // attempt to load next. |
107 size_t next_load_index_; | 106 size_t next_load_index_; |
108 | 107 |
109 // Internal plugins that have been registered at the time of loading. | 108 // Internal plugins that have been registered at the time of loading. |
110 std::vector<webkit::WebPluginInfo> internal_plugins_; | 109 std::vector<webkit::WebPluginInfo> internal_plugins_; |
111 | 110 |
112 // A vector of plugins that have been loaded successfully. | 111 // A vector of plugins that have been loaded successfully. |
113 std::vector<webkit::WebPluginInfo> loaded_plugins_; | 112 std::vector<webkit::WebPluginInfo> loaded_plugins_; |
114 | 113 |
115 // The callback and message loop on which the callback will be run when the | 114 // The callback and message loop on which the callback will be run when the |
116 // plugin loading process has been completed. | 115 // plugin loading process has been completed. |
117 std::deque<PendingCallback> callbacks_; | 116 std::deque<PendingCallback> callbacks_; |
118 | 117 |
119 // The time at which plugin loading started. | 118 // The time at which plugin loading started. |
120 base::TimeTicks load_start_time_; | 119 base::TimeTicks load_start_time_; |
121 | 120 |
122 friend class MockPluginLoaderPosix; | 121 friend class MockPluginLoaderPosix; |
123 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix); | 122 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix); |
124 }; | 123 }; |
125 | 124 |
| 125 } // namespace content |
| 126 |
126 #endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_ | 127 #endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_ |
OLD | NEW |