diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 00:27:04 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-14 00:27:04 +0000 |
commit | 00d320a6e403c645dc00d47217028aef5f2792a0 (patch) | |
tree | 4cb1feea9a8c9819c95d1520db3ebd2dff69a3c6 /ppapi/shared_impl | |
parent | 2354c0fa1003d87661d20255211306ae4c9cf622 (diff) | |
download | chromium_src-00d320a6e403c645dc00d47217028aef5f2792a0.zip chromium_src-00d320a6e403c645dc00d47217028aef5f2792a0.tar.gz chromium_src-00d320a6e403c645dc00d47217028aef5f2792a0.tar.bz2 |
Make a global enum to differentiate impl & proxy.
Use this in resource constructors and remove all the old weird structs that we
used to tell which one to call. This removes some extra code we had to deal
with this.
Review URL: http://codereview.chromium.org/9391013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121781 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
25 files changed, 150 insertions, 260 deletions
diff --git a/ppapi/shared_impl/ppb_audio_config_shared.cc b/ppapi/shared_impl/ppb_audio_config_shared.cc index 78df9ad..a866d79 100644 --- a/ppapi/shared_impl/ppb_audio_config_shared.cc +++ b/ppapi/shared_impl/ppb_audio_config_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -6,15 +6,9 @@ namespace ppapi { -PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(PP_Instance instance) - : Resource(instance), - sample_rate_(PP_AUDIOSAMPLERATE_NONE), - sample_frame_count_(0) { -} - -PPB_AudioConfig_Shared::PPB_AudioConfig_Shared( - const HostResource& host_resource) - : Resource(host_resource), +PPB_AudioConfig_Shared::PPB_AudioConfig_Shared(ResourceObjectType type, + PP_Instance instance) + : Resource(type, instance), sample_rate_(PP_AUDIOSAMPLERATE_NONE), sample_frame_count_(0) { } @@ -22,25 +16,13 @@ PPB_AudioConfig_Shared::PPB_AudioConfig_Shared( PPB_AudioConfig_Shared::~PPB_AudioConfig_Shared() { } -// static -PP_Resource PPB_AudioConfig_Shared::CreateAsImpl( +PP_Resource PPB_AudioConfig_Shared::Create( + ResourceObjectType type, PP_Instance instance, PP_AudioSampleRate sample_rate, uint32_t sample_frame_count) { scoped_refptr<PPB_AudioConfig_Shared> object( - new PPB_AudioConfig_Shared(instance)); - if (!object->Init(sample_rate, sample_frame_count)) - return 0; - return object->GetReference(); -} - -// static -PP_Resource PPB_AudioConfig_Shared::CreateAsProxy( - PP_Instance instance, - PP_AudioSampleRate sample_rate, - uint32_t sample_frame_count) { - scoped_refptr<PPB_AudioConfig_Shared> object(new PPB_AudioConfig_Shared( - HostResource::MakeInstanceOnly(instance))); + new PPB_AudioConfig_Shared(type, instance)); if (!object->Init(sample_rate, sample_frame_count)) return 0; return object->GetReference(); diff --git a/ppapi/shared_impl/ppb_audio_config_shared.h b/ppapi/shared_impl/ppb_audio_config_shared.h index 65e3b2b..410a32a8b 100644 --- a/ppapi/shared_impl/ppb_audio_config_shared.h +++ b/ppapi/shared_impl/ppb_audio_config_shared.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -18,12 +18,10 @@ class PPAPI_SHARED_EXPORT PPB_AudioConfig_Shared public: virtual ~PPB_AudioConfig_Shared(); - static PP_Resource CreateAsImpl(PP_Instance instance, - PP_AudioSampleRate sample_rate, - uint32_t sample_frame_count); - static PP_Resource CreateAsProxy(PP_Instance instance, - PP_AudioSampleRate sample_rate, - uint32_t sample_frame_count); + static PP_Resource Create(ResourceObjectType type, + PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count); // Resource overrides. virtual thunk::PPB_AudioConfig_API* AsPPB_AudioConfig_API() OVERRIDE; @@ -34,10 +32,8 @@ class PPAPI_SHARED_EXPORT PPB_AudioConfig_Shared private: // You must call Init before using this object. - // Construct as implementation. - explicit PPB_AudioConfig_Shared(PP_Instance instance); - // Construct as proxy. - explicit PPB_AudioConfig_Shared(const HostResource& host_resource); + explicit PPB_AudioConfig_Shared(ResourceObjectType type, + PP_Instance instance); // Returns false if the arguments are invalid, the object should not be // used in this case. diff --git a/ppapi/shared_impl/ppb_device_ref_shared.cc b/ppapi/shared_impl/ppb_device_ref_shared.cc index edd01f2..43f758f 100644 --- a/ppapi/shared_impl/ppb_device_ref_shared.cc +++ b/ppapi/shared_impl/ppb_device_ref_shared.cc @@ -15,17 +15,10 @@ DeviceRefData::DeviceRefData() : type(PP_DEVICETYPE_DEV_INVALID) { } -PPB_DeviceRef_Shared::PPB_DeviceRef_Shared(const InitAsImpl&, +PPB_DeviceRef_Shared::PPB_DeviceRef_Shared(ResourceObjectType type, PP_Instance instance, const DeviceRefData& data) - : Resource(instance), - data_(data) { -} - -PPB_DeviceRef_Shared::PPB_DeviceRef_Shared(const InitAsProxy&, - PP_Instance instance, - const DeviceRefData& data) - : Resource(HostResource::MakeInstanceOnly(instance)), + : Resource(type, instance), data_(data) { } diff --git a/ppapi/shared_impl/ppb_device_ref_shared.h b/ppapi/shared_impl/ppb_device_ref_shared.h index bbdda72..908cace 100644 --- a/ppapi/shared_impl/ppb_device_ref_shared.h +++ b/ppapi/shared_impl/ppb_device_ref_shared.h @@ -29,15 +29,7 @@ class PPAPI_SHARED_EXPORT PPB_DeviceRef_Shared : public Resource, public thunk::PPB_DeviceRef_API { public: - struct InitAsImpl {}; - struct InitAsProxy {}; - - // The dummy arguments control which version of Resource's constructor is - // called for this base class. - PPB_DeviceRef_Shared(const InitAsImpl&, - PP_Instance instance, - const DeviceRefData& data); - PPB_DeviceRef_Shared(const InitAsProxy&, + PPB_DeviceRef_Shared(ResourceObjectType type, PP_Instance instance, const DeviceRefData& data); diff --git a/ppapi/shared_impl/ppb_file_io_shared.cc b/ppapi/shared_impl/ppb_file_io_shared.cc index 7eeab92..63945b5 100644 --- a/ppapi/shared_impl/ppb_file_io_shared.cc +++ b/ppapi/shared_impl/ppb_file_io_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -36,14 +36,14 @@ PPB_FileIO_Shared::CallbackEntry::~CallbackEntry() { } PPB_FileIO_Shared::PPB_FileIO_Shared(PP_Instance instance) - : Resource(instance), + : Resource(OBJECT_IS_IMPL, instance), file_system_type_(PP_FILESYSTEMTYPE_INVALID), file_open_(false), pending_op_(OPERATION_NONE) { } PPB_FileIO_Shared::PPB_FileIO_Shared(const HostResource& host_resource) - : Resource(host_resource), + : Resource(OBJECT_IS_PROXY, host_resource), file_system_type_(PP_FILESYSTEMTYPE_INVALID), file_open_(false), pending_op_(OPERATION_NONE) { diff --git a/ppapi/shared_impl/ppb_file_ref_shared.cc b/ppapi/shared_impl/ppb_file_ref_shared.cc index 64268b3..b273364 100644 --- a/ppapi/shared_impl/ppb_file_ref_shared.cc +++ b/ppapi/shared_impl/ppb_file_ref_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -9,23 +9,16 @@ namespace ppapi { -PPB_FileRef_Shared::PPB_FileRef_Shared(const InitAsImpl&, +PPB_FileRef_Shared::PPB_FileRef_Shared(ResourceObjectType type, const PPB_FileRef_CreateInfo& info) - : Resource(info.resource.instance()), - create_info_(info) { - // Should not have been passed a host resource for the trusted constructor. - DCHECK(info.resource.is_null()); - - // Resource's constructor assigned a PP_Resource, so we can fill out our - // host resource now. - create_info_.resource = host_resource(); - DCHECK(!create_info_.resource.is_null()); -} - -PPB_FileRef_Shared::PPB_FileRef_Shared(const InitAsProxy&, - const PPB_FileRef_CreateInfo& info) - : Resource(info.resource), + : Resource(type, info.resource), create_info_(info) { + if (type == OBJECT_IS_IMPL) { + // Resource's constructor assigned a PP_Resource, so we can fill out our + // host resource now. + create_info_.resource = host_resource(); + DCHECK(!create_info_.resource.is_null()); + } } PPB_FileRef_Shared::~PPB_FileRef_Shared() { diff --git a/ppapi/shared_impl/ppb_file_ref_shared.h b/ppapi/shared_impl/ppb_file_ref_shared.h index 3d0a9f8..5decd7f 100644 --- a/ppapi/shared_impl/ppb_file_ref_shared.h +++ b/ppapi/shared_impl/ppb_file_ref_shared.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -33,11 +33,8 @@ class PPAPI_SHARED_EXPORT PPB_FileRef_Shared : public Resource, public thunk::PPB_FileRef_API { public: - struct InitAsImpl {}; - struct InitAsProxy {}; - - PPB_FileRef_Shared(const InitAsImpl&, const PPB_FileRef_CreateInfo& info); - PPB_FileRef_Shared(const InitAsProxy&, const PPB_FileRef_CreateInfo& info); + PPB_FileRef_Shared(ResourceObjectType type, + const PPB_FileRef_CreateInfo& info); virtual ~PPB_FileRef_Shared(); // Resource overrides. diff --git a/ppapi/shared_impl/ppb_graphics_3d_shared.cc b/ppapi/shared_impl/ppb_graphics_3d_shared.cc index e21b77e..13184eb 100644 --- a/ppapi/shared_impl/ppb_graphics_3d_shared.cc +++ b/ppapi/shared_impl/ppb_graphics_3d_shared.cc @@ -13,11 +13,11 @@ namespace ppapi { PPB_Graphics3D_Shared::PPB_Graphics3D_Shared(PP_Instance instance) - : Resource(instance) { + : Resource(OBJECT_IS_IMPL, instance) { } PPB_Graphics3D_Shared::PPB_Graphics3D_Shared(const HostResource& host_resource) - : Resource(host_resource) { + : Resource(OBJECT_IS_PROXY, host_resource) { } PPB_Graphics3D_Shared::~PPB_Graphics3D_Shared() { diff --git a/ppapi/shared_impl/ppb_input_event_shared.cc b/ppapi/shared_impl/ppb_input_event_shared.cc index 2cffa0f..4f1a4d0 100644 --- a/ppapi/shared_impl/ppb_input_event_shared.cc +++ b/ppapi/shared_impl/ppb_input_event_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -32,17 +32,10 @@ InputEventData::InputEventData() InputEventData::~InputEventData() { } -PPB_InputEvent_Shared::PPB_InputEvent_Shared(const InitAsImpl&, +PPB_InputEvent_Shared::PPB_InputEvent_Shared(ResourceObjectType type, PP_Instance instance, const InputEventData& data) - : Resource(instance), - data_(data) { -} - -PPB_InputEvent_Shared::PPB_InputEvent_Shared(const InitAsProxy&, - PP_Instance instance, - const InputEventData& data) - : Resource(HostResource::MakeInstanceOnly(instance)), + : Resource(type, instance), data_(data) { } diff --git a/ppapi/shared_impl/ppb_input_event_shared.h b/ppapi/shared_impl/ppb_input_event_shared.h index 1a29750..c9ab572 100644 --- a/ppapi/shared_impl/ppb_input_event_shared.h +++ b/ppapi/shared_impl/ppb_input_event_shared.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -55,15 +55,7 @@ class PPAPI_SHARED_EXPORT PPB_InputEvent_Shared : public Resource, public thunk::PPB_InputEvent_API { public: - struct InitAsImpl {}; - struct InitAsProxy {}; - - // The dummy arguments control which version of Resource's constructor is - // called for this base class. - PPB_InputEvent_Shared(const InitAsImpl&, - PP_Instance instance, - const InputEventData& data); - PPB_InputEvent_Shared(const InitAsProxy&, + PPB_InputEvent_Shared(ResourceObjectType type, PP_Instance instance, const InputEventData& data); diff --git a/ppapi/shared_impl/ppb_resource_array_shared.cc b/ppapi/shared_impl/ppb_resource_array_shared.cc index 9949fd5..f7353f1 100644 --- a/ppapi/shared_impl/ppb_resource_array_shared.cc +++ b/ppapi/shared_impl/ppb_resource_array_shared.cc @@ -12,20 +12,20 @@ using ppapi::thunk::PPB_ResourceArray_API; namespace ppapi { -PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsImpl&, +PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(ResourceObjectType type, PP_Instance instance, const PP_Resource elements[], uint32_t size) - : Resource(instance) { - Initialize(elements, size); -} + : Resource(type, instance) { + DCHECK(resources_.empty()); -PPB_ResourceArray_Shared::PPB_ResourceArray_Shared(const InitAsProxy&, - PP_Instance instance, - const PP_Resource elements[], - uint32_t size) - : Resource(HostResource::MakeInstanceOnly(instance)) { - Initialize(elements, size); + resources_.reserve(size); + for (uint32_t index = 0; index < size; ++index) { + PP_Resource element = elements[index]; + if (element) + PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(element); + resources_.push_back(element); + } } PPB_ResourceArray_Shared::~PPB_ResourceArray_Shared() { @@ -48,17 +48,4 @@ PP_Resource PPB_ResourceArray_Shared::GetAt(uint32_t index) { return index < resources_.size() ? resources_[index] : 0; } -void PPB_ResourceArray_Shared::Initialize(const PP_Resource elements[], - uint32_t size) { - DCHECK(resources_.empty()); - - resources_.reserve(size); - for (uint32_t index = 0; index < size; ++index) { - PP_Resource element = elements[index]; - if (element) - PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(element); - resources_.push_back(element); - } -} - } // namespace ppapi diff --git a/ppapi/shared_impl/ppb_resource_array_shared.h b/ppapi/shared_impl/ppb_resource_array_shared.h index 55342e0..e3d6750 100644 --- a/ppapi/shared_impl/ppb_resource_array_shared.h +++ b/ppapi/shared_impl/ppb_resource_array_shared.h @@ -18,20 +18,10 @@ class PPAPI_SHARED_EXPORT PPB_ResourceArray_Shared : public Resource, public thunk::PPB_ResourceArray_API { public: - struct InitAsImpl {}; - struct InitAsProxy {}; - - // The dummy arguments control which version of Resource's constructor is - // called for this base class. - PPB_ResourceArray_Shared(const InitAsImpl&, - PP_Instance instance, - const PP_Resource elements[], - uint32_t size); - PPB_ResourceArray_Shared(const InitAsProxy&, + PPB_ResourceArray_Shared(ResourceObjectType type, PP_Instance instance, const PP_Resource elements[], uint32_t size); - virtual ~PPB_ResourceArray_Shared(); // Resource overrides. @@ -42,8 +32,6 @@ class PPAPI_SHARED_EXPORT PPB_ResourceArray_Shared virtual PP_Resource GetAt(uint32_t index) OVERRIDE; private: - void Initialize(const PP_Resource elements[], uint32_t size); - std::vector<PP_Resource> resources_; DISALLOW_IMPLICIT_CONSTRUCTORS(PPB_ResourceArray_Shared); diff --git a/ppapi/shared_impl/ppb_url_request_info_shared.cc b/ppapi/shared_impl/ppb_url_request_info_shared.cc index f582eac..d7a3ea2 100644 --- a/ppapi/shared_impl/ppb_url_request_info_shared.cc +++ b/ppapi/shared_impl/ppb_url_request_info_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -71,16 +71,10 @@ PPB_URLRequestInfo_Data::~PPB_URLRequestInfo_Data() { } PPB_URLRequestInfo_Shared::PPB_URLRequestInfo_Shared( + ResourceObjectType type, PP_Instance instance, const PPB_URLRequestInfo_Data& data) - : Resource(instance), - data_(data) { -} - -PPB_URLRequestInfo_Shared::PPB_URLRequestInfo_Shared( - const HostResource& host_resource, - const PPB_URLRequestInfo_Data& data) - : Resource(host_resource), + : Resource(type, instance), data_(data) { } diff --git a/ppapi/shared_impl/ppb_url_request_info_shared.h b/ppapi/shared_impl/ppb_url_request_info_shared.h index c07b9c9..7876d23 100644 --- a/ppapi/shared_impl/ppb_url_request_info_shared.h +++ b/ppapi/shared_impl/ppb_url_request_info_shared.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -90,11 +90,9 @@ class PPAPI_SHARED_EXPORT PPB_URLRequestInfo_Shared : public ::ppapi::Resource, public ::ppapi::thunk::PPB_URLRequestInfo_API { public: - // This constructor initializes the object as a proxy object with the given - // host resource. - PPB_URLRequestInfo_Shared(const HostResource& host_resource, - const PPB_URLRequestInfo_Data& data); - + PPB_URLRequestInfo_Shared(ResourceObjectType type, + PP_Instance instance, + const PPB_URLRequestInfo_Data& data); ~PPB_URLRequestInfo_Shared(); // Resource overrides. diff --git a/ppapi/shared_impl/ppb_video_decoder_shared.cc b/ppapi/shared_impl/ppb_video_decoder_shared.cc index 39a4088..b61567b 100644 --- a/ppapi/shared_impl/ppb_video_decoder_shared.cc +++ b/ppapi/shared_impl/ppb_video_decoder_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -13,14 +13,14 @@ namespace ppapi { PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared(PP_Instance instance) - : Resource(instance), + : Resource(OBJECT_IS_IMPL, instance), graphics_context_(0), gles2_impl_(NULL) { } PPB_VideoDecoder_Shared::PPB_VideoDecoder_Shared( const HostResource& host_resource) - : Resource(host_resource), + : Resource(OBJECT_IS_PROXY, host_resource), graphics_context_(0), gles2_impl_(NULL) { } diff --git a/ppapi/shared_impl/ppb_view_shared.cc b/ppapi/shared_impl/ppb_view_shared.cc index 8b2f339..1e024a6 100644 --- a/ppapi/shared_impl/ppb_view_shared.cc +++ b/ppapi/shared_impl/ppb_view_shared.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -27,17 +27,10 @@ bool ViewData::Equals(const ViewData& other) const { clip_rect.size.height == other.clip_rect.size.height; } -PPB_View_Shared::PPB_View_Shared(const InitAsImpl&, +PPB_View_Shared::PPB_View_Shared(ResourceObjectType type, PP_Instance instance, const ViewData& data) - : Resource(instance), - data_(data) { -} - -PPB_View_Shared::PPB_View_Shared(const InitAsProxy&, - PP_Instance instance, - const ViewData& data) - : Resource(HostResource::MakeInstanceOnly(instance)), + : Resource(type, instance), data_(data) { } diff --git a/ppapi/shared_impl/ppb_view_shared.h b/ppapi/shared_impl/ppb_view_shared.h index ecfb1a0..59b8e72 100644 --- a/ppapi/shared_impl/ppb_view_shared.h +++ b/ppapi/shared_impl/ppb_view_shared.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -31,15 +31,7 @@ class PPAPI_SHARED_EXPORT PPB_View_Shared : public Resource, public thunk::PPB_View_API { public: - struct InitAsImpl {}; - struct InitAsProxy {}; - - // The dummy arguments control which version of Resource's constructor is - // called for this base class. - PPB_View_Shared(const InitAsImpl&, - PP_Instance instance, - const ViewData& data); - PPB_View_Shared(const InitAsProxy&, + PPB_View_Shared(ResourceObjectType type, PP_Instance instance, const ViewData& data); virtual ~PPB_View_Shared(); diff --git a/ppapi/shared_impl/private/ppb_font_shared.cc b/ppapi/shared_impl/private/ppb_font_shared.cc index 3b4f04b..3918088 100644 --- a/ppapi/shared_impl/private/ppb_font_shared.cc +++ b/ppapi/shared_impl/private/ppb_font_shared.cc @@ -302,41 +302,24 @@ bool PPB_Font_Shared::IsPPFontDescriptionValid( } // static -PP_Resource PPB_Font_Shared::CreateAsImpl( - PP_Instance instance, - const PP_FontDescription_Dev& description, - const ::ppapi::Preferences& prefs) { +PP_Resource PPB_Font_Shared::Create(ResourceObjectType type, + PP_Instance instance, + const PP_FontDescription_Dev& description, + const ::ppapi::Preferences& prefs) { if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description)) return 0; - return (new PPB_Font_Shared(InitAsImpl(), instance, description, + return (new PPB_Font_Shared(type, instance, description, prefs))->GetReference(); } -// static -PP_Resource PPB_Font_Shared::CreateAsProxy( - PP_Instance instance, - const PP_FontDescription_Dev& description, - const ::ppapi::Preferences& prefs) { - if (!::ppapi::PPB_Font_Shared::IsPPFontDescriptionValid(description)) - return 0; - return (new PPB_Font_Shared(InitAsProxy(), instance, description, - prefs))->GetReference(); -} - -PPB_Font_Shared::PPB_Font_Shared(const InitAsImpl&, - PP_Instance pp_instance, - const PP_FontDescription_Dev& desc, - const ::ppapi::Preferences& prefs) - : Resource(pp_instance) { - Initialize(desc, prefs); -} - -PPB_Font_Shared::PPB_Font_Shared(const InitAsProxy&, - PP_Instance pp_instance, +PPB_Font_Shared::PPB_Font_Shared(ResourceObjectType type, + PP_Instance instance, const PP_FontDescription_Dev& desc, const ::ppapi::Preferences& prefs) - : Resource(HostResource::MakeInstanceOnly(pp_instance)) { - Initialize(desc, prefs); + : Resource(type, instance) { + StringVar* face_name = StringVar::FromPPVar(desc.face); + font_impl_.reset(new FontImpl( + desc, face_name ? face_name->value() : std::string(), prefs)); } PPB_Font_Shared::~PPB_Font_Shared() { @@ -425,13 +408,5 @@ int32_t PPB_Font_Shared::PixelOffsetForCharacter(const PP_TextRun_Dev* text, return result; } -void PPB_Font_Shared::Initialize(const PP_FontDescription_Dev& desc, - const ::ppapi::Preferences& prefs) { - StringVar* face_name = StringVar::FromPPVar(desc.face); - - font_impl_.reset(new FontImpl( - desc, face_name ? face_name->value() : std::string(), prefs)); -} - } // namespace ppapi diff --git a/ppapi/shared_impl/private/ppb_font_shared.h b/ppapi/shared_impl/private/ppb_font_shared.h index ec34215..8e5bebb 100644 --- a/ppapi/shared_impl/private/ppb_font_shared.h +++ b/ppapi/shared_impl/private/ppb_font_shared.h @@ -33,12 +33,10 @@ class PPAPI_SHARED_EXPORT PPB_Font_Shared virtual ~PPB_Font_Shared(); - static PP_Resource CreateAsImpl(PP_Instance instance, - const PP_FontDescription_Dev& description, - const ::ppapi::Preferences& prefs); - static PP_Resource CreateAsProxy(PP_Instance instance, - const PP_FontDescription_Dev& description, - const ::ppapi::Preferences& prefs); + static PP_Resource Create(ResourceObjectType type, + PP_Instance instance, + const PP_FontDescription_Dev& description, + const ::ppapi::Preferences& prefs); // Resource. virtual ::ppapi::thunk::PPB_Font_API* AsPPB_Font_API() OVERRIDE; @@ -59,23 +57,11 @@ class PPAPI_SHARED_EXPORT PPB_Font_Shared uint32_t char_offset) OVERRIDE; private: - struct InitAsImpl {}; - struct InitAsProxy {}; - - // The dummy arguments control which version of Resource's constructor is - // called for this base class. - PPB_Font_Shared(const InitAsImpl&, - PP_Instance instance, - const PP_FontDescription_Dev& desc, - const ::ppapi::Preferences& prefs); - PPB_Font_Shared(const InitAsProxy&, + PPB_Font_Shared(ResourceObjectType type, PP_Instance instance, const PP_FontDescription_Dev& desc, const ::ppapi::Preferences& prefs); - void Initialize(const PP_FontDescription_Dev& desc, - const ::ppapi::Preferences& prefs); - scoped_ptr< ::ppapi::WebKitForwarding::Font> font_impl_; DISALLOW_COPY_AND_ASSIGN(PPB_Font_Shared); diff --git a/ppapi/shared_impl/private/tcp_socket_private_impl.cc b/ppapi/shared_impl/private/tcp_socket_private_impl.cc index a268801..de99e20 100644 --- a/ppapi/shared_impl/private/tcp_socket_private_impl.cc +++ b/ppapi/shared_impl/private/tcp_socket_private_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -22,13 +22,13 @@ const int32_t TCPSocketPrivateImpl::kMaxWriteSize = 1024 * 1024; TCPSocketPrivateImpl::TCPSocketPrivateImpl(PP_Instance instance, uint32 socket_id) - : Resource(instance) { + : Resource(OBJECT_IS_IMPL, instance) { Init(socket_id); } TCPSocketPrivateImpl::TCPSocketPrivateImpl(const HostResource& resource, uint32 socket_id) - : Resource(resource) { + : Resource(OBJECT_IS_PROXY, resource) { Init(socket_id); } diff --git a/ppapi/shared_impl/private/udp_socket_private_impl.cc b/ppapi/shared_impl/private/udp_socket_private_impl.cc index 23f125d..d596b02 100644 --- a/ppapi/shared_impl/private/udp_socket_private_impl.cc +++ b/ppapi/shared_impl/private/udp_socket_private_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -22,13 +22,13 @@ const int32_t UDPSocketPrivateImpl::kMaxWriteSize = 1024 * 1024; UDPSocketPrivateImpl::UDPSocketPrivateImpl(const HostResource& resource, uint32 socket_id) - : Resource(resource) { + : Resource(OBJECT_IS_PROXY, resource) { Init(socket_id); } UDPSocketPrivateImpl::UDPSocketPrivateImpl(PP_Instance instance, uint32 socket_id) - : Resource(instance) { + : Resource(OBJECT_IS_IMPL, instance) { Init(socket_id); } diff --git a/ppapi/shared_impl/resource.cc b/ppapi/shared_impl/resource.cc index 35add15..b8dd315 100644 --- a/ppapi/shared_impl/resource.cc +++ b/ppapi/shared_impl/resource.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,23 +10,34 @@ namespace ppapi { -Resource::Resource(PP_Instance instance) { +Resource::Resource(ResourceObjectType type, PP_Instance instance) + : host_resource_(HostResource::MakeInstanceOnly(instance)) { // The instance should always be valid (nonzero). DCHECK(instance); - // For the in-process case, the host resource and resource are the same. - // - // AddResource needs our instance() getter to work, and that goes through - // the host resource, so we need to fill that first even though we don't - // have a resource ID yet, then fill the resource in later. - host_resource_ = HostResource::MakeInstanceOnly(instance); pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); - host_resource_.SetHostResource(instance, pp_resource_); + if (type == OBJECT_IS_IMPL) { + // For the in-process case, the host resource and resource are the same. + // + // Note that we need to have set the instance above (in the initializer + // list) since AddResource needs our instance() getter to work, and that + // goes through the host resource. When we get the "real" resource ID, + // we re-set the host_resource. + host_resource_.SetHostResource(instance, pp_resource_); + } } -Resource::Resource(const HostResource& host_resource) +Resource::Resource(ResourceObjectType type, const HostResource& host_resource) : host_resource_(host_resource) { pp_resource_ = PpapiGlobals::Get()->GetResourceTracker()->AddResource(this); + if (type == OBJECT_IS_IMPL) { + // When using this constructor for the implementation, the resource ID + // should not have been passed in. + DCHECK(host_resource_.host_resource() == 0); + + // See previous constructor. + host_resource_.SetHostResource(host_resource.instance(), pp_resource_); + } } Resource::~Resource() { diff --git a/ppapi/shared_impl/resource.h b/ppapi/shared_impl/resource.h index 4b26d28..b0876a2 100644 --- a/ppapi/shared_impl/resource.h +++ b/ppapi/shared_impl/resource.h @@ -69,17 +69,44 @@ FOR_ALL_PPAPI_RESOURCE_APIS(DECLARE_RESOURCE_CLASS) #undef DECLARE_RESOURCE_CLASS } // namespace thunk +// Resources have slightly different registration behaviors when the're an +// in-process ("impl") resource in the host (renderer) process, or when they're +// a proxied resource in the plugin process. This enum differentiates those +// cases. +enum ResourceObjectType { + OBJECT_IS_IMPL, + OBJECT_IS_PROXY +}; + class PPAPI_SHARED_EXPORT Resource : public base::RefCounted<Resource> { public: - // For constructing non-proxied objects. This just takes the associated - // instance, and generates a new resource ID. The host resource will be the - // same as the newly-generated resource ID. - explicit Resource(PP_Instance instance); - - // For constructing proxied objects. This takes the resource generated in - // the host side, stores it, and allocates a "local" resource ID for use in - // the current process. - explicit Resource(const HostResource& host_resource); + // Constructor for impl and non-proxied, instance-only objects. + // + // For constructing "impl" (non-proxied) objects, this just takes the + // associated instance, and generates a new resource ID. The host resource + // will be the same as the newly-generated resource ID. For all objects in + // the renderer (host) process, you'll use this constructor and call it with + // OBJECT_IS_IMPL. + // + // For proxied objects, this will create an "instance-only" object which + // lives only in the plugin and doesn't have a corresponding object in the + // host. If you have a host resource ID, use the constructor below which + // takes that HostResource value. + explicit Resource(ResourceObjectType type, PP_Instance instance); + + // For constructing given a host resource. + // + // For OBJECT_IS_PROXY objects, this takes the resource generated in the host + // side, stores it, and allocates a "local" resource ID for use in the + // current process. + // + // For OBJECT_IS_IMPL, the host resource ID must be 0, since there should be + // no host resource generated (impl objects should generate their own). The + // reason for supporting this constructor at all for the IMPL case is that + // some shared objects use a host resource for both modes to keep things the + // same. + explicit Resource(ResourceObjectType type, + const HostResource& host_resource); virtual ~Resource(); diff --git a/ppapi/shared_impl/resource_tracker_unittest.cc b/ppapi/shared_impl/resource_tracker_unittest.cc index a77dc78..26d02c3 100644 --- a/ppapi/shared_impl/resource_tracker_unittest.cc +++ b/ppapi/shared_impl/resource_tracker_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -19,7 +19,7 @@ int instance_was_deleted_count = 0; class MyMockResource : public Resource { public: - MyMockResource(PP_Instance instance) : Resource(instance) { + MyMockResource(PP_Instance instance) : Resource(OBJECT_IS_IMPL, instance) { mock_resource_alive_count++; } virtual ~MyMockResource() { diff --git a/ppapi/shared_impl/tracked_callback_unittest.cc b/ppapi/shared_impl/tracked_callback_unittest.cc index 62da396..ca4d3b1 100644 --- a/ppapi/shared_impl/tracked_callback_unittest.cc +++ b/ppapi/shared_impl/tracked_callback_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -80,7 +80,7 @@ class CallbackShutdownTest : public TrackedCallbackTest { // Tests that callbacks are properly aborted on module shutdown. TEST_F(CallbackShutdownTest, AbortOnShutdown) { - scoped_refptr<Resource> resource(new Resource(pp_instance())); + scoped_refptr<Resource> resource(new Resource(OBJECT_IS_IMPL, pp_instance())); // Set up case (1) (see above). EXPECT_EQ(0U, info_did_run().run_count); @@ -133,7 +133,8 @@ class CallbackResourceTest : public TrackedCallbackTest { class CallbackMockResource : public Resource { public: - CallbackMockResource(PP_Instance instance) : Resource(instance) {} + CallbackMockResource(PP_Instance instance) + : Resource(OBJECT_IS_IMPL, instance) {} ~CallbackMockResource() {} PP_Resource SetupForTest() { |