diff options
author | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-18 22:42:41 +0000 |
---|---|---|
committer | teravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-18 22:42:41 +0000 |
commit | c6420f0816e2f409ba2f0f161905a6f2a46ed80b (patch) | |
tree | e5ce4cbc98536450e5d049032f034dd5156afbde /ppapi/shared_impl | |
parent | 0e523c610f65d020ceef61c186502394830a120e (diff) | |
download | chromium_src-c6420f0816e2f409ba2f0f161905a6f2a46ed80b.zip chromium_src-c6420f0816e2f409ba2f0f161905a6f2a46ed80b.tar.gz chromium_src-c6420f0816e2f409ba2f0f161905a6f2a46ed80b.tar.bz2 |
Pepper: Move FileRef to the "new" resource proxy.
This change moves the FileRef implementation from the previous one in the "old"
resource model (ppb_file_ref_impl.cc) to the "new" resource model
(pepper_file_ref_host.cc), and from the renderer to the browser.
As many as possible of the supporting changes were split off to other changes
to minimize the size of this change. Unfortunately, a lot of changes for
URLLoader had to be rolled into this change.
The data structures for CreateInfo have changed, and all users of FileRef have
to be moved over, which is what causes this change to be so large.
TBR=dmichael@chromium.org, jschuh@chromium.org, yzshen@chromium.org
BUG=225441
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=216744
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=218305
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=219911
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=221284
Review URL: https://chromiumcodereview.appspot.com/21966004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223963 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl')
-rw-r--r-- | ppapi/shared_impl/file_ref_create_info.cc | 50 | ||||
-rw-r--r-- | ppapi/shared_impl/file_ref_create_info.h | 24 | ||||
-rw-r--r-- | ppapi/shared_impl/ppb_file_ref_shared.cc | 54 | ||||
-rw-r--r-- | ppapi/shared_impl/ppb_file_ref_shared.h | 70 | ||||
-rw-r--r-- | ppapi/shared_impl/url_request_info_data.cc | 6 | ||||
-rw-r--r-- | ppapi/shared_impl/url_request_info_data.h | 23 | ||||
-rw-r--r-- | ppapi/shared_impl/url_response_info_data.h | 6 |
7 files changed, 87 insertions, 146 deletions
diff --git a/ppapi/shared_impl/file_ref_create_info.cc b/ppapi/shared_impl/file_ref_create_info.cc new file mode 100644 index 0000000..2fd3e13 --- /dev/null +++ b/ppapi/shared_impl/file_ref_create_info.cc @@ -0,0 +1,50 @@ +// Copyright 2013 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. + +#include "ppapi/shared_impl/file_ref_create_info.h" + +#include "base/logging.h" +#include "base/strings/utf_string_conversions.h" +#include "ppapi/c/pp_file_info.h" + +namespace ppapi { + +namespace { + +std::string GetNameForExternalFilePath(const base::FilePath& in_path) { + const base::FilePath::StringType& path = in_path.value(); + size_t pos = path.rfind(base::FilePath::kSeparators[0]); + CHECK(pos != base::FilePath::StringType::npos); +#if defined(OS_WIN) + return base::WideToUTF8(path.substr(pos + 1)); +#elif defined(OS_POSIX) + return path.substr(pos + 1); +#else +#error "Unsupported platform." +#endif +} + +} // namespace + +bool FileRefCreateInfo::IsValid() const { + return file_system_type != PP_FILESYSTEMTYPE_INVALID; +} + +FileRefCreateInfo +MakeExternalFileRefCreateInfo(const base::FilePath& external_path, + const std::string& display_name, + int browser_pending_host_resource_id, + int renderer_pending_host_resource_id) { + FileRefCreateInfo info; + info.file_system_type = PP_FILESYSTEMTYPE_EXTERNAL; + if (!display_name.empty()) + info.display_name = display_name; + else + info.display_name = GetNameForExternalFilePath(external_path); + info.browser_pending_host_resource_id = browser_pending_host_resource_id; + info.renderer_pending_host_resource_id = renderer_pending_host_resource_id; + return info; +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/file_ref_create_info.h b/ppapi/shared_impl/file_ref_create_info.h index a3599f7..02fc8cc 100644 --- a/ppapi/shared_impl/file_ref_create_info.h +++ b/ppapi/shared_impl/file_ref_create_info.h @@ -10,24 +10,42 @@ #include "base/files/file_path.h" #include "ppapi/c/pp_file_info.h" #include "ppapi/c/pp_resource.h" +#include "ppapi/shared_impl/ppapi_shared_export.h" namespace ppapi { // FileRefs are created in a number of places and they include a number of // return values. This struct encapsulates everything in one place. -struct FileRef_CreateInfo { +struct FileRefCreateInfo { + FileRefCreateInfo() : file_system_type(PP_FILESYSTEMTYPE_INVALID), + browser_pending_host_resource_id(0), + renderer_pending_host_resource_id(0), + file_system_plugin_resource(0) { } + + PPAPI_SHARED_EXPORT bool IsValid() const; + PP_FileSystemType file_system_type; std::string internal_path; std::string display_name; // Used when a FileRef is created in the Renderer. - int pending_host_resource_id; + int browser_pending_host_resource_id; + int renderer_pending_host_resource_id; // Since FileRef needs to hold a FileSystem reference, we need to pass the - // resource in this CreateInfo. + // resource in this CreateInfo. This struct doesn't hold any refrence on the + // file_system_plugin_resource. PP_Resource file_system_plugin_resource; }; +// Used in the renderer when sending a FileRefCreateInfo to a plugin for a +// FileRef on an external filesystem. +PPAPI_SHARED_EXPORT FileRefCreateInfo +MakeExternalFileRefCreateInfo(const base::FilePath& external_path, + const std::string& display_name, + int browser_pending_host_resource_id, + int renderer_pending_host_resource_id); + } // namespace ppapi #endif // PPAPI_SHARED_IMPL_FILE_REF_CREATE_INFO_H diff --git a/ppapi/shared_impl/ppb_file_ref_shared.cc b/ppapi/shared_impl/ppb_file_ref_shared.cc deleted file mode 100644 index a47cdb8..0000000 --- a/ppapi/shared_impl/ppb_file_ref_shared.cc +++ /dev/null @@ -1,54 +0,0 @@ -// 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. - -#include "ppapi/shared_impl/ppb_file_ref_shared.h" - -#include "base/logging.h" -#include "ppapi/shared_impl/var.h" - -namespace ppapi { - -PPB_FileRef_Shared::PPB_FileRef_Shared(ResourceObjectType type, - const PPB_FileRef_CreateInfo& info) - : 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(); - } -} - -PPB_FileRef_Shared::~PPB_FileRef_Shared() { -} - -thunk::PPB_FileRef_API* PPB_FileRef_Shared::AsPPB_FileRef_API() { - return this; -} - -PP_FileSystemType PPB_FileRef_Shared::GetFileSystemType() const { - return static_cast<PP_FileSystemType>(create_info_.file_system_type); -} - -PP_Var PPB_FileRef_Shared::GetName() const { - if (!name_var_.get()) { - name_var_ = new StringVar(create_info_.name); - } - return name_var_->GetPPVar(); -} - -PP_Var PPB_FileRef_Shared::GetPath() const { - if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) - return PP_MakeUndefined(); - if (!path_var_.get()) { - path_var_ = new StringVar(create_info_.path); - } - return path_var_->GetPPVar(); -} - -const PPB_FileRef_CreateInfo& PPB_FileRef_Shared::GetCreateInfo() const { - return create_info_; -} - -} // namespace ppapi diff --git a/ppapi/shared_impl/ppb_file_ref_shared.h b/ppapi/shared_impl/ppb_file_ref_shared.h deleted file mode 100644 index 5025eb3..0000000 --- a/ppapi/shared_impl/ppb_file_ref_shared.h +++ /dev/null @@ -1,70 +0,0 @@ -// 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. - -#ifndef PPAPI_SHARED_IMPL_PPB_FILE_REF_SHARED_H_ -#define PPAPI_SHARED_IMPL_PPB_FILE_REF_SHARED_H_ - -#include <string> - -#include "base/compiler_specific.h" -#include "ppapi/shared_impl/resource.h" -#include "ppapi/thunk/ppb_file_ref_api.h" - -namespace ppapi { - -class StringVar; - -// FileRefs are created in a number of places and they include a number of -// return values. This struct encapsulates everything in one place. -struct PPB_FileRef_CreateInfo { - PPB_FileRef_CreateInfo() - : file_system_type(PP_FILESYSTEMTYPE_EXTERNAL), - file_system_plugin_resource(0) {} - - ppapi::HostResource resource; - int file_system_type; // One of PP_FileSystemType values. - std::string path; - std::string name; - - // Since FileRef needs to hold a FileSystem reference, we need to pass the - // resource in this CreateInfo. Note that this is a plugin resource as - // FileSystem is already in new design. - PP_Resource file_system_plugin_resource; -}; - -// This class provides the shared implementation of a FileRef. The functions -// that actually "do stuff" like Touch and MakeDirectory are implemented -// differently for the proxied and non-proxied derived classes. -class PPAPI_SHARED_EXPORT PPB_FileRef_Shared - : public Resource, - public thunk::PPB_FileRef_API { - public: - PPB_FileRef_Shared(ResourceObjectType type, - const PPB_FileRef_CreateInfo& info); - virtual ~PPB_FileRef_Shared(); - - // Resource overrides. - virtual thunk::PPB_FileRef_API* AsPPB_FileRef_API() OVERRIDE; - - // PPB_FileRef_API implementation (partial). - virtual PP_FileSystemType GetFileSystemType() const OVERRIDE; - virtual PP_Var GetName() const OVERRIDE; - virtual PP_Var GetPath() const OVERRIDE; - virtual const PPB_FileRef_CreateInfo& GetCreateInfo() const OVERRIDE; - virtual PP_Var GetAbsolutePath() = 0; - - private: - PPB_FileRef_CreateInfo create_info_; - - // Lazily initialized vars created from the create_info_. This is so we can - // return the identical string object every time they're requested. - mutable scoped_refptr<StringVar> name_var_; - mutable scoped_refptr<StringVar> path_var_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(PPB_FileRef_Shared); -}; - -} // namespace ppapi - -#endif // PPAPI_SHARED_IMPL_PPB_FILE_REF_SHARED_H_ diff --git a/ppapi/shared_impl/url_request_info_data.cc b/ppapi/shared_impl/url_request_info_data.cc index 8bb02a4..15b2787 100644 --- a/ppapi/shared_impl/url_request_info_data.cc +++ b/ppapi/shared_impl/url_request_info_data.cc @@ -17,6 +17,7 @@ const int32_t kDefaultPrefetchBufferLowerThreshold = 50 * 1000 * 1000; URLRequestInfoData::BodyItem::BodyItem() : is_file(false), + file_ref_pp_resource(0), start_offset(0), number_of_bytes(-1), expected_last_modified_time(0.0) { @@ -25,6 +26,7 @@ URLRequestInfoData::BodyItem::BodyItem() URLRequestInfoData::BodyItem::BodyItem(const std::string& data) : is_file(false), data(data), + file_ref_pp_resource(0), start_offset(0), number_of_bytes(-1), expected_last_modified_time(0.0) { @@ -36,8 +38,8 @@ URLRequestInfoData::BodyItem::BodyItem( int64_t number_of_bytes, PP_Time expected_last_modified_time) : is_file(true), - file_ref(file_ref), - file_ref_host_resource(file_ref->host_resource()), + file_ref_resource(file_ref), + file_ref_pp_resource(file_ref->pp_resource()), start_offset(start_offset), number_of_bytes(number_of_bytes), expected_last_modified_time(expected_last_modified_time) { diff --git a/ppapi/shared_impl/url_request_info_data.h b/ppapi/shared_impl/url_request_info_data.h index 501251a..d0acf4b 100644 --- a/ppapi/shared_impl/url_request_info_data.h +++ b/ppapi/shared_impl/url_request_info_data.h @@ -9,10 +9,12 @@ #include <vector> #include "base/memory/ref_counted.h" +#include "ppapi/c/pp_resource.h" #include "ppapi/c/pp_stdint.h" #include "ppapi/c/pp_time.h" -#include "ppapi/shared_impl/host_resource.h" +#include "ppapi/shared_impl/ppapi_globals.h" #include "ppapi/shared_impl/ppapi_shared_export.h" +#include "ppapi/shared_impl/resource_tracker.h" namespace ppapi { @@ -32,19 +34,12 @@ struct PPAPI_SHARED_EXPORT URLRequestInfoData { std::string data; - // Is is_file is set, these variables are set. Note that the resource - // may still be NULL in some cases, such as deserialization errors. - // - // This is a bit tricky. In the plugin side of the proxy, both the file ref - // and the file_ref_host_resource will be set and valid. The scoped_refptr - // ensures that the resource is alive for as long as the BodyItem is. - // - // When we deserialize this in the renderer, only the - // file_ref_host_resource's are serialized over IPC. The file_refs won't be - // valid until the host resources are converted to Resource pointers in the - // PPB_URLRequestInfo_Impl. - scoped_refptr<Resource> file_ref; - HostResource file_ref_host_resource; + // Only set on the plugin-side, for refcounting purposes. Only valid when + // |is_file| is set. + scoped_refptr<Resource> file_ref_resource; + // This struct holds no ref to this resource. Only valid when |is_file| is + // set. + PP_Resource file_ref_pp_resource; int64_t start_offset; int64_t number_of_bytes; diff --git a/ppapi/shared_impl/url_response_info_data.h b/ppapi/shared_impl/url_response_info_data.h index a40ca50..c6f7dbd 100644 --- a/ppapi/shared_impl/url_response_info_data.h +++ b/ppapi/shared_impl/url_response_info_data.h @@ -8,7 +8,7 @@ #include <string> #include "ppapi/c/pp_stdint.h" -#include "ppapi/shared_impl/ppb_file_ref_shared.h" +#include "ppapi/shared_impl/file_ref_create_info.h" #include "ppapi/shared_impl/ppapi_shared_export.h" namespace ppapi { @@ -23,8 +23,8 @@ struct PPAPI_SHARED_EXPORT URLResponseInfoData { std::string status_text; std::string redirect_url; - // Nonzero when streaming to a file. - PPB_FileRef_CreateInfo body_as_file_ref; + // Valid when streaming to a file. + FileRefCreateInfo body_as_file_ref; }; } // namespace ppapi |