Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: base/win/scoped_bstr.cc

Issue 3781009: Move the windows-specific scoped_* stuff from base to base/win and in the bas... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "base/scoped_bstr_win.h" 5 #include "base/win/scoped_bstr.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace base {
10 namespace win {
9 11
10 ScopedBstr::ScopedBstr(const wchar_t* non_bstr) 12 ScopedBstr::ScopedBstr(const char16* non_bstr)
11 : bstr_(SysAllocString(non_bstr)) { 13 : bstr_(SysAllocString(non_bstr)) {
12 } 14 }
13 15
14 ScopedBstr::~ScopedBstr() { 16 ScopedBstr::~ScopedBstr() {
15 COMPILE_ASSERT(sizeof(ScopedBstr) == sizeof(BSTR), ScopedBstrSize); 17 COMPILE_ASSERT(sizeof(ScopedBstr) == sizeof(BSTR), ScopedBstrSize);
16 SysFreeString(bstr_); 18 SysFreeString(bstr_);
17 } 19 }
18 20
19 void ScopedBstr::Reset(BSTR bstr) { 21 void ScopedBstr::Reset(BSTR bstr) {
20 if (bstr != bstr_) { 22 if (bstr != bstr_) {
(...skipping 13 matching lines...) Expand all
34 BSTR tmp = bstr_; 36 BSTR tmp = bstr_;
35 bstr_ = bstr2.bstr_; 37 bstr_ = bstr2.bstr_;
36 bstr2.bstr_ = tmp; 38 bstr2.bstr_ = tmp;
37 } 39 }
38 40
39 BSTR* ScopedBstr::Receive() { 41 BSTR* ScopedBstr::Receive() {
40 DCHECK(bstr_ == NULL) << "BSTR leak."; 42 DCHECK(bstr_ == NULL) << "BSTR leak.";
41 return &bstr_; 43 return &bstr_;
42 } 44 }
43 45
44 BSTR ScopedBstr::Allocate(const wchar_t* wide_str) { 46 BSTR ScopedBstr::Allocate(const char16* str) {
45 Reset(SysAllocString(wide_str)); 47 Reset(SysAllocString(str));
46 return bstr_; 48 return bstr_;
47 } 49 }
48 50
49 BSTR ScopedBstr::AllocateBytes(int bytes) { 51 BSTR ScopedBstr::AllocateBytes(size_t bytes) {
50 Reset(SysAllocStringByteLen(NULL, bytes)); 52 Reset(SysAllocStringByteLen(NULL, bytes));
51 return bstr_; 53 return bstr_;
52 } 54 }
53 55
54 void ScopedBstr::SetByteLen(uint32 bytes) { 56 void ScopedBstr::SetByteLen(size_t bytes) {
55 DCHECK(bstr_ != NULL) << "attempting to modify a NULL bstr"; 57 DCHECK(bstr_ != NULL) << "attempting to modify a NULL bstr";
56 uint32* data = reinterpret_cast<uint32*>(bstr_); 58 uint32* data = reinterpret_cast<uint32*>(bstr_);
57 data[-1] = bytes; 59 data[-1] = bytes;
58 } 60 }
59 61
60 uint32 ScopedBstr::Length() const { 62 size_t ScopedBstr::Length() const {
61 return SysStringLen(bstr_); 63 return SysStringLen(bstr_);
62 } 64 }
63 65
64 uint32 ScopedBstr::ByteLength() const { 66 size_t ScopedBstr::ByteLength() const {
65 return SysStringByteLen(bstr_); 67 return SysStringByteLen(bstr_);
66 } 68 }
69
70 } // namespace win
71 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698