Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: win8/delegate_execute/delegate_execute.cc

Issue 23258005: Give SxS distribution its own registration GUIDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed IsSetAsDefaultSupported() and GetCommandExecuteImplClsid(), and other minor cleanup. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/intsafe_workaround.h" 5 #include "build/intsafe_workaround.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlcom.h> 8 #include <atlcom.h>
9 #include <atlctl.h> 9 #include <atlctl.h>
10 #include <initguid.h> 10 #include <initguid.h>
11 #include <shellapi.h> 11 #include <shellapi.h>
12 12
13 #include "base/at_exit.h" 13 #include "base/at_exit.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_util.h" 15 #include "base/file_util.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/process/kill.h" 17 #include "base/process/kill.h"
18 #include "base/strings/string16.h" 18 #include "base/strings/string16.h"
19 #include "base/win/scoped_com_initializer.h" 19 #include "base/win/scoped_com_initializer.h"
20 #include "base/win/scoped_comptr.h"
20 #include "base/win/scoped_handle.h" 21 #include "base/win/scoped_handle.h"
21 #include "breakpad/src/client/windows/handler/exception_handler.h" 22 #include "breakpad/src/client/windows/handler/exception_handler.h"
22 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/installer/util/browser_distribution.h"
23 #include "win8/delegate_execute/command_execute_impl.h" 25 #include "win8/delegate_execute/command_execute_impl.h"
24 #include "win8/delegate_execute/crash_server_init.h" 26 #include "win8/delegate_execute/crash_server_init.h"
25 #include "win8/delegate_execute/delegate_execute_operation.h" 27 #include "win8/delegate_execute/delegate_execute_operation.h"
26 #include "win8/delegate_execute/resource.h" 28 #include "win8/delegate_execute/resource.h"
27 29
28 using namespace ATL; 30 using namespace ATL;
29 31
32 // Usually classes derived from CAtlExeModuleT, or other types of ATL
33 // COM module classes statically define their CLSID at compile time through
34 // the use of various macros, and ATL internals takes care of creating the
35 // class objects and registering them. However, we need to register the same
36 // object with different CLSIDs depending on a runtime setting, so we handle
37 // that logic here, before the main ATL message loop runs.
30 class DelegateExecuteModule 38 class DelegateExecuteModule
31 : public ATL::CAtlExeModuleT< DelegateExecuteModule > { 39 : public ATL::CAtlExeModuleT< DelegateExecuteModule > {
32 public : 40 public :
33 typedef ATL::CAtlExeModuleT<DelegateExecuteModule> ParentClass; 41 typedef ATL::CAtlExeModuleT<DelegateExecuteModule> ParentClass;
42 typedef CComObject<CommandExecuteImpl> ImplType;
34 43
35 HRESULT RegisterServer(BOOL reg_type_lib) { 44 DelegateExecuteModule()
36 return ParentClass::RegisterServer(FALSE); 45 : registration_token_(0) {
37 } 46 }
38 47
39 virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() { 48 HRESULT PreMessageLoop(int nShowCmd) {
40 AtlTrace(L"In %hs\n", __FUNCTION__); 49 HRESULT hr = S_OK;
41 HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar); 50 string16 clsid_string;
51 GUID clsid;
52 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
53 if (!dist->GetCommandExecuteImplClsidString(&clsid_string))
54 return E_FAIL;
55 if (FAILED(hr = ::CLSIDFromString(clsid_string.c_str(), &clsid)))
grt (UTC plus 2) 2013/09/09 18:39:15 please do the assignment in its own statement
56 return hr;
57
58 // We use the same class creation logic as ATL itself. See
59 // _ATL_OBJMAP_ENTRY::RegisterClassObject() in atlbase.h
60 hr = ImplType::_ClassFactoryCreatorClass::CreateInstance(
61 ImplType::_CreatorClass::CreateInstance, IID_IUnknown,
62 instance_.ReceiveVoid());
63 if (FAILED(hr))
64 return hr;
65 hr = ::CoRegisterClassObject(clsid, instance_, CLSCTX_LOCAL_SERVER,
66 REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED, &registration_token_);
42 if (FAILED(hr)) 67 if (FAILED(hr))
43 return hr; 68 return hr;
44 69
45 wchar_t delegate_execute_clsid[MAX_PATH] = {0}; 70 return ParentClass::PreMessageLoop(nShowCmd);
46 if (!StringFromGUID2(__uuidof(CommandExecuteImpl), delegate_execute_clsid, 71 }
47 ARRAYSIZE(delegate_execute_clsid))) { 72
48 ATLASSERT(false); 73 HRESULT PostMessageLoop() {
49 return E_FAIL; 74 if (registration_token_ != 0) {
75 ::CoRevokeClassObject(registration_token_);
76 registration_token_ = 0;
50 } 77 }
51 78
52 hr = registrar->AddReplacement(L"DELEGATE_EXECUTE_CLSID", 79 instance_.Release();
53 delegate_execute_clsid); 80
54 ATLASSERT(SUCCEEDED(hr)); 81 return ParentClass::PostMessageLoop();
55 return hr;
56 } 82 }
83
84 private:
85 base::win::ScopedComPtr<IUnknown> instance_;
86 DWORD registration_token_;
57 }; 87 };
58 88
59 DelegateExecuteModule _AtlModule; 89 DelegateExecuteModule _AtlModule;
60 90
61 using delegate_execute::DelegateExecuteOperation; 91 using delegate_execute::DelegateExecuteOperation;
62 using base::win::ScopedHandle; 92 using base::win::ScopedHandle;
63 93
64 int RelaunchChrome(const DelegateExecuteOperation& operation) { 94 int RelaunchChrome(const DelegateExecuteOperation& operation) {
65 AtlTrace("Relaunching [%ls] with flags [%s]\n", 95 AtlTrace("Relaunching [%ls] with flags [%s]\n",
66 operation.mutex().c_str(), operation.relaunch_flags()); 96 operation.mutex().c_str(), operation.relaunch_flags());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 case DelegateExecuteOperation::RELAUNCH_CHROME: 155 case DelegateExecuteOperation::RELAUNCH_CHROME:
126 ret_code = RelaunchChrome(operation); 156 ret_code = RelaunchChrome(operation);
127 break; 157 break;
128 default: 158 default:
129 NOTREACHED(); 159 NOTREACHED();
130 } 160 }
131 } 161 }
132 AtlTrace("delegate_execute exit, code = %d\n", ret_code); 162 AtlTrace("delegate_execute exit, code = %d\n", ret_code);
133 return ret_code; 163 return ret_code;
134 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698