Skip to content

Commit

Permalink
Convert more interfaces to the new thunk system. This goes up to and …
Browse files Browse the repository at this point in the history
…including

the ones starting with "F".

Since this adds a lot more interfaces, I added the macro stuff we used for the
old system to generate the various template specializations. This involded a
lot of renaming since the As* needs to match the name (I was previously leaving
off the "PPB_" part). I did other misc cleanup to the infrastructure.
Review URL: http://codereview.chromium.org/7082036

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87415 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Jun 1, 2011
1 parent d0922ea commit 1598e4a
Show file tree
Hide file tree
Showing 86 changed files with 1,857 additions and 1,211 deletions.
17 changes: 17 additions & 0 deletions ppapi/ppapi_shared.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
'shared_impl/crypto_impl.h',
'shared_impl/font_impl.cc',
'shared_impl/font_impl.h',
'shared_impl/function_group_base.cc',
'shared_impl/function_group_base.h',
'shared_impl/image_data_impl.cc',
'shared_impl/image_data_impl.h',
'shared_impl/ppapi_preferences.cc',
'shared_impl/ppapi_preferences.h',
'shared_impl/resource_object_base.cc',
'shared_impl/resource_object_base.h',
'shared_impl/tracker_base.cc',
'shared_impl/tracker_base.h',
'shared_impl/url_util_impl.cc',
Expand All @@ -59,6 +63,19 @@
'thunk/ppb_char_set_thunk.cc',
'thunk/ppb_cursor_control_api.h',
'thunk/ppb_cursor_control_thunk.cc',
'thunk/ppb_directory_reader_api.h',
'thunk/ppb_directory_reader_thunk.cc',
'thunk/ppb_file_chooser_api.h',
'thunk/ppb_file_chooser_thunk.cc',
'thunk/ppb_file_io_api.h',
'thunk/ppb_file_io_thunk.cc',
'thunk/ppb_file_io_trusted_thunk.cc',
'thunk/ppb_file_ref_api.h',
'thunk/ppb_file_ref_thunk.cc',
'thunk/ppb_file_system_api.h',
'thunk/ppb_file_system_thunk.cc',
'thunk/ppb_find_api.h',
'thunk/ppb_find_thunk.cc',
'thunk/ppb_font_api.h',
'thunk/ppb_font_thunk.cc',
'thunk/ppb_graphics_2d_api.h',
Expand Down
58 changes: 58 additions & 0 deletions ppapi/proxy/enter_proxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PPAPI_PROXY_ENTER_PROXY_H_
#define PPAPI_PROXY_ENTER_PROXY_H_

#include "base/logging.h"
#include "ppapi/proxy/host_dispatcher.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource_tracker.h"
#include "ppapi/thunk/enter.h"

namespace pp {
namespace proxy {

// Wrapper around EnterResourceNoLock that takes a host resource. This is used
// when handling messages in the plugin from the host and we need to convert to
// an object in the plugin side corresponding to that.
//
// This never locks since we assume the host Resource is coming from IPC, and
// never logs errors since we assume the host is doing reasonable things.
template<typename ResourceT>
class EnterPluginFromHostResource
: public ::ppapi::thunk::EnterResourceNoLock<ResourceT> {
public:
EnterPluginFromHostResource(const HostResource& host_resource)
: ::ppapi::thunk::EnterResourceNoLock<ResourceT>(
PluginResourceTracker::GetInstance()->PluginResourceForHostResource(
host_resource),
false) {
// Validate that we're in the plugin rather than the host. Otherwise this
// object will do the wrong thing. In the plugin, the instance should have
// a corresponding plugin dispatcher (assuming the resource is valid).
DCHECK(this->failed() ||
PluginDispatcher::GetForInstance(host_resource.instance()));
}
};

template<typename ResourceT>
class EnterHostFromHostResource
: public ::ppapi::thunk::EnterResourceNoLock<ResourceT> {
public:
EnterHostFromHostResource(const HostResource& host_resource)
: ::ppapi::thunk::EnterResourceNoLock<ResourceT>(
host_resource.host_resource(), false) {
// Validate that we're in the host rather than the plugin. Otherwise this
// object will do the wrong thing. In the host, the instance should have
// a corresponding host disptacher (assuming the resource is valid).
DCHECK(this->failed() ||
HostDispatcher::GetForInstance(host_resource.instance()));
}
};

} // namespace proxy
} // namespace pp

#endif // PPAPI_PROXY_ENTER_PROXY_H_
1 change: 1 addition & 0 deletions ppapi/proxy/interface_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum InterfaceID {
INTERFACE_ID_PPB_FILE_CHOOSER,
INTERFACE_ID_PPB_FILE_REF,
INTERFACE_ID_PPB_FILE_SYSTEM,
INTERFACE_ID_PPB_FIND,
INTERFACE_ID_PPB_FLASH,
INTERFACE_ID_PPB_FLASH_CLIPBOARD,
INTERFACE_ID_PPB_FLASH_FILE_FILEREF,
Expand Down
8 changes: 8 additions & 0 deletions ppapi/proxy/plugin_resource_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ ::ppapi::FunctionGroupBase* PluginResourceTracker::GetFunctionAPI(
return NULL;
}

PP_Instance PluginResourceTracker::GetInstanceForResource(
PP_Resource resource) {
ResourceMap::iterator found = resource_map_.find(resource);
if (found == resource_map_.end())
return 0;
return found->second.resource->instance();
}

void PluginResourceTracker::ReleasePluginResourceRef(
const PP_Resource& resource,
bool notify_browser_on_release) {
Expand Down
6 changes: 4 additions & 2 deletions ppapi/proxy/plugin_resource_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <map>
#include <utility>

#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "ppapi/c/pp_completion_callback.h"
#include "ppapi/c/pp_instance.h"
Expand Down Expand Up @@ -56,10 +57,11 @@ class PluginResourceTracker : public ::ppapi::TrackerBase {

// TrackerBase.
virtual ::ppapi::ResourceObjectBase* GetResourceAPI(
PP_Resource res);
PP_Resource res) OVERRIDE;
virtual ::ppapi::FunctionGroupBase* GetFunctionAPI(
PP_Instance inst,
pp::proxy::InterfaceID id);
pp::proxy::InterfaceID id) OVERRIDE;
virtual PP_Instance GetInstanceForResource(PP_Resource resource) OVERRIDE;

private:
friend struct DefaultSingletonTraits<PluginResourceTracker>;
Expand Down
4 changes: 2 additions & 2 deletions ppapi/proxy/ppb_audio_config_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AudioConfig : public PluginResource,
virtual ~AudioConfig();

// ResourceObjectBase overrides.
virtual ::ppapi::thunk::PPB_AudioConfig_API* AsAudioConfig_API() OVERRIDE;
virtual ::ppapi::thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE;

private:
DISALLOW_COPY_AND_ASSIGN(AudioConfig);
Expand All @@ -36,7 +36,7 @@ AudioConfig::AudioConfig(const HostResource& resource)
AudioConfig::~AudioConfig() {
}

::ppapi::thunk::PPB_AudioConfig_API* AudioConfig::AsAudioConfig_API() {
::ppapi::thunk::PPB_AudioConfig_API* AudioConfig::AsPPB_AudioConfig_API() {
return this;
}

Expand Down
21 changes: 10 additions & 11 deletions ppapi/proxy/ppb_audio_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "ppapi/c/ppb_audio_config.h"
#include "ppapi/c/ppb_var.h"
#include "ppapi/c/trusted/ppb_audio_trusted.h"
#include "ppapi/proxy/enter_proxy.h"
#include "ppapi/proxy/interface_id.h"
#include "ppapi/proxy/plugin_dispatcher.h"
#include "ppapi/proxy/plugin_resource.h"
Expand All @@ -21,6 +22,8 @@
#include "ppapi/thunk/resource_creation_api.h"
#include "ppapi/thunk/thunk.h"

using ::ppapi::thunk::PPB_Audio_API;

namespace pp {
namespace proxy {

Expand All @@ -33,7 +36,7 @@ class Audio : public PluginResource, public ppapi::AudioImpl {
virtual ~Audio();

// ResourceObjectBase overrides.
virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API();
virtual PPB_Audio_API* AsPPB_Audio_API();

// PPB_Audio_API implementation.
virtual PP_Resource GetCurrentConfig() OVERRIDE;
Expand Down Expand Up @@ -62,7 +65,7 @@ Audio::~Audio() {
PluginResourceTracker::GetInstance()->ReleaseResource(config_);
}

::ppapi::thunk::PPB_Audio_API* Audio::AsAudio_API() {
PPB_Audio_API* Audio::AsPPB_Audio_API() {
return this;
}

Expand Down Expand Up @@ -232,23 +235,19 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated(
IPC::PlatformFileForTransit socket_handle,
base::SharedMemoryHandle handle,
uint32_t length) {
PP_Resource plugin_resource =
PluginResourceTracker::GetInstance()->PluginResourceForHostResource(
audio_id);
ppapi::thunk::EnterResource<ppapi::thunk::PPB_Audio_API> enter(
plugin_resource, false);
EnterPluginFromHostResource<PPB_Audio_API> enter(audio_id);
if (enter.failed() || result_code != PP_OK) {
// The caller may still have given us these handles in the failure case.
// The easiest way to clean these up is to just put them in the objects
// and then close them. This failure case is not performance critical.
base::SyncSocket temp_socket(
IPC::PlatformFileForTransitToPlatformFile(socket_handle));
base::SharedMemory temp_mem(handle, false);
return;
} else {
static_cast<Audio*>(enter.object())->SetStreamInfo(
handle, length,
IPC::PlatformFileForTransitToPlatformFile(socket_handle));
}
Audio* audio = static_cast<Audio*>(enter.object());
audio->SetStreamInfo(
handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle));
}

void PPB_Audio_Proxy::AudioChannelConnected(
Expand Down
4 changes: 2 additions & 2 deletions ppapi/proxy/ppb_broker_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Broker : public ppapi::thunk::PPB_Broker_API,
virtual ~Broker();

// ResourceObjectBase overries.
virtual ppapi::thunk::PPB_Broker_API* AsBroker_API() OVERRIDE;
virtual ppapi::thunk::PPB_Broker_API* AsPPB_Broker_API() OVERRIDE;

// PPB_Broker_API implementation.
virtual int32_t Connect(PP_CompletionCallback connect_callback) OVERRIDE;
Expand Down Expand Up @@ -95,7 +95,7 @@ Broker::~Broker() {
socket_handle_ = base::kInvalidPlatformFileValue;
}

ppapi::thunk::PPB_Broker_API* Broker::AsBroker_API() {
ppapi::thunk::PPB_Broker_API* Broker::AsPPB_Broker_API() {
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions ppapi/proxy/ppb_buffer_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Buffer : public ppapi::thunk::PPB_Buffer_API,
virtual Buffer* AsBuffer() OVERRIDE;

// ResourceObjectBase overries.
virtual ppapi::thunk::PPB_Buffer_API* AsBuffer_API() OVERRIDE;
virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE;

// PPB_Buffer_API implementation.
virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE;
Expand Down Expand Up @@ -75,7 +75,7 @@ Buffer* Buffer::AsBuffer() {
return this;
}

ppapi::thunk::PPB_Buffer_API* Buffer::AsBuffer_API() {
ppapi::thunk::PPB_Buffer_API* Buffer::AsPPB_Buffer_API() {
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion ppapi/proxy/ppb_char_set_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const InterfaceProxy::Info* PPB_CharSet_Proxy::GetInfo() {
}

ppapi::thunk::PPB_CharSet_FunctionAPI*
PPB_CharSet_Proxy::AsCharSet_FunctionAPI() {
PPB_CharSet_Proxy::AsPPB_CharSet_FunctionAPI() {
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion ppapi/proxy/ppb_char_set_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PPB_CharSet_Proxy : public ppapi::FunctionGroupBase,
static const Info* GetInfo();

// FunctionGroupBase overrides.
virtual ppapi::thunk::PPB_CharSet_FunctionAPI* AsCharSet_FunctionAPI()
virtual ppapi::thunk::PPB_CharSet_FunctionAPI* AsPPB_CharSet_FunctionAPI()
OVERRIDE;

// PPB_CharSet_FunctionAPI implementation.
Expand Down
2 changes: 1 addition & 1 deletion ppapi/proxy/ppb_cursor_control_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const InterfaceProxy::Info* PPB_CursorControl_Proxy::GetInfo() {
}

ppapi::thunk::PPB_CursorControl_FunctionAPI*
PPB_CursorControl_Proxy::AsCursorControl_FunctionAPI() {
PPB_CursorControl_Proxy::AsPPB_CursorControl_FunctionAPI() {
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion ppapi/proxy/ppb_cursor_control_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PPB_CursorControl_Proxy
static const Info* GetInfo();

// FunctionGroupBase overrides.
ppapi::thunk::PPB_CursorControl_FunctionAPI* AsCursorControl_FunctionAPI()
ppapi::thunk::PPB_CursorControl_FunctionAPI* AsPPB_CursorControl_FunctionAPI()
OVERRIDE;

// PPB_CursorControl_FunctionAPI implementation.
Expand Down
Loading

0 comments on commit 1598e4a

Please sign in to comment.