Add ability to change display settings to chrome.systemInfo.display
[chromium-blink-merge.git] / ppapi / shared_impl / scoped_pp_resource.cc
blob45a1ad77f03e68ab59c92af921e0fa49a0dbea41
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"
11 namespace ppapi {
13 ScopedPPResource::ScopedPPResource() : id_(0) {
16 ScopedPPResource::ScopedPPResource(PP_Resource resource) : id_(resource) {
17 CallAddRef();
20 ScopedPPResource::ScopedPPResource(const PassRef&, PP_Resource resource)
21 : id_(resource) {
24 ScopedPPResource::ScopedPPResource(Resource* resource)
25 : id_(resource ? resource->GetReference() : 0) {
26 // GetReference AddRef's for us.
29 ScopedPPResource::ScopedPPResource(const ScopedPPResource& other)
30 : id_(other.id_) {
31 CallAddRef();
34 ScopedPPResource::~ScopedPPResource() {
35 CallRelease();
38 ScopedPPResource& ScopedPPResource::operator=(PP_Resource resource) {
39 if (id_ == resource)
40 return *this; // Be careful about self-assignment.
41 CallRelease();
42 id_ = resource;
43 CallAddRef();
44 return *this;
47 ScopedPPResource& ScopedPPResource::operator=(
48 const ScopedPPResource& resource) {
49 if (id_ == resource.id_)
50 return *this; // Be careful about self-assignment.
51 CallRelease();
52 id_ = resource.id_;
53 CallAddRef();
54 return *this;
57 PP_Resource ScopedPPResource::Release() {
58 // We do NOT call CallRelease, because we want to pass our reference to the
59 // caller.
61 PP_Resource ret = id_;
62 id_ = 0;
63 return ret;
66 void ScopedPPResource::CallAddRef() {
67 if (id_)
68 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(id_);
71 void ScopedPPResource::CallRelease() {
72 if (id_)
73 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(id_);
76 } // namespace ppapi