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

Side by Side Diff: ppapi/shared_impl/scoped_pp_resource.cc

Issue 7669055: Remove webkit::ppapi::Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nulls auditeed Created 9 years, 4 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
« no previous file with comments | « ppapi/shared_impl/scoped_pp_resource.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ppapi/shared_impl/scoped_pp_resource.h"
6
7 #include "ppapi/shared_impl/resource.h"
8 #include "ppapi/shared_impl/resource_tracker.h"
9 #include "ppapi/shared_impl/tracker_base.h"
10
11 namespace ppapi {
12
13 ScopedPPResource::ScopedPPResource() : id_(0) {
14 }
15
16 ScopedPPResource::ScopedPPResource(PP_Resource resource) : id_(resource) {
17 CallAddRef();
18 }
19
20 ScopedPPResource::ScopedPPResource(Resource* resource)
21 : id_(resource ? resource->GetReference() : 0) {
22 // GetReference AddRef's for us.
23 }
24
25 ScopedPPResource::ScopedPPResource(const ScopedPPResource& other)
26 : id_(other.id_) {
27 CallAddRef();
28 }
29
30 ScopedPPResource::~ScopedPPResource() {
31 CallRelease();
32 }
33
34 ScopedPPResource& ScopedPPResource::operator=(PP_Resource resource) {
35 if (id_ == resource)
36 return *this; // Be careful about self-assignment.
37 CallRelease();
38 id_ = resource;
39 CallAddRef();
40 return *this;
41 }
42
43 ScopedPPResource& ScopedPPResource::operator=(
44 const ScopedPPResource& resource) {
45 if (id_ == resource.id_)
46 return *this; // Be careful about self-assignment.
47 CallRelease();
48 id_ = resource.id_;
49 CallAddRef();
50 return *this;
51 }
52
53 PP_Resource ScopedPPResource::Release() {
54 CallRelease();
55
56 PP_Resource ret = id_;
57 id_ = NULL;
58 return ret;
59 }
60
61 void ScopedPPResource::CallAddRef() {
62 if (id_)
63 TrackerBase::Get()->GetResourceTracker()->AddRefResource(id_);
64 }
65
66 void ScopedPPResource::CallRelease() {
67 if (id_)
68 TrackerBase::Get()->GetResourceTracker()->ReleaseResource(id_);
69 }
70
71 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/scoped_pp_resource.h ('k') | webkit/glue/webkit_glue.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698