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

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

Issue 11359063: Refactor the way singleton-style resources are exposed via PPB_Instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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/resource.h ('k') | ppapi/thunk/ppb_flash_clipboard_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 EnterInstanceNoLock(PP_Instance instance, 238 EnterInstanceNoLock(PP_Instance instance,
239 const PP_CompletionCallback& callback); 239 const PP_CompletionCallback& callback);
240 ~EnterInstanceNoLock(); 240 ~EnterInstanceNoLock();
241 241
242 PPB_Instance_API* functions() { return functions_; } 242 PPB_Instance_API* functions() { return functions_; }
243 243
244 private: 244 private:
245 PPB_Instance_API* functions_; 245 PPB_Instance_API* functions_;
246 }; 246 };
247 247
248 // EnterInstanceAPI ------------------------------------------------------------
249
250 template<typename ApiT, bool lock_on_entry = true>
251 class PPAPI_THUNK_EXPORT EnterInstanceAPI
252 : public subtle::EnterBase,
253 public subtle::LockOnEntry<lock_on_entry> {
254 public:
255 EnterInstanceAPI(PP_Instance instance) : EnterBase() {
dmichael (off chromium) 2012/11/21 17:26:26 nit: explicit
raymes 2012/11/21 20:59:10 Done.
256 functions_ = NULL;
dmichael (off chromium) 2012/11/21 17:26:26 nit: Why not initialize this in the initializer li
raymes 2012/11/21 20:59:10 Done.
257 PPB_Instance_API* ppb_instance =
258 PpapiGlobals::Get()->GetInstanceAPI(instance);
259 if (ppb_instance) {
260 Resource* resource =
261 ppb_instance->GetSingletonResource(instance,
262 ApiT::kSingletonResourceID);
263 if (resource)
264 functions_ = resource->GetAs<ApiT>();
265 }
266 SetStateForFunctionError(instance, functions_, true);
267 }
268 ~EnterInstanceAPI() {}
269
270 bool succeeded() const { return !!functions_; }
271 bool failed() const { return !functions_; }
272
273 ApiT* functions() { return functions_; }
dmichael (off chromium) 2012/11/21 17:26:26 I'm noticing we don't do this in EnterInstance eit
raymes 2012/11/21 20:59:10 As discussed, we can't return const ApiT* because
274
275 private:
276 ApiT* functions_;
277 };
278
279 template<typename ApiT>
280 class PPAPI_THUNK_EXPORT EnterInstanceAPINoLock
281 : public EnterInstanceAPI<ApiT, false> {
282 public:
283 EnterInstanceAPINoLock(PP_Instance instance)
284 : EnterInstanceAPI<ApiT, false>(instance) {
285 }
286 };
287
248 // EnterResourceCreation ------------------------------------------------------- 288 // EnterResourceCreation -------------------------------------------------------
249 289
250 class PPAPI_THUNK_EXPORT EnterResourceCreation 290 class PPAPI_THUNK_EXPORT EnterResourceCreation
251 : public subtle::EnterBase, 291 : public subtle::EnterBase,
252 public subtle::LockOnEntry<true> { 292 public subtle::LockOnEntry<true> {
253 public: 293 public:
254 EnterResourceCreation(PP_Instance instance); 294 EnterResourceCreation(PP_Instance instance);
255 ~EnterResourceCreation(); 295 ~EnterResourceCreation();
256 296
257 ResourceCreationAPI* functions() { return functions_; } 297 ResourceCreationAPI* functions() { return functions_; }
(...skipping 12 matching lines...) Expand all
270 ResourceCreationAPI* functions() { return functions_; } 310 ResourceCreationAPI* functions() { return functions_; }
271 311
272 private: 312 private:
273 ResourceCreationAPI* functions_; 313 ResourceCreationAPI* functions_;
274 }; 314 };
275 315
276 } // namespace thunk 316 } // namespace thunk
277 } // namespace ppapi 317 } // namespace ppapi
278 318
279 #endif // PPAPI_THUNK_ENTER_H_ 319 #endif // PPAPI_THUNK_ENTER_H_
OLDNEW
« no previous file with comments | « ppapi/shared_impl/resource.h ('k') | ppapi/thunk/ppb_flash_clipboard_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698