| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #ifndef OMAHA_GOOPDATE_BROKER_CLASS_FACTORY_H_ | |
| 17 #define OMAHA_GOOPDATE_BROKER_CLASS_FACTORY_H_ | |
| 18 | |
| 19 #include <atlcom.h> | |
| 20 #include "base/basictypes.h" | |
| 21 #include "omaha/base/atlregmapex.h" | |
| 22 #include "omaha/base/scope_guard.h" | |
| 23 #include "omaha/base/system.h" | |
| 24 #include "omaha/base/vistautil.h" | |
| 25 #include "omaha/goopdate/elevation_moniker_resource.h" | |
| 26 | |
| 27 namespace omaha { | |
| 28 | |
| 29 // This class factory delegates CoCreation to the template "clsid" and returns | |
| 30 // the resulting interface to the caller. If unable to CoCreate "clsid", | |
| 31 // BrokerClassFactory attempts to CoCreateAsAdmin and return "clsid2" to the | |
| 32 // caller. | |
| 33 template <const CLSID& clsid, const CLSID& clsid2> | |
| 34 class BrokerClassFactory : public CComClassFactory { | |
| 35 public: | |
| 36 BrokerClassFactory() {} | |
| 37 | |
| 38 virtual ~BrokerClassFactory() {} | |
| 39 | |
| 40 STDMETHOD(CreateInstance)(LPUNKNOWN outer_unk, REFIID riid, void** instance) { | |
| 41 CORE_LOG(L3, (_T("[BrokerClassFactory CreateInstance][%s]"), | |
| 42 GuidToString(riid))); | |
| 43 | |
| 44 // The LockServer combo is used to pulse the module count, which will | |
| 45 // shutdown the server after this CreateInstance() request completes, | |
| 46 // provided there are no other outstanding interface references being held | |
| 47 // by clients. | |
| 48 LockServer(TRUE); | |
| 49 ON_SCOPE_EXIT_OBJ(*this, &IClassFactory::LockServer, FALSE); | |
| 50 | |
| 51 if (!instance) { | |
| 52 return E_POINTER; | |
| 53 } | |
| 54 | |
| 55 *instance = NULL; | |
| 56 | |
| 57 if (outer_unk) { | |
| 58 return CLASS_E_NOAGGREGATION; | |
| 59 } | |
| 60 | |
| 61 HRESULT hr = ::CoCreateInstance(clsid, | |
| 62 outer_unk, | |
| 63 CLSCTX_ALL, | |
| 64 riid, | |
| 65 instance); | |
| 66 if (FAILED(hr)) { | |
| 67 CORE_LOG(LE, (_T("[Create failed][%s][0x%x]"), GuidToString(clsid), hr)); | |
| 68 | |
| 69 if (!vista_util::IsVistaOrLater() && !vista_util::IsUserAdmin()) { | |
| 70 return hr; | |
| 71 } | |
| 72 | |
| 73 hr = System::CoCreateInstanceAsAdmin(NULL, clsid2, riid, instance); | |
| 74 if (FAILED(hr)) { | |
| 75 CORE_LOG(LE, (_T("[Create fail][%s][0x%x]"), GuidToString(clsid2), hr)); | |
| 76 return hr; | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 return S_OK; | |
| 81 } | |
| 82 }; | |
| 83 | |
| 84 #pragma warning(push) | |
| 85 // Construction of local static object is not thread-safe | |
| 86 #pragma warning(disable:4640) | |
| 87 | |
| 88 // This class is used for COM registration and class factory registration and | |
| 89 // instantiation of the delegate brokers. The class itself is not | |
| 90 // instantiated. target_clsid is the CLSID that BrokerClassFactory | |
| 91 // CoCreates and returns to the caller. If unable to CoCreate target_clsid, | |
| 92 // BrokerClassFactory attempts to CoCreateAsAdmin target_clsid2. broker_clsid is | |
| 93 // the CLSID that clients of the broker CoCreate. | |
| 94 template <const CLSID& target_clsid, const CLSID& target_clsid2, | |
| 95 const CLSID& broker_clsid, const TCHAR* const broker_progid> | |
| 96 class ATL_NO_VTABLE BrokerClassFactoryRegistrar | |
| 97 : public CComObjectRootEx<CComObjectThreadModel>, | |
| 98 public CComCoClass<BrokerClassFactoryRegistrar<target_clsid, | |
| 99 target_clsid2, | |
| 100 broker_clsid, | |
| 101 broker_progid> > { | |
| 102 public: | |
| 103 BrokerClassFactoryRegistrar() { | |
| 104 ASSERT1(false); | |
| 105 } | |
| 106 | |
| 107 typedef BrokerClassFactory<target_clsid, target_clsid2> BrokerClassFactoryT; | |
| 108 | |
| 109 DECLARE_CLASSFACTORY_EX(BrokerClassFactoryT); | |
| 110 DECLARE_NOT_AGGREGATABLE(BrokerClassFactoryRegistrar); | |
| 111 DECLARE_REGISTRY_RESOURCEID_EX(IDR_LOCAL_SERVER_ELEVATION_RGS) | |
| 112 | |
| 113 BEGIN_REGISTRY_MAP() | |
| 114 REGMAP_ENTRY(_T("PROGID"), broker_progid) | |
| 115 REGMAP_ENTRY(_T("VERSION"), _T("1.0")) | |
| 116 REGMAP_ENTRY(L"DESCRIPTION", L"Google Update Broker Class Factory") | |
| 117 REGMAP_ENTRY(L"CLSID", broker_clsid) | |
| 118 REGMAP_ENTRY(L"ICONRESID", PP_STRINGIZE(IDI_ELEVATION_MONIKER_ICON)) | |
| 119 REGMAP_ENTRY(L"STRINGRESID", | |
| 120 PP_STRINGIZE(IDS_ELEVATION_MONIKER_DISPLAYNAME)) | |
| 121 REGMAP_MODULE2(L"MODULE", kOmahaBrokerFileName) | |
| 122 END_REGISTRY_MAP() | |
| 123 | |
| 124 BEGIN_COM_MAP(BrokerClassFactoryRegistrar) | |
| 125 END_COM_MAP() | |
| 126 | |
| 127 protected: | |
| 128 virtual ~BrokerClassFactoryRegistrar() {} | |
| 129 | |
| 130 private: | |
| 131 DISALLOW_COPY_AND_ASSIGN(BrokerClassFactoryRegistrar); | |
| 132 }; | |
| 133 | |
| 134 #pragma warning(pop) | |
| 135 | |
| 136 extern TCHAR kOnDemandMachineBrokerProgId[]; | |
| 137 extern TCHAR kUpdate3WebMachineBrokerProgId[]; | |
| 138 | |
| 139 // An OnDemand client CoCreates OnDemandMachineAppsClass, which | |
| 140 // instantiates the class factory for the OnDemandMachineBroker typedef below. | |
| 141 // The class factory in turn passes the CreateInstance through to | |
| 142 // OnDemandMachineAppsServiceClass. | |
| 143 typedef BrokerClassFactoryRegistrar<__uuidof(OnDemandMachineAppsServiceClass), | |
| 144 __uuidof(OnDemandMachineAppsFallbackClass), | |
| 145 __uuidof(OnDemandMachineAppsClass), | |
| 146 kOnDemandMachineBrokerProgId> | |
| 147 OnDemandMachineBroker; | |
| 148 | |
| 149 // The Pack web plugin client CoCreates GoogleUpdate3WebMachineClass, which | |
| 150 // instantiates the class factory for the Update3WebBroker typedef below. The | |
| 151 // class factory in turn passes the CreateInstance through to | |
| 152 // GoogleUpdate3WebServiceClass. | |
| 153 typedef BrokerClassFactoryRegistrar< | |
| 154 __uuidof(GoogleUpdate3WebServiceClass), | |
| 155 __uuidof(GoogleUpdate3WebMachineFallbackClass), | |
| 156 __uuidof(GoogleUpdate3WebMachineClass), | |
| 157 kUpdate3WebMachineBrokerProgId> | |
| 158 Update3WebMachineBroker; | |
| 159 | |
| 160 } // namespace omaha | |
| 161 | |
| 162 #endif // OMAHA_GOOPDATE_BROKER_CLASS_FACTORY_H_ | |
| OLD | NEW |