Chromium Code Reviews| 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 BASE_WIN_SCOPED_COMPTR_H_ | 5 #ifndef BASE_WIN_SCOPED_COMPTR_H_ |
| 6 #define BASE_WIN_SCOPED_COMPTR_H_ | 6 #define BASE_WIN_SCOPED_COMPTR_H_ |
| 7 | 7 |
| 8 #include <unknwn.h> | 8 #include <unknwn.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 | 126 |
| 127 if (!other || !ptr_) | 127 if (!other || !ptr_) |
| 128 return false; | 128 return false; |
| 129 | 129 |
| 130 ScopedComPtr<IUnknown> my_identity; | 130 ScopedComPtr<IUnknown> my_identity; |
| 131 QueryInterface(my_identity.Receive()); | 131 QueryInterface(my_identity.Receive()); |
| 132 | 132 |
| 133 ScopedComPtr<IUnknown> other_identity; | 133 ScopedComPtr<IUnknown> other_identity; |
| 134 other->QueryInterface(other_identity.Receive()); | 134 other->QueryInterface(other_identity.Receive()); |
| 135 | 135 |
| 136 return static_cast<IUnknown*>(my_identity) == | 136 return static_cast<IUnknown*>(my_identity.get()) == |
| 137 static_cast<IUnknown*>(other_identity); | 137 static_cast<IUnknown*>(other_identity.get()); |
|
dcheng
2014/11/12 23:37:54
I'm reverting this, because once the implicit conv
| |
| 138 } | 138 } |
| 139 | 139 |
| 140 // Provides direct access to the interface. | 140 // Provides direct access to the interface. |
| 141 // Here we use a well known trick to make sure we block access to | 141 // Here we use a well known trick to make sure we block access to |
| 142 // IUnknown methods so that something bad like this doesn't happen: | 142 // IUnknown methods so that something bad like this doesn't happen: |
| 143 // ScopedComPtr<IUnknown> p(Foo()); | 143 // ScopedComPtr<IUnknown> p(Foo()); |
| 144 // p->Release(); | 144 // p->Release(); |
| 145 // ... later the destructor runs, which will Release() again. | 145 // ... later the destructor runs, which will Release() again. |
| 146 // and to get the benefit of the DCHECKs we add to QueryInterface. | 146 // and to get the benefit of the DCHECKs we add to QueryInterface. |
| 147 // There's still a way to call these methods if you absolutely must | 147 // There's still a way to call these methods if you absolutely must |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 159 | 159 |
| 160 static const IID& iid() { | 160 static const IID& iid() { |
| 161 return *interface_id; | 161 return *interface_id; |
| 162 } | 162 } |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 } // namespace win | 165 } // namespace win |
| 166 } // namespace base | 166 } // namespace base |
| 167 | 167 |
| 168 #endif // BASE_WIN_SCOPED_COMPTR_H_ | 168 #endif // BASE_WIN_SCOPED_COMPTR_H_ |
| OLD | NEW |