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
3 // found in the LICENSE file.
5 #include "ppapi/shared_impl/scoped_pp_resource.h"
7 #include "ppapi/shared_impl/ppapi_globals.h"
8 #include "ppapi/shared_impl/resource.h"
9 #include "ppapi/shared_impl/resource_tracker.h"
13 ScopedPPResource::ScopedPPResource() : id_(0) {}
15 ScopedPPResource::ScopedPPResource(PP_Resource resource
) : id_(resource
) {
19 ScopedPPResource::ScopedPPResource(const PassRef
&, PP_Resource resource
)
22 ScopedPPResource::ScopedPPResource(Resource
* resource
)
23 : id_(resource
? resource
->GetReference() : 0) {
24 // GetReference AddRef's for us.
27 ScopedPPResource::ScopedPPResource(const ScopedPPResource
& other
)
32 ScopedPPResource::~ScopedPPResource() { CallRelease(); }
34 ScopedPPResource
& ScopedPPResource::operator=(PP_Resource resource
) {
36 return *this; // Be careful about self-assignment.
43 ScopedPPResource
& ScopedPPResource::operator=(
44 const ScopedPPResource
& resource
) {
45 if (id_
== resource
.id_
)
46 return *this; // Be careful about self-assignment.
53 PP_Resource
ScopedPPResource::Release() {
54 // We do NOT call CallRelease, because we want to pass our reference to the
57 PP_Resource ret
= id_
;
62 void ScopedPPResource::CallAddRef() {
64 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(id_
);
67 void ScopedPPResource::CallRelease() {
69 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(id_
);