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 3 // found in the LICENSE file. 4 5 #include "ppapi/cpp/resource.h" 6 7 #include <algorithm> 8 9 #include "ppapi/cpp/logging.h" 10 #include "ppapi/cpp/module.h" 11 12 namespace pp { 13 Resource()14Resource::Resource() : pp_resource_(0) { 15 } 16 Resource(const Resource & other)17Resource::Resource(const Resource& other) : pp_resource_(other.pp_resource_) { 18 if (!is_null()) 19 Module::Get()->core()->AddRefResource(pp_resource_); 20 } 21 ~Resource()22Resource::~Resource() { 23 if (!is_null()) 24 Module::Get()->core()->ReleaseResource(pp_resource_); 25 } 26 operator =(const Resource & other)27Resource& Resource::operator=(const Resource& other) { 28 if (!other.is_null()) 29 Module::Get()->core()->AddRefResource(other.pp_resource_); 30 if (!is_null()) 31 Module::Get()->core()->ReleaseResource(pp_resource_); 32 pp_resource_ = other.pp_resource_; 33 return *this; 34 } 35 detach()36PP_Resource Resource::detach() { 37 PP_Resource ret = pp_resource_; 38 pp_resource_ = 0; 39 return ret; 40 } 41 Resource(PP_Resource resource)42Resource::Resource(PP_Resource resource) : pp_resource_(resource) { 43 if (!is_null()) 44 Module::Get()->core()->AddRefResource(pp_resource_); 45 } 46 Resource(PassRef,PP_Resource resource)47Resource::Resource(PassRef, PP_Resource resource) : pp_resource_(resource) { 48 } 49 PassRefFromConstructor(PP_Resource resource)50void Resource::PassRefFromConstructor(PP_Resource resource) { 51 PP_DCHECK(!pp_resource_); 52 pp_resource_ = resource; 53 } 54 Clear()55void Resource::Clear() { 56 if (is_null()) 57 return; 58 Module::Get()->core()->ReleaseResource(pp_resource_); 59 pp_resource_ = 0; 60 } 61 62 } // namespace pp 63