Chromium Code Reviews| Index: win8/delegate_execute/delegate_execute.cc |
| diff --git a/win8/delegate_execute/delegate_execute.cc b/win8/delegate_execute/delegate_execute.cc |
| index 549716ac60d32cbfa62f1d0a66591267759ba3c7..ddb9883daa208bc7e0262131fc28a990deb23fd1 100644 |
| --- a/win8/delegate_execute/delegate_execute.cc |
| +++ b/win8/delegate_execute/delegate_execute.cc |
| @@ -17,9 +17,11 @@ |
| #include "base/process/kill.h" |
| #include "base/strings/string16.h" |
| #include "base/win/scoped_com_initializer.h" |
| +#include "base/win/scoped_comptr.h" |
| #include "base/win/scoped_handle.h" |
| #include "breakpad/src/client/windows/handler/exception_handler.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "chrome/installer/util/browser_distribution.h" |
| #include "win8/delegate_execute/command_execute_impl.h" |
| #include "win8/delegate_execute/crash_server_init.h" |
| #include "win8/delegate_execute/delegate_execute_operation.h" |
| @@ -27,33 +29,62 @@ |
| using namespace ATL; |
| +// Usually classes derived from CAtlExeModuleT, or other types of ATL |
| +// COM module classes statically define their CLSID at compile time through |
| +// the use of various macros, and ATL internals takes care of creating the |
| +// class objects and registering them. However, we need to register the same |
| +// object with different CLSIDs depending on a runtime setting, so we handle |
| +// that logic here, before the main ATL message loop runs. |
| class DelegateExecuteModule |
| : public ATL::CAtlExeModuleT< DelegateExecuteModule > { |
| public : |
| typedef ATL::CAtlExeModuleT<DelegateExecuteModule> ParentClass; |
| + typedef CComObject<CommandExecuteImpl> ImplType; |
| - HRESULT RegisterServer(BOOL reg_type_lib) { |
| - return ParentClass::RegisterServer(FALSE); |
| + DelegateExecuteModule() |
| + : registration_token_(0) { |
| } |
| - virtual HRESULT AddCommonRGSReplacements(IRegistrarBase* registrar) throw() { |
| - AtlTrace(L"In %hs\n", __FUNCTION__); |
| - HRESULT hr = ParentClass::AddCommonRGSReplacements(registrar); |
| + HRESULT PreMessageLoop(int nShowCmd) { |
| + HRESULT hr = S_OK; |
| + string16 clsid_string; |
| + GUID clsid; |
| + BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| + if (!dist->GetCommandExecuteImplClsid(&clsid_string)) |
| + return E_FAIL; |
| + hr = ::CLSIDFromString(clsid_string.c_str(), &clsid); |
|
gab
2013/09/10 19:08:57
Nice, I much prefer that to the two methods in Bro
|
| if (FAILED(hr)) |
| return hr; |
| - wchar_t delegate_execute_clsid[MAX_PATH] = {0}; |
| - if (!StringFromGUID2(__uuidof(CommandExecuteImpl), delegate_execute_clsid, |
| - ARRAYSIZE(delegate_execute_clsid))) { |
| - ATLASSERT(false); |
| - return E_FAIL; |
| + // We use the same class creation logic as ATL itself. See |
| + // _ATL_OBJMAP_ENTRY::RegisterClassObject() in atlbase.h |
| + hr = ImplType::_ClassFactoryCreatorClass::CreateInstance( |
| + ImplType::_CreatorClass::CreateInstance, IID_IUnknown, |
| + instance_.ReceiveVoid()); |
| + if (FAILED(hr)) |
| + return hr; |
| + hr = ::CoRegisterClassObject(clsid, instance_, CLSCTX_LOCAL_SERVER, |
| + REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED, ®istration_token_); |
| + if (FAILED(hr)) |
| + return hr; |
| + |
| + return ParentClass::PreMessageLoop(nShowCmd); |
| + } |
| + |
| + HRESULT PostMessageLoop() { |
| + if (registration_token_ != 0) { |
| + ::CoRevokeClassObject(registration_token_); |
| + registration_token_ = 0; |
| } |
| - hr = registrar->AddReplacement(L"DELEGATE_EXECUTE_CLSID", |
| - delegate_execute_clsid); |
| - ATLASSERT(SUCCEEDED(hr)); |
| - return hr; |
| + instance_.Release(); |
| + |
| + return ParentClass::PostMessageLoop(); |
| } |
| + |
| + private: |
| + base::win::ScopedComPtr<IUnknown> instance_; |
| + DWORD registration_token_; |
| }; |
| DelegateExecuteModule _AtlModule; |