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

Side by Side Diff: ppapi/thunk/enter.h

Issue 7629017: Add a unified resource tracker shared between the proxy and the impl. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #ifndef PPAPI_THUNK_ENTER_H_ 5 #ifndef PPAPI_THUNK_ENTER_H_
6 #define PPAPI_THUNK_ENTER_H_ 6 #define PPAPI_THUNK_ENTER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "ppapi/c/pp_resource.h" 9 #include "ppapi/c/pp_resource.h"
10 #include "ppapi/proxy/interface_id.h" 10 #include "ppapi/proxy/interface_id.h"
11 #include "ppapi/shared_impl/function_group_base.h" 11 #include "ppapi/shared_impl/function_group_base.h"
12 #include "ppapi/shared_impl/resource_object_base.h" 12 #include "ppapi/shared_impl/resource.h"
13 #include "ppapi/shared_impl/tracker_base.h" 13 #include "ppapi/shared_impl/tracker_base.h"
14 #include "ppapi/shared_impl/resource_tracker.h"
14 15
15 namespace ppapi { 16 namespace ppapi {
16 namespace thunk { 17 namespace thunk {
17 18
18 // EnterHost* helper objects: These objects wrap a call from the C PPAPI into 19 // EnterHost* helper objects: These objects wrap a call from the C PPAPI into
19 // the internal implementation. They make sure the lock is acquired and will 20 // the internal implementation. They make sure the lock is acquired and will
20 // automatically set up some stuff for you. 21 // automatically set up some stuff for you.
21 // 22 //
22 // You should always check whether the enter succeeded before using the object. 23 // You should always check whether the enter succeeded before using the object.
23 // If this fails, then the instance or resource ID supplied was invalid. 24 // If this fails, then the instance or resource ID supplied was invalid.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // TODO(brettw) assert the lock is held. 71 // TODO(brettw) assert the lock is held.
71 } 72 }
72 }; 73 };
73 74
74 // Used when a caller has a resource, and wants to do EnterFunction for the 75 // Used when a caller has a resource, and wants to do EnterFunction for the
75 // instance corresponding to that resource. 76 // instance corresponding to that resource.
76 template<typename FunctionsT> 77 template<typename FunctionsT>
77 class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { 78 class EnterFunctionGivenResource : public EnterFunction<FunctionsT> {
78 public: 79 public:
79 EnterFunctionGivenResource(PP_Resource resource, bool report_error) 80 EnterFunctionGivenResource(PP_Resource resource, bool report_error)
80 : EnterFunction<FunctionsT>( 81 : EnterFunction<FunctionsT>(GetInstanceForResource(resource),
81 TrackerBase::Get()->GetInstanceForResource(resource), 82 report_error) {
82 report_error) { 83 }
84
85 private:
86 static PP_Instance GetInstanceForResource(PP_Resource resource) {
87 Resource* object =
88 TrackerBase::Get()->GetResourceTracker()->GetResource(resource);
89 return object ? object->pp_instance() : 0;
83 } 90 }
84 }; 91 };
85 92
86 // EnterResource --------------------------------------------------------------- 93 // EnterResource ---------------------------------------------------------------
87 94
88 template<typename ResourceT> 95 template<typename ResourceT>
89 class EnterResource { 96 class EnterResource {
90 public: 97 public:
91 EnterResource(PP_Resource resource, bool report_error) 98 EnterResource(PP_Resource resource, bool report_error)
92 : object_(NULL) { 99 : object_(NULL) {
93 ResourceObjectBase* base = TrackerBase::Get()->GetResourceAPI(resource); 100 Resource* base =
101 TrackerBase::Get()->GetResourceTracker()->GetResource(resource);
94 if (base) 102 if (base)
95 object_ = base->GetAs<ResourceT>(); 103 object_ = base->GetAs<ResourceT>();
96 // TODO(brettw) check error and if report_error is set, do something. 104 // TODO(brettw) check error and if report_error is set, do something.
97 } 105 }
98 ~EnterResource() {} 106 ~EnterResource() {}
99 107
100 bool succeeded() const { return !!object_; } 108 bool succeeded() const { return !!object_; }
101 bool failed() const { return !object_; } 109 bool failed() const { return !object_; }
102 110
103 ResourceT* object() { return object_; } 111 ResourceT* object() { return object_; }
(...skipping 12 matching lines...) Expand all
116 EnterResourceNoLock(PP_Resource resource, bool report_error) 124 EnterResourceNoLock(PP_Resource resource, bool report_error)
117 : EnterResource<ResourceT>(resource, report_error) { 125 : EnterResource<ResourceT>(resource, report_error) {
118 // TODO(brettw) assert the lock is held. 126 // TODO(brettw) assert the lock is held.
119 } 127 }
120 }; 128 };
121 129
122 } // namespace thunk 130 } // namespace thunk
123 } // namespace ppapi 131 } // namespace ppapi
124 132
125 #endif // PPAPI_THUNK_ENTER_H_ 133 #endif // PPAPI_THUNK_ENTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698