| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_FRAME_DLL_REDIRECTOR_H_ | 5 #ifndef CHROME_FRAME_DLL_REDIRECTOR_H_ |
| 6 #define CHROME_FRAME_DLL_REDIRECTOR_H_ | 6 #define CHROME_FRAME_DLL_REDIRECTOR_H_ |
| 7 | 7 |
| 8 #include <ObjBase.h> | 8 #include <ObjBase.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 15 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
| 16 | 16 |
| 17 // Forward | 17 // Forward |
| 18 namespace ATL { | 18 namespace ATL { |
| 19 class CSecurityAttributes; | 19 class CSecurityAttributes; |
| 20 } | 20 } |
| 21 |
| 22 namespace base { |
| 21 class Version; | 23 class Version; |
| 24 } |
| 22 | 25 |
| 23 // A singleton class that provides a facility to register the version of the | 26 // A singleton class that provides a facility to register the version of the |
| 24 // current module as the only version that should be loaded system-wide. If | 27 // current module as the only version that should be loaded system-wide. If |
| 25 // this module is not the first instance loaded in the system, then the version | 28 // this module is not the first instance loaded in the system, then the version |
| 26 // that loaded first will be delegated to. This makes a few assumptions: | 29 // that loaded first will be delegated to. This makes a few assumptions: |
| 27 // 1) That different versions of the module this code is in reside in | 30 // 1) That different versions of the module this code is in reside in |
| 28 // neighbouring versioned directories, e.g. | 31 // neighbouring versioned directories, e.g. |
| 29 // C:\foo\bar\1.2.3.4\my_module.dll | 32 // C:\foo\bar\1.2.3.4\my_module.dll |
| 30 // C:\foo\bar\1.2.3.5\my_module.dll | 33 // C:\foo\bar\1.2.3.5\my_module.dll |
| 31 // 2) That the instance of this class will outlive the module that may be | 34 // 2) That the instance of this class will outlive the module that may be |
| (...skipping 30 matching lines...) Expand all Loading... |
| 62 DllRedirector(); | 65 DllRedirector(); |
| 63 friend struct DefaultSingletonTraits<DllRedirector>; | 66 friend struct DefaultSingletonTraits<DllRedirector>; |
| 64 | 67 |
| 65 // Constructor used for tests. | 68 // Constructor used for tests. |
| 66 explicit DllRedirector(const char* shared_memory_name); | 69 explicit DllRedirector(const char* shared_memory_name); |
| 67 | 70 |
| 68 // Returns an HMODULE to the version of the module that should be loaded. | 71 // Returns an HMODULE to the version of the module that should be loaded. |
| 69 virtual HMODULE GetFirstModule(); | 72 virtual HMODULE GetFirstModule(); |
| 70 | 73 |
| 71 // Returns the version of the current module or NULL if none can be found. | 74 // Returns the version of the current module or NULL if none can be found. |
| 72 // The caller must free the Version. | 75 // The caller must free the returned version. |
| 73 virtual Version* GetCurrentModuleVersion(); | 76 virtual base::Version* GetCurrentModuleVersion(); |
| 74 | 77 |
| 75 // Attempt to load the specified version dll. Finds it by walking up one | 78 // Attempt to load the specified version dll. Finds it by walking up one |
| 76 // directory from our current module's location, then appending the newly | 79 // directory from our current module's location, then appending the newly |
| 77 // found version number. The Version class in base will have ensured that we | 80 // found version number. The Version class in base will have ensured that we |
| 78 // actually have a valid version and not e.g. ..\..\..\..\MyEvilFolder\. | 81 // actually have a valid version and not e.g. ..\..\..\..\MyEvilFolder\. |
| 79 virtual HMODULE LoadVersionedModule(Version* version); | 82 virtual HMODULE LoadVersionedModule(base::Version* version); |
| 80 | 83 |
| 81 // Builds the necessary SECURITY_ATTRIBUTES to allow low integrity access | 84 // Builds the necessary SECURITY_ATTRIBUTES to allow low integrity access |
| 82 // to an object. Returns true on success, false otherwise. | 85 // to an object. Returns true on success, false otherwise. |
| 83 virtual bool BuildSecurityAttributesForLock( | 86 virtual bool BuildSecurityAttributesForLock( |
| 84 ATL::CSecurityAttributes* sec_attr); | 87 ATL::CSecurityAttributes* sec_attr); |
| 85 | 88 |
| 86 // Attempts to change the permissions on the given file mapping to read only. | 89 // Attempts to change the permissions on the given file mapping to read only. |
| 87 // Returns true on success, false otherwise. | 90 // Returns true on success, false otherwise. |
| 88 virtual bool SetFileMappingToReadOnly(base::SharedMemoryHandle mapping); | 91 virtual bool SetFileMappingToReadOnly(base::SharedMemoryHandle mapping); |
| 89 | 92 |
| 90 // Shared memory segment that contains the version beacon. | 93 // Shared memory segment that contains the version beacon. |
| 91 scoped_ptr<base::SharedMemory> shared_memory_; | 94 scoped_ptr<base::SharedMemory> shared_memory_; |
| 92 | 95 |
| 93 // The current version of the DLL to be loaded. | 96 // The current version of the DLL to be loaded. |
| 94 scoped_ptr<Version> dll_version_; | 97 scoped_ptr<base::Version> dll_version_; |
| 95 | 98 |
| 96 // The handle to the first version of this module that was loaded. This | 99 // The handle to the first version of this module that was loaded. This |
| 97 // may refer to the current module, or another version of the same module | 100 // may refer to the current module, or another version of the same module |
| 98 // that we go and load. | 101 // that we go and load. |
| 99 HMODULE first_module_handle_; | 102 HMODULE first_module_handle_; |
| 100 | 103 |
| 101 // Used for tests to override the name of the shared memory segment. | 104 // Used for tests to override the name of the shared memory segment. |
| 102 std::string shared_memory_name_; | 105 std::string shared_memory_name_; |
| 103 | 106 |
| 104 friend class ModuleUtilsTest; | 107 friend class ModuleUtilsTest; |
| 105 | 108 |
| 106 DISALLOW_COPY_AND_ASSIGN(DllRedirector); | 109 DISALLOW_COPY_AND_ASSIGN(DllRedirector); |
| 107 }; | 110 }; |
| 108 | 111 |
| 109 #endif // CHROME_FRAME_DLL_REDIRECTOR_H_ | 112 #endif // CHROME_FRAME_DLL_REDIRECTOR_H_ |
| OLD | NEW |