Output data about media requests to the netlog too.
[chromium-blink-merge.git] / base / scoped_bstr_win.cc
blob673aca2b2034903ed6b778918b2fdc89ead23387
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/scoped_bstr_win.h"
7 #include "base/logging.h"
10 ScopedBstr::ScopedBstr(const wchar_t* non_bstr)
11 : bstr_(SysAllocString(non_bstr)) {
14 ScopedBstr::~ScopedBstr() {
15 COMPILE_ASSERT(sizeof(ScopedBstr) == sizeof(BSTR), ScopedBstrSize);
16 SysFreeString(bstr_);
19 void ScopedBstr::Reset(BSTR bstr) {
20 if (bstr != bstr_) {
21 // if |bstr_| is NULL, SysFreeString does nothing.
22 SysFreeString(bstr_);
23 bstr_ = bstr;
27 BSTR ScopedBstr::Release() {
28 BSTR bstr = bstr_;
29 bstr_ = NULL;
30 return bstr;
33 void ScopedBstr::Swap(ScopedBstr& bstr2) {
34 BSTR tmp = bstr_;
35 bstr_ = bstr2.bstr_;
36 bstr2.bstr_ = tmp;
39 BSTR* ScopedBstr::Receive() {
40 DCHECK(bstr_ == NULL) << "BSTR leak.";
41 return &bstr_;
44 BSTR ScopedBstr::Allocate(const wchar_t* wide_str) {
45 Reset(SysAllocString(wide_str));
46 return bstr_;
49 BSTR ScopedBstr::AllocateBytes(int bytes) {
50 Reset(SysAllocStringByteLen(NULL, bytes));
51 return bstr_;
54 void ScopedBstr::SetByteLen(uint32 bytes) {
55 DCHECK(bstr_ != NULL) << "attempting to modify a NULL bstr";
56 uint32* data = reinterpret_cast<uint32*>(bstr_);
57 data[-1] = bytes;
60 uint32 ScopedBstr::Length() const {
61 return SysStringLen(bstr_);
64 uint32 ScopedBstr::ByteLength() const {
65 return SysStringByteLen(bstr_);