OLD | NEW |
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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 instance, FunctionsT::interface_id); | 45 instance, FunctionsT::interface_id); |
46 if (base) | 46 if (base) |
47 functions_ = base->GetAs<FunctionsT>(); | 47 functions_ = base->GetAs<FunctionsT>(); |
48 // TODO(brettw) check error and if report_error is set, do something. | 48 // TODO(brettw) check error and if report_error is set, do something. |
49 } | 49 } |
50 ~EnterFunction() {} | 50 ~EnterFunction() {} |
51 | 51 |
52 bool succeeded() const { return !!functions_; } | 52 bool succeeded() const { return !!functions_; } |
53 bool failed() const { return !functions_; } | 53 bool failed() const { return !functions_; } |
54 | 54 |
| 55 PP_Instance instance() const { return instance_; } |
55 FunctionsT* functions() { return functions_; } | 56 FunctionsT* functions() { return functions_; } |
56 | 57 |
57 private: | 58 private: |
| 59 PP_Instance instance_; |
58 FunctionsT* functions_; | 60 FunctionsT* functions_; |
59 | 61 |
60 DISALLOW_COPY_AND_ASSIGN(EnterFunction); | 62 DISALLOW_COPY_AND_ASSIGN(EnterFunction); |
61 }; | 63 }; |
62 | 64 |
63 // Like EnterResource but assumes the lock is already held. | 65 // Like EnterResource but assumes the lock is already held. |
64 // TODO(brettw) actually implement locks, this is just a placeholder for now. | 66 // TODO(brettw) actually implement locks, this is just a placeholder for now. |
65 template<typename FunctionsT> | 67 template<typename FunctionsT> |
66 class EnterFunctionNoLock : public EnterFunction<FunctionsT> { | 68 class EnterFunctionNoLock : public EnterFunction<FunctionsT> { |
67 public: | 69 public: |
68 EnterFunctionNoLock(PP_Instance instance, bool report_error) | 70 EnterFunctionNoLock(PP_Instance instance, bool report_error) |
69 : EnterFunction<FunctionsT>(instance, report_error) { | 71 : EnterFunction<FunctionsT>(instance, report_error) { |
70 // TODO(brettw) assert the lock is held. | 72 // TODO(brettw) assert the lock is held. |
71 } | 73 } |
72 }; | 74 }; |
73 | 75 |
| 76 // Used when a caller has a resource, and wants to do EnterFunction for the |
| 77 // instance corresponding to that resource. |
| 78 template<typename FunctionsT> |
| 79 class EnterFunctionGivenResource : public EnterFunction<FunctionsT> { |
| 80 public: |
| 81 EnterFunctionGivenResource(PP_Resource resource, bool report_error) |
| 82 : EnterFunction<FunctionsT>( |
| 83 TrackerBase::Get()->GetInstanceForResource(resource), |
| 84 report_error) { |
| 85 } |
| 86 }; |
| 87 |
| 88 // EnterResource --------------------------------------------------------------- |
| 89 |
74 template<typename ResourceT> | 90 template<typename ResourceT> |
75 class EnterResource { | 91 class EnterResource { |
76 public: | 92 public: |
77 EnterResource(PP_Resource resource, bool report_error) | 93 EnterResource(PP_Resource resource, bool report_error) |
78 : object_(NULL) { | 94 : object_(NULL) { |
79 ResourceObjectBase* base = TrackerBase::Get()->GetResourceAPI(resource); | 95 ResourceObjectBase* base = TrackerBase::Get()->GetResourceAPI(resource); |
80 if (base) | 96 if (base) |
81 object_ = base->GetAs<ResourceT>(); | 97 object_ = base->GetAs<ResourceT>(); |
82 // TODO(brettw) check error and if report_error is set, do something. | 98 // TODO(brettw) check error and if report_error is set, do something. |
83 } | 99 } |
(...skipping 18 matching lines...) Expand all Loading... |
102 EnterResourceNoLock(PP_Resource resource, bool report_error) | 118 EnterResourceNoLock(PP_Resource resource, bool report_error) |
103 : EnterResource<ResourceT>(resource, report_error) { | 119 : EnterResource<ResourceT>(resource, report_error) { |
104 // TODO(brettw) assert the lock is held. | 120 // TODO(brettw) assert the lock is held. |
105 } | 121 } |
106 }; | 122 }; |
107 | 123 |
108 } // namespace thunk | 124 } // namespace thunk |
109 } // namespace ppapi | 125 } // namespace ppapi |
110 | 126 |
111 #endif // PPAPI_THUNK_ENTER_H_ | 127 #endif // PPAPI_THUNK_ENTER_H_ |
OLD | NEW |