| OLD | NEW |
| (Empty) |
| 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 | |
| 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 <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "base/macros.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/time/time.h" | |
| 17 #include "content/browser/plugin_service_impl.h" | |
| 18 #include "content/public/browser/utility_process_host_client.h" | |
| 19 #include "content/public/common/webplugininfo.h" | |
| 20 #include "ipc/ipc_sender.h" | |
| 21 | |
| 22 namespace content { | |
| 23 class UtilityProcessHost; | |
| 24 | |
| 25 // 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. | |
| 46 class CONTENT_EXPORT PluginLoaderPosix | |
| 47 : public NON_EXPORTED_BASE(UtilityProcessHostClient), | |
| 48 public IPC::Sender { | |
| 49 public: | |
| 50 PluginLoaderPosix(); | |
| 51 | |
| 52 // Must be called from the IO thread. The |callback| will be called on the IO | |
| 53 // thread too. | |
| 54 void GetPlugins(const PluginService::GetPluginsCallback& callback); | |
| 55 | |
| 56 // UtilityProcessHostClient: | |
| 57 void OnProcessCrashed(int exit_code) override; | |
| 58 void OnProcessLaunchFailed() override; | |
| 59 bool OnMessageReceived(const IPC::Message& message) override; | |
| 60 | |
| 61 // IPC::Sender: | |
| 62 bool Send(IPC::Message* msg) override; | |
| 63 | |
| 64 private: | |
| 65 ~PluginLoaderPosix() override; | |
| 66 | |
| 67 // Called on the FILE thread to get the list of plugin paths to probe. | |
| 68 void GetPluginsToLoad(); | |
| 69 | |
| 70 // Must be called on the IO thread. | |
| 71 virtual void LoadPluginsInternal(); | |
| 72 | |
| 73 // Called after plugin loading has finished, if we don't know whether the | |
| 74 // plugin list has been invalidated in the mean time. | |
| 75 void GetPluginsWrapper( | |
| 76 const PluginService::GetPluginsCallback& callback, | |
| 77 const std::vector<WebPluginInfo>& plugins_unused); | |
| 78 | |
| 79 // Message handlers. | |
| 80 void OnPluginLoaded(uint32_t index, const WebPluginInfo& plugin); | |
| 81 void OnPluginLoadFailed(uint32_t index, const base::FilePath& plugin_path); | |
| 82 | |
| 83 // Returns an iterator to the plugin in |internal_plugins_| whose path | |
| 84 // matches |plugin_path|. | |
| 85 std::vector<WebPluginInfo>::iterator FindInternalPlugin( | |
| 86 const base::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 | |
| 90 // the range of the |canonical_list_|). | |
| 91 bool MaybeRunPendingCallbacks(); | |
| 92 | |
| 93 // Returns true if there are no plugins left to load. | |
| 94 bool IsFinishedLoadingPlugins(); | |
| 95 | |
| 96 // This method should be called when the plugins are finished loading. | |
| 97 // It updates the PluginList's list of plugins, and runs the queued callbacks. | |
| 98 void FinishedLoadingPlugins(); | |
| 99 | |
| 100 // Launches the utility process that loads the plugins. | |
| 101 // Virtual for testing. | |
| 102 virtual bool LaunchUtilityProcess(); | |
| 103 | |
| 104 // The process host for which this is a client. | |
| 105 base::WeakPtr<UtilityProcessHost> process_host_; | |
| 106 | |
| 107 // A list of paths to plugins which will be loaded by the utility process, in | |
| 108 // the order specified by this vector. | |
| 109 std::vector<base::FilePath> canonical_list_; | |
| 110 | |
| 111 // The index in |canonical_list_| of the plugin that the child process will | |
| 112 // attempt to load next. | |
| 113 size_t next_load_index_; | |
| 114 | |
| 115 // Internal plugins that have been registered at the time of loading. | |
| 116 std::vector<WebPluginInfo> internal_plugins_; | |
| 117 | |
| 118 // A vector of plugins that have been loaded successfully. | |
| 119 std::vector<WebPluginInfo> loaded_plugins_; | |
| 120 | |
| 121 // The callback and message loop on which the callback will be run when the | |
| 122 // plugin loading process has been completed. | |
| 123 std::vector<PluginService::GetPluginsCallback> callbacks_; | |
| 124 | |
| 125 // True if there is (or is about to be) a utility process that loads plugins. | |
| 126 bool loading_plugins_; | |
| 127 | |
| 128 friend class MockPluginLoaderPosix; | |
| 129 DISALLOW_COPY_AND_ASSIGN(PluginLoaderPosix); | |
| 130 }; | |
| 131 | |
| 132 } // namespace content | |
| 133 | |
| 134 #endif // CONTENT_BROWSER_PLUGIN_LOADER_POSIX_H_ | |
| OLD | NEW |