blob: 20f7baf6da1b6203ee484e8c9a482a15234b9d53 [file] [log] [blame]
[email protected]f7885d42012-04-03 08:30:041// Copyright (c) 2012 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.
4
5#ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_
6#define CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_
7#pragma once
8
9#include <string>
10#include <map>
11
12#include "base/memory/linked_ptr.h"
13#include "v8/include/v8.h"
14
15class ChromeV8ContextSet;
16class ExtensionDispatcher;
17
18namespace base {
19class ListValue;
20}
21
22struct PendingRequest;
23
24// Responsible for sending requests for named extension API functions to the
25// extension host and routing the responses back to the caller.
[email protected]74e21e72012-07-09 21:20:5326class ExtensionRequestSender {
[email protected]f7885d42012-04-03 08:30:0427 public:
28 explicit ExtensionRequestSender(ExtensionDispatcher* extension_dispatcher,
29 ChromeV8ContextSet* context_set);
[email protected]74e21e72012-07-09 21:20:5330 ~ExtensionRequestSender();
[email protected]f7885d42012-04-03 08:30:0431
32 // Makes a call to the API function |name| that is to be handled by the
[email protected]74e21e72012-07-09 21:20:5333 // extension host. The response to this request will be received in
34 // HandleResponse().
35 // TODO(koz): Remove |request_id| and generate that internally.
36 void StartRequest(const std::string& name,
37 int request_id,
38 bool has_callback,
39 bool for_io_thread,
40 base::ListValue* value_args);
41
42 // Handles responses from the extension host to calls made by StartRequest().
43 void HandleResponse(int request_id,
44 bool success,
45 const base::ListValue& response,
46 const std::string& error);
47
[email protected]f7885d42012-04-03 08:30:0448
49 private:
[email protected]74e21e72012-07-09 21:20:5350 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap;
[email protected]f7885d42012-04-03 08:30:0451
52 void InsertRequest(int request_id, PendingRequest* pending_request);
53 linked_ptr<PendingRequest> RemoveRequest(int request_id);
54
55 ExtensionDispatcher* extension_dispatcher_;
[email protected]21776be2012-07-09 03:53:3256 PendingRequestMap pending_requests_;
[email protected]74e21e72012-07-09 21:20:5357 ChromeV8ContextSet* context_set_;
[email protected]21776be2012-07-09 03:53:3258
[email protected]f7885d42012-04-03 08:30:0459 DISALLOW_COPY_AND_ASSIGN(ExtensionRequestSender);
60};
61
62#endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_