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 #include "webkit/plugins/ppapi/ppb_broker_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_broker_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "webkit/plugins/ppapi/common.h" | 8 #include "webkit/plugins/ppapi/common.h" |
9 #include "webkit/plugins/ppapi/plugin_module.h" | 9 #include "webkit/plugins/ppapi/plugin_module.h" |
10 #include "webkit/plugins/ppapi/resource_helper.h" | |
10 | 11 |
11 using ::ppapi::thunk::PPB_Broker_API; | 12 using ::ppapi::thunk::PPB_Broker_API; |
12 | 13 |
13 namespace webkit { | 14 namespace webkit { |
14 namespace ppapi { | 15 namespace ppapi { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // TODO(ddorwin): Put conversion functions in a common place and/or add an | 19 // TODO(ddorwin): Put conversion functions in a common place and/or add an |
19 // invalid value to sync_socket.h. | 20 // invalid value to sync_socket.h. |
20 int32_t PlatformFileToInt(base::PlatformFile handle) { | 21 int32_t PlatformFileToInt(base::PlatformFile handle) { |
21 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
22 return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); | 23 return static_cast<int32_t>(reinterpret_cast<intptr_t>(handle)); |
23 #elif defined(OS_POSIX) | 24 #elif defined(OS_POSIX) |
24 return handle; | 25 return handle; |
25 #else | 26 #else |
26 #error Not implemented. | 27 #error Not implemented. |
27 #endif | 28 #endif |
28 } | 29 } |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 // PPB_Broker_Impl ------------------------------------------------------ | 33 // PPB_Broker_Impl ------------------------------------------------------ |
33 | 34 |
34 PPB_Broker_Impl::PPB_Broker_Impl(PluginInstance* instance) | 35 PPB_Broker_Impl::PPB_Broker_Impl(PP_Instance instance) |
35 : Resource(instance), | 36 : Resource(instance), |
36 broker_(NULL), | 37 broker_(NULL), |
37 connect_callback_(), | 38 connect_callback_(), |
38 pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)) { | 39 pipe_handle_(PlatformFileToInt(base::kInvalidPlatformFileValue)) { |
39 } | 40 } |
40 | 41 |
41 PPB_Broker_Impl::~PPB_Broker_Impl() { | 42 PPB_Broker_Impl::~PPB_Broker_Impl() { |
42 if (broker_) { | 43 if (broker_) { |
43 broker_->Disconnect(this); | 44 broker_->Disconnect(this); |
44 broker_ = NULL; | 45 broker_ = NULL; |
(...skipping 13 matching lines...) Expand all Loading... | |
58 return PP_ERROR_BADARGUMENT; | 59 return PP_ERROR_BADARGUMENT; |
59 } | 60 } |
60 | 61 |
61 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. | 62 // TODO(ddorwin): Return PP_ERROR_FAILED if plugin is in-process. |
62 | 63 |
63 if (broker_) { | 64 if (broker_) { |
64 // May only be called once. | 65 // May only be called once. |
65 return PP_ERROR_FAILED; | 66 return PP_ERROR_FAILED; |
66 } | 67 } |
67 | 68 |
69 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); | |
viettrungluu
2011/08/22 23:19:47
Maybe we should use plugin_instance for PluginInst
| |
70 | |
68 // The callback must be populated now in case we are connected to the broker | 71 // The callback must be populated now in case we are connected to the broker |
69 // and BrokerConnected is called before ConnectToPpapiBroker returns. | 72 // and BrokerConnected is called before ConnectToPpapiBroker returns. |
70 // Because it must be created now, it must be aborted and cleared if | 73 // Because it must be created now, it must be aborted and cleared if |
71 // ConnectToPpapiBroker fails. | 74 // ConnectToPpapiBroker fails. |
72 connect_callback_ = new TrackedCompletionCallback( | 75 connect_callback_ = new TrackedCompletionCallback( |
73 instance()->module()->GetCallbackTracker(), pp_resource(), | 76 instance->module()->GetCallbackTracker(), pp_resource(), |
74 connect_callback); | 77 connect_callback); |
75 | 78 |
76 broker_ = instance()->delegate()->ConnectToPpapiBroker(this); | 79 broker_ = instance->delegate()->ConnectToPpapiBroker(this); |
77 if (!broker_) { | 80 if (!broker_) { |
78 scoped_refptr<TrackedCompletionCallback> callback; | 81 scoped_refptr<TrackedCompletionCallback> callback; |
79 callback.swap(connect_callback_); | 82 callback.swap(connect_callback_); |
80 callback->Abort(); | 83 callback->Abort(); |
81 return PP_ERROR_FAILED; | 84 return PP_ERROR_FAILED; |
82 } | 85 } |
83 | 86 |
84 return PP_OK_COMPLETIONPENDING; | 87 return PP_OK_COMPLETIONPENDING; |
85 } | 88 } |
86 | 89 |
(...skipping 16 matching lines...) Expand all Loading... | |
103 // Synchronous calls are not supported. | 106 // Synchronous calls are not supported. |
104 DCHECK(connect_callback_.get() && !connect_callback_->completed()); | 107 DCHECK(connect_callback_.get() && !connect_callback_->completed()); |
105 | 108 |
106 scoped_refptr<TrackedCompletionCallback> callback; | 109 scoped_refptr<TrackedCompletionCallback> callback; |
107 callback.swap(connect_callback_); | 110 callback.swap(connect_callback_); |
108 callback->Run(result); // Will complete abortively if necessary. | 111 callback->Run(result); // Will complete abortively if necessary. |
109 } | 112 } |
110 | 113 |
111 } // namespace ppapi | 114 } // namespace ppapi |
112 } // namespace webkit | 115 } // namespace webkit |
OLD | NEW |