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

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

Issue 9235003: Enhance the PPAPI enter tracking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix build Created 8 years, 11 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/thunk/enter.h ('k') | ppapi/thunk/ppb_graphics_2d_thunk.cc » ('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) 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 #include "ppapi/thunk/enter.h" 5 #include "ppapi/thunk/enter.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/message_loop.h"
10 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/thunk/ppb_instance_api.h" 11 #include "ppapi/thunk/ppb_instance_api.h"
9 #include "ppapi/thunk/resource_creation_api.h" 12 #include "ppapi/thunk/resource_creation_api.h"
10 13
11 namespace ppapi { 14 namespace ppapi {
12 namespace thunk { 15 namespace thunk {
13 16
17 namespace subtle {
18
19 bool CallbackIsRequired(const PP_CompletionCallback& callback) {
20 return callback.func != NULL &&
21 (callback.flags & PP_COMPLETIONCALLBACK_FLAG_OPTIONAL) == 0;
22 }
23
24 EnterBase::EnterBase()
25 : callback_(PP_BlockUntilComplete()),
26 retval_(PP_OK) {
27 // TODO(brettw) validate threads.
28 }
29
30 EnterBase::EnterBase(const PP_CompletionCallback& callback)
31 : callback_(CallbackIsRequired(callback) ? callback
32 : PP_BlockUntilComplete()),
33 retval_(PP_OK) {
34 // TODO(brettw) validate threads.
35 }
36
37 EnterBase::~EnterBase() {
38 if (callback_.func) {
39 // All async completions should have cleared the callback in SetResult().
40 DCHECK(retval_ != PP_OK_COMPLETIONPENDING && retval_ != PP_OK);
41 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
42 callback_.func, callback_.user_data, retval_));
43 }
44 }
45
46 int32_t EnterBase::SetResult(int32_t result) {
47 if (!callback_.func || result == PP_OK_COMPLETIONPENDING) {
48 // Easy case, we don't need to issue the callback (either none is
49 // required, or the implementation will asynchronously issue it
50 // for us), just store the result.
51 callback_ = PP_BlockUntilComplete();
52 retval_ = result;
53 return retval_;
54 }
55
56 // This is a required callback, asynchronously issue it.
57 // TODO(brettw) make this work on different threads, etc.
58 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
59 callback_.func, callback_.user_data, result));
60
61 // Now that the callback will be issued in the future, we should return
62 // "pending" to the caller, and not issue the callback again.
63 callback_ = PP_BlockUntilComplete();
64 retval_ = PP_OK_COMPLETIONPENDING;
65 return retval_;
66 }
67
68 FunctionGroupBase* EnterBase::GetFunctions(PP_Instance instance,
69 ApiID id) const {
70 return PpapiGlobals::Get()->GetFunctionAPI(instance, id);
71 }
72
73 Resource* EnterBase::GetResource(PP_Resource resource) const {
74 return PpapiGlobals::Get()->GetResourceTracker()->GetResource(resource);
75 }
76
77 void EnterBase::SetStateForResourceError(PP_Resource /* pp_resource */,
78 Resource* /* resource_base */,
79 void* object,
80 bool /* report_error */) {
81 if (object)
82 return; // Everything worked.
83
84 retval_ = PP_ERROR_BADRESOURCE;
85 // TODO(brettw) log the error.
86 }
87
88 } // namespace subtle
89
14 EnterResourceCreation::EnterResourceCreation(PP_Instance instance) 90 EnterResourceCreation::EnterResourceCreation(PP_Instance instance)
15 : EnterFunctionNoLock<ResourceCreationAPI>(instance, true) { 91 : EnterFunctionNoLock<ResourceCreationAPI>(instance, true) {
16 } 92 }
17 93
18 EnterResourceCreation::~EnterResourceCreation() { 94 EnterResourceCreation::~EnterResourceCreation() {
19 } 95 }
20 96
21 EnterInstance::EnterInstance(PP_Instance instance) 97 EnterInstance::EnterInstance(PP_Instance instance)
22 : EnterFunctionNoLock<PPB_Instance_FunctionAPI>(instance, true) { 98 : EnterFunctionNoLock<PPB_Instance_FunctionAPI>(instance, true) {
23 } 99 }
24 100
25 EnterInstance::~EnterInstance() { 101 EnterInstance::~EnterInstance() {
26 } 102 }
27 103
28 } // namespace thunk 104 } // namespace thunk
29 } // namespace ppapi 105 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/thunk/enter.h ('k') | ppapi/thunk/ppb_graphics_2d_thunk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698