| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_MAC_RELAUNCHER_H_ |
| 6 #define CHROME_BROWSER_MAC_RELAUNCHER_H_ |
| 7 #pragma once |
| 8 |
| 9 // mac_relauncher implements main browser application relaunches on the Mac. |
| 10 // When a browser wants to relaunch itself, it can't simply fork off a new |
| 11 // process and exec a new browser from within. That leaves open a window |
| 12 // during which two browser applications might be running concurrently. If |
| 13 // that happens, each will wind up with a distinct Dock icon, which is |
| 14 // especially bad if the user expected the Dock icon to be persistent by |
| 15 // choosing Keep in Dock from the icon's contextual menu. |
| 16 // |
| 17 // mac_relauncher approaches this problem by introducing an intermediate |
| 18 // process (the "relauncher") in between the original browser ("parent") and |
| 19 // replacement browser ("relaunched"). The helper executable is used for the |
| 20 // relauncher process; because it's an LSUIElement, it doesn't get a Dock |
| 21 // icon and isn't visible as a running application at all. The parent will |
| 22 // start a relauncher process, giving it the "writer" side of a pipe that it |
| 23 // retains the "reader" end of. When the relauncher starts up, it will |
| 24 // establish a kqueue to wait for the parent to exit, and will then write to |
| 25 // the pipe. The parent, upon reading from the pipe, is free to exit. When the |
| 26 // relauncher is notified via its kqueue that the parent has exited, it |
| 27 // proceeds, launching the relaunched process. The handshake to synchronize |
| 28 // the parent with the relauncher is necessary to avoid races: the relauncher |
| 29 // needs to be sure that it's monitoring the parent and not some other process |
| 30 // in light of PID reuse, so the parent must remain alive long enough for the |
| 31 // relauncher to set up its kqueue. |
| 32 |
| 33 #include <string> |
| 34 #include <vector> |
| 35 |
| 36 class MainFunctionParams; |
| 37 |
| 38 namespace mac_relauncher { |
| 39 |
| 40 // Relaunches the application using the helper application associated with the |
| 41 // currently running instance of Chrome in the parent browser process as the |
| 42 // executable for the relauncher process. |args| is an argv-style vector of |
| 43 // command line arguments of the form normally passed to execv. args[0] is |
| 44 // also the path to the relaunched process. Because the relauncher process |
| 45 // will ultimately launch the relaunched process via Launch Services, args[0] |
| 46 // may be either a pathname to an executable file or a pathname to an .app |
| 47 // bundle directory. The caller should exit soon after RelaunchApp returns |
| 48 // successfully. Returns true on success, although some failures can occur |
| 49 // after this function returns true if, for example, they occur within the |
| 50 // relauncher process. Returns false when the relaunch definitely failed. |
| 51 bool RelaunchApp(const std::vector<std::string>& args); |
| 52 |
| 53 // Identical to RelaunchApp, but uses |helper| as the path to the relauncher |
| 54 // process. Unlike args[0], |helper| must be a pathname to an executable file. |
| 55 // The helper path given must be from the same version of Chrome as the |
| 56 // running parent browser process, as there are no guarantees that the parent |
| 57 // and relauncher processes from different versions will be able to |
| 58 // communicate with one another. This variant can be useful to relaunch the |
| 59 // same version of Chrome from another location, using that location's helper. |
| 60 bool RelaunchAppWithHelper(const std::string& helper, |
| 61 const std::vector<std::string>& args); |
| 62 |
| 63 // The entry point from ChromeMain into the relauncher process. This is not a |
| 64 // user API. Don't call it if your name isn't ChromeMain. |
| 65 int RelauncherMain(const MainFunctionParams& main_parameters); |
| 66 |
| 67 } // namespace mac_relauncher |
| 68 |
| 69 #endif // CHROME_BROWSER_MAC_RELAUNCHER_H_ |
| OLD | NEW |