Chromium Code Reviews

Side by Side Diff: ppapi/cpp/resource.cc

Issue 6212003: Fix self-assignment in pp::Resource (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 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 "ppapi/cpp/resource.h" 5 #include "ppapi/cpp/resource.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ppapi/cpp/logging.h" 9 #include "ppapi/cpp/logging.h"
10 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
11 11
12 namespace pp { 12 namespace pp {
13 13
14 Resource::Resource() : pp_resource_(0) { 14 Resource::Resource() : pp_resource_(0) {
15 } 15 }
16 16
17 Resource::Resource(const Resource& other) : pp_resource_(other.pp_resource_) { 17 Resource::Resource(const Resource& other) : pp_resource_(other.pp_resource_) {
18 if (!is_null()) 18 if (!is_null())
19 Module::Get()->core()->AddRefResource(pp_resource_); 19 Module::Get()->core()->AddRefResource(pp_resource_);
20 } 20 }
21 21
22 Resource::~Resource() { 22 Resource::~Resource() {
23 if (!is_null()) 23 if (!is_null())
24 Module::Get()->core()->ReleaseResource(pp_resource_); 24 Module::Get()->core()->ReleaseResource(pp_resource_);
25 } 25 }
26 26
27 Resource& Resource::operator=(const Resource& other) { 27 Resource& Resource::operator=(const Resource& other) {
28 if (!other.is_null())
29 Module::Get()->core()->AddRefResource(other.pp_resource_);
28 if (!is_null()) 30 if (!is_null())
29 Module::Get()->core()->ReleaseResource(pp_resource_); 31 Module::Get()->core()->ReleaseResource(pp_resource_);
30 pp_resource_ = other.pp_resource_; 32 pp_resource_ = other.pp_resource_;
31 if (!is_null())
32 Module::Get()->core()->AddRefResource(pp_resource_);
33 return *this; 33 return *this;
34 } 34 }
35 35
36 PP_Resource Resource::detach() { 36 PP_Resource Resource::detach() {
37 PP_Resource ret = pp_resource_; 37 PP_Resource ret = pp_resource_;
38 pp_resource_ = 0; 38 pp_resource_ = 0;
39 return ret; 39 return ret;
40 } 40 }
41 41
42 Resource::Resource(PP_Resource resource) : pp_resource_(resource) { 42 Resource::Resource(PP_Resource resource) : pp_resource_(resource) {
43 if (!is_null()) 43 if (!is_null())
44 Module::Get()->core()->AddRefResource(pp_resource_); 44 Module::Get()->core()->AddRefResource(pp_resource_);
45 } 45 }
46 46
47 void Resource::PassRefFromConstructor(PP_Resource resource) { 47 void Resource::PassRefFromConstructor(PP_Resource resource) {
48 PP_DCHECK(!pp_resource_); 48 PP_DCHECK(!pp_resource_);
49 pp_resource_ = resource; 49 pp_resource_ = resource;
50 } 50 }
51 51
52 } // namespace pp 52 } // namespace pp
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine