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