Home | History | Annotate | Download | only in delegate_execute
      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 WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_
      6 #define WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_
      7 
      8 #include <windows.h>
      9 #include <atldef.h>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/files/file_path.h"
     13 #include "base/strings/string16.h"
     14 
     15 class CommandLine;
     16 
     17 namespace delegate_execute {
     18 
     19 // Parses a portion of the DelegateExecute handler's command line to determine
     20 // the desired operation. The operation type is decided by looking at the
     21 // command line. The operations are:
     22 // DELEGATE_EXECUTE:
     23 //   When the delegate_execute.exe is invoked by windows when a chrome
     24 //   activation via the shell, possibly using ShellExecute. Control must
     25 //   be given to ATLs WinMain.
     26 // RELAUNCH_CHROME:
     27 //   When the delegate_execute.exe is launched by chrome, when chrome needs
     28 //   to re-launch itself. The required command line parameters are:
     29 //     --relaunch-shortcut=<PathToShortcut>
     30 //     --wait-for-mutex=<MutexNamePid>
     31 //   The PathToShortcut must be the fully qualified file name to the chrome
     32 //   shortcut that has the appId and other 'metro ready' parameters.
     33 //   The MutexNamePid is a mutex name that also encodes the process id and
     34 //   must follow the format <A>.<B>.<pid> where A and B are arbitray strings
     35 //   (usually chrome.relaunch) and pid is the process id of chrome.
     36 class DelegateExecuteOperation {
     37  public:
     38   enum OperationType {
     39     DELEGATE_EXECUTE,
     40     RELAUNCH_CHROME,
     41   };
     42 
     43   DelegateExecuteOperation();
     44   ~DelegateExecuteOperation();
     45 
     46   bool Init(const CommandLine* cmd_line);
     47 
     48   OperationType operation_type() const {
     49     return operation_type_;
     50   }
     51 
     52   const string16& relaunch_flags() const {
     53     return relaunch_flags_;
     54   }
     55 
     56   const string16& mutex() const {
     57     return mutex_;
     58   }
     59 
     60   // Returns the process id of the parent or 0 on failure.
     61   DWORD GetParentPid() const;
     62 
     63   const base::FilePath& shortcut() const {
     64     return relaunch_shortcut_;
     65   }
     66 
     67  private:
     68   OperationType operation_type_;
     69   string16 relaunch_flags_;
     70   base::FilePath relaunch_shortcut_;
     71   string16 mutex_;
     72 
     73   DISALLOW_COPY_AND_ASSIGN(DelegateExecuteOperation);
     74 };
     75 
     76 }  // namespace delegate_execute
     77 
     78 #endif  // WIN8_DELEGATE_EXECUTE_DELEGATE_EXECUTE_OPERATION_H_
     79