Home | History | Annotate | Download | only in mac
      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 
      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 
     35 namespace content {
     36 struct MainFunctionParams;
     37 }
     38 
     39 namespace mac_relauncher {
     40 
     41 // The relauncher process can unmount and eject a mounted disk image and move
     42 // its disk image file to the trash. This argument may be supplied to
     43 // RelaunchAppWithHelper to achieve this. The argument's value must be a BSD
     44 // device name of the form "diskN" or "diskNsM".
     45 extern const char* const kRelauncherDMGDeviceArg;
     46 
     47 // Relaunches the application using the helper application associated with the
     48 // currently running instance of Chrome in the parent browser process as the
     49 // executable for the relauncher process. |args| is an argv-style vector of
     50 // command line arguments of the form normally passed to execv. args[0] is
     51 // also the path to the relaunched process. Because the relauncher process
     52 // will ultimately launch the relaunched process via Launch Services, args[0]
     53 // may be either a pathname to an executable file or a pathname to an .app
     54 // bundle directory. The caller should exit soon after RelaunchApp returns
     55 // successfully. Returns true on success, although some failures can occur
     56 // after this function returns true if, for example, they occur within the
     57 // relauncher process. Returns false when the relaunch definitely failed.
     58 bool RelaunchApp(const std::vector<std::string>& args);
     59 
     60 // Identical to RelaunchApp, but uses |helper| as the path to the relauncher
     61 // process, and allows additional arguments to be supplied to the relauncher
     62 // process in relauncher_args. Unlike args[0], |helper| must be a pathname to
     63 // an executable file. The helper path given must be from the same version of
     64 // Chrome as the running parent browser process, as there are no guarantees
     65 // that the parent and relauncher processes from different versions will be
     66 // able to communicate with one another. This variant can be useful to
     67 // relaunch the same version of Chrome from another location, using that
     68 // location's helper.
     69 bool RelaunchAppWithHelper(const std::string& helper,
     70                            const std::vector<std::string>& relauncher_args,
     71                            const std::vector<std::string>& args);
     72 
     73 namespace internal {
     74 
     75 // The entry point from ChromeMain into the relauncher process. This is not a
     76 // user API. Don't call it if your name isn't ChromeMain.
     77 int RelauncherMain(const content::MainFunctionParams& main_parameters);
     78 
     79 }  // namespace internal
     80 
     81 }  // namespace mac_relauncher
     82 
     83 #endif  // CHROME_BROWSER_MAC_RELAUNCHER_H_
     84