content/gpu: Ownership and lifetime cleanup for CommandBufferProxyImpl.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_browser_connection.h
blob241d6123d9e50966855cc0db6d70f5abc262a15f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/files/file_path.h"
14 #include "content/public/renderer/render_frame_observer.h"
15 #include "content/public/renderer/render_frame_observer_tracker.h"
16 #include "ppapi/c/pp_file_info.h"
17 #include "ppapi/c/pp_instance.h"
18 #include "ppapi/c/pp_resource.h"
20 class GURL;
22 namespace content {
24 // This class represents a connection from the renderer to the browser for
25 // sending/receiving pepper ResourceHost related messages. When the browser
26 // and renderer communicate about ResourceHosts, they should pass the plugin
27 // process ID to identify which plugin they are talking about.
28 class PepperBrowserConnection
29 : public RenderFrameObserver,
30 public RenderFrameObserverTracker<PepperBrowserConnection> {
31 public:
32 typedef base::Callback<void(const std::vector<int>&)>
33 PendingResourceIDCallback;
34 explicit PepperBrowserConnection(RenderFrame* render_frame);
35 ~PepperBrowserConnection() override;
37 bool OnMessageReceived(const IPC::Message& message) override;
39 // TODO(teravest): Instead of having separate methods per message, we should
40 // add generic functionality similar to PluginResource::Call().
42 // Sends a request to the browser to create ResourceHosts for the given
43 // |instance| of a plugin identified by |child_process_id|. |callback| will be
44 // run when a reply is received with the pending resource IDs.
45 void SendBrowserCreate(PP_Instance instance,
46 int child_process_id,
47 const std::vector<IPC::Message>& create_messages,
48 const PendingResourceIDCallback& callback);
50 // Called when the renderer creates an in-process instance.
51 void DidCreateInProcessInstance(PP_Instance instance,
52 int render_frame_id,
53 const GURL& document_url,
54 const GURL& plugin_url);
56 // Called when the renderer deletes an in-process instance.
57 void DidDeleteInProcessInstance(PP_Instance instance);
59 private:
60 // Message handlers.
61 void OnMsgCreateResourceHostsFromHostReply(
62 int32_t sequence_number,
63 const std::vector<int>& pending_resource_host_ids);
65 // Return the next sequence number.
66 int32_t GetNextSequence();
68 // Sequence number to track pending callbacks.
69 int32_t next_sequence_number_;
71 // Maps a sequence number to the callback to be run.
72 std::map<int32_t, PendingResourceIDCallback> pending_create_map_;
73 DISALLOW_COPY_AND_ASSIGN(PepperBrowserConnection);
76 } // namespace content
78 #endif // CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_