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