Skip to content

Commit

Permalink
Pepper: GetInfoForRenderer for N FileRefs.
Browse files Browse the repository at this point in the history
Currently, operations to support AppendFileRefToBody in the renderer send a
sync message to the browser for each file ref.

This change alters GetInfoForRenderer (for the FileRef change) to take a vector
of FileRefs and return a vector of results back, reducing the number of IPC
round trips.

TBR=jschuh
BUG=225441

Review URL: https://chromiumcodereview.appspot.com/21891002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215356 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
teravest@chromium.org committed Aug 2, 2013
1 parent 562378f commit 6e37b42
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 38 deletions.
39 changes: 23 additions & 16 deletions content/browser/renderer_host/pepper/pepper_renderer_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,35 @@ void PepperRendererConnection::OnMsgCreateResourceHostFromHost(
void PepperRendererConnection::OnMsgFileRefGetInfoForRenderer(
int routing_id,
int child_process_id,
const ppapi::proxy::ResourceMessageCallParams& params) {
PP_FileSystemType fs_type = PP_FILESYSTEMTYPE_INVALID;
std::string file_system_url_spec;
base::FilePath external_path;
int32_t sequence,
const std::vector<PP_Resource>& resources) {
std::vector<PP_Resource> out_resources;
std::vector<PP_FileSystemType> fs_types;
std::vector<std::string> file_system_url_specs;
std::vector<base::FilePath> external_paths;

BrowserPpapiHostImpl* host = GetHostForChildProcess(child_process_id);
if (host) {
ppapi::host::ResourceHost* resource_host =
host->GetPpapiHost()->GetResourceHost(params.pp_resource());
if (resource_host && resource_host->IsFileRefHost()) {
PepperFileRefHost* file_ref_host =
static_cast<PepperFileRefHost*>(resource_host);
fs_type = file_ref_host->GetFileSystemType();
file_system_url_spec = file_ref_host->GetFileSystemURLSpec();
external_path = file_ref_host->GetExternalPath();
for (size_t i = 0; i < resources.size(); ++i) {
ppapi::host::ResourceHost* resource_host =
host->GetPpapiHost()->GetResourceHost(resources[i]);
if (resource_host && resource_host->IsFileRefHost()) {
PepperFileRefHost* file_ref_host =
static_cast<PepperFileRefHost*>(resource_host);
out_resources.push_back(resources[i]);
fs_types.push_back(file_ref_host->GetFileSystemType());
file_system_url_specs.push_back(file_ref_host->GetFileSystemURLSpec());
external_paths.push_back(file_ref_host->GetExternalPath());
}
}
}
Send(new PpapiHostMsg_FileRef_GetInfoForRendererReply(
routing_id,
params.sequence(),
fs_type,
file_system_url_spec,
external_path));
sequence,
out_resources,
fs_types,
file_system_url_specs,
external_paths));
}

void PepperRendererConnection::OnMsgDidCreateInProcessInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class PepperRendererConnection : public BrowserMessageFilter {
void OnMsgFileRefGetInfoForRenderer(
int routing_id,
int child_process_id,
const ppapi::proxy::ResourceMessageCallParams& params);
int32_t sequence_num,
const std::vector<PP_Resource>& resources);

void OnMsgDidCreateInProcessInstance(
PP_Instance instance,
Expand Down
15 changes: 8 additions & 7 deletions content/renderer/pepper/pepper_browser_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,12 @@ void PepperBrowserConnection::SendBrowserCreate(

void PepperBrowserConnection::SendBrowserFileRefGetInfo(
int child_process_id,
PP_Resource resource,
const std::vector<PP_Resource>& resources,
const FileRefGetInfoCallback& callback) {
int32_t sequence_number = GetNextSequence();
get_info_map_[sequence_number] = callback;
ppapi::proxy::ResourceMessageCallParams params(resource, sequence_number);
helper_->Send(new PpapiHostMsg_FileRef_GetInfoForRenderer(
helper_->routing_id(), child_process_id, params));
helper_->routing_id(), child_process_id, sequence_number, resources));
}

void PepperBrowserConnection::OnMsgCreateResourceHostFromHostReply(
Expand All @@ -104,16 +103,18 @@ void PepperBrowserConnection::OnMsgCreateResourceHostFromHostReply(

void PepperBrowserConnection::OnMsgFileRefGetInfoReply(
int32_t sequence_number,
PP_FileSystemType type,
std::string file_system_url_spec,
base::FilePath external_path) {
const std::vector<PP_Resource>& resources,
const std::vector<PP_FileSystemType>& types,
const std::vector<std::string>& file_system_url_specs,
const std::vector<base::FilePath>& external_paths) {
// Check that the message is destined for the plugin this object is associated
// with.
std::map<int32_t, FileRefGetInfoCallback>::iterator it =
get_info_map_.find(sequence_number);
if (it != get_info_map_.end()) {
it->second.Run(type, file_system_url_spec, external_path);
FileRefGetInfoCallback callback = it->second;
get_info_map_.erase(it);
callback.Run(resources, types, file_system_url_specs, external_paths);
} else {
NOTREACHED();
}
Expand Down
20 changes: 12 additions & 8 deletions content/renderer/pepper/pepper_browser_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ class PepperHelperImpl;
class PepperBrowserConnection {
public:
typedef base::Callback<void(int)> PendingResourceIDCallback;
typedef base::Callback<void(PP_FileSystemType,
std::string,
base::FilePath)> FileRefGetInfoCallback;
typedef base::Callback<void(
const std::vector<PP_Resource>&,
const std::vector<PP_FileSystemType>&,
const std::vector<std::string>&,
const std::vector<base::FilePath>&)> FileRefGetInfoCallback;

explicit PepperBrowserConnection(PepperHelperImpl* helper);
virtual ~PepperBrowserConnection();
Expand All @@ -50,7 +52,7 @@ class PepperBrowserConnection {
// |resource|. |callback| will be run when a reply is received with the
// file information.
void SendBrowserFileRefGetInfo(int child_process_id,
PP_Resource resource,
const std::vector<PP_Resource>& resource,
const FileRefGetInfoCallback& callback);

// Called when the renderer creates an in-process instance.
Expand All @@ -66,10 +68,12 @@ class PepperBrowserConnection {
// Message handlers.
void OnMsgCreateResourceHostFromHostReply(int32_t sequence_number,
int pending_resource_host_id);
void OnMsgFileRefGetInfoReply(int32_t sequence_number,
PP_FileSystemType type,
std::string file_system_url_spec,
base::FilePath external_path);
void OnMsgFileRefGetInfoReply(
int32_t sequence_number,
const std::vector<PP_Resource>& resources,
const std::vector<PP_FileSystemType>& types,
const std::vector<std::string>& file_system_url_specs,
const std::vector<base::FilePath>& external_paths);

// Return the next sequence number.
int32_t GetNextSequence();
Expand Down
14 changes: 8 additions & 6 deletions ppapi/proxy/ppapi_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1836,21 +1836,23 @@ IPC_MESSAGE_CONTROL1(PpapiPluginMsg_BrowserFontSingleton_GetFontFamiliesReply,
// |child_process_id|. |routing_id| is sent so that the reply can be routed
// properly in the renderer.
// Only sent from the renderer to the browser.
IPC_MESSAGE_CONTROL3(PpapiHostMsg_FileRef_GetInfoForRenderer,
IPC_MESSAGE_CONTROL4(PpapiHostMsg_FileRef_GetInfoForRenderer,
int /* routing_id */,
int /* child_process_id */,
ppapi::proxy::ResourceMessageCallParams /* params */)
int32_t /* sequence */,
std::vector<PP_Resource> /* resources */)

// Reply to PpapiHostMsg_FileRef_GetInfoForRenderer with a sequence number for
// invoking the right callback, |fs_type| which indicates the file system, and
// path information in either |file_system_url_spec| (for internal file systems)
// or |external_path| (for external file systems).
// Only sent from the browser to the renderer.
IPC_MESSAGE_ROUTED4(PpapiHostMsg_FileRef_GetInfoForRendererReply,
IPC_MESSAGE_ROUTED5(PpapiHostMsg_FileRef_GetInfoForRendererReply,
int32_t /* sequence */,
PP_FileSystemType /* fs_type */,
std::string /* file_system_url_spec */,
base::FilePath /* external_path */)
std::vector<PP_Resource> /* resources */,
std::vector<PP_FileSystemType> /* fs_type */,
std::vector<std::string> /* file_system_url_spec */,
std::vector<base::FilePath> /* external_path */)

// Flash -----------------------------------------------------------------------

Expand Down

0 comments on commit 6e37b42

Please sign in to comment.