Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: chrome/renderer/extensions/extension_request_sender.h

Issue 10703111: Cleanup: make ExtensionRequestSender manage its IPC responses directly, rather (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert sceopd_observer change Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_
6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ 6 #define CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <map> 10 #include <map>
11 11
12 #include "base/compiler_specific.h"
12 #include "base/memory/linked_ptr.h" 13 #include "base/memory/linked_ptr.h"
14 #include "base/scoped_observer.h"
15 #include "content/public/renderer/render_process_observer.h"
13 #include "v8/include/v8.h" 16 #include "v8/include/v8.h"
14 17
15 class ChromeV8ContextSet; 18 class ChromeV8ContextSet;
16 class ExtensionDispatcher; 19 class ExtensionDispatcher;
17 20
18 namespace base { 21 namespace base {
19 class ListValue; 22 class ListValue;
20 } 23 }
21 24
25 namespace content {
26 class RenderThread;
27 }
28
22 struct PendingRequest; 29 struct PendingRequest;
23 30
24 // Responsible for sending requests for named extension API functions to the 31 // Responsible for sending requests for named extension API functions to the
25 // extension host and routing the responses back to the caller. 32 // extension host and routing the responses back to the caller.
26 class ExtensionRequestSender { 33 class ExtensionRequestSender : content::RenderProcessObserver {
27 public: 34 public:
28 explicit ExtensionRequestSender(ExtensionDispatcher* extension_dispatcher, 35 explicit ExtensionRequestSender(ExtensionDispatcher* extension_dispatcher,
29 ChromeV8ContextSet* context_set); 36 ChromeV8ContextSet* context_set);
30 ~ExtensionRequestSender(); 37 virtual ~ExtensionRequestSender();
31 38
32 // Makes a call to the API function |name| that is to be handled by the 39 // Makes a call to the API function |name| that is to be handled by the
33 // extension host. The response to this request will be received in 40 // extension host.
34 // HandleResponse(). 41 // Returns the request ID of the request, or -1 if no request was made.
35 // TODO(koz): Remove |request_id| and generate that internally. 42 int StartRequest(const std::string& name,
36 void StartRequest(const std::string& name, 43 bool has_callback,
37 int request_id, 44 bool for_io_thread,
38 bool has_callback, 45 base::ListValue* value_args);
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
48 46
49 private: 47 private:
50 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; 48 // content::RenderProcessObserver implementation.
49 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE;
50
51 void OnExtensionResponse(int request_id,
52 bool success,
53 const base::ListValue& response,
54 const std::string& error);
51 55
52 void InsertRequest(int request_id, PendingRequest* pending_request); 56 void InsertRequest(int request_id, PendingRequest* pending_request);
53 linked_ptr<PendingRequest> RemoveRequest(int request_id); 57 linked_ptr<PendingRequest> RemoveRequest(int request_id);
54 58
59 // Owner (weak reference).
55 ExtensionDispatcher* extension_dispatcher_; 60 ExtensionDispatcher* extension_dispatcher_;
61
62 // V8 contexts (weak reference).
63 ChromeV8ContextSet* context_set_;
64
65 // Scoped observer to RenderProcessHost.
66 ScopedObserver<content::RenderThread, content::RenderProcessObserver>
67 scoped_observer_;
68
69 // The next request ID.
70 int next_request_id_;
71
72 // Pending requests.
73 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap;
56 PendingRequestMap pending_requests_; 74 PendingRequestMap pending_requests_;
57 ChromeV8ContextSet* context_set_;
58 75
59 DISALLOW_COPY_AND_ASSIGN(ExtensionRequestSender); 76 DISALLOW_COPY_AND_ASSIGN(ExtensionRequestSender);
60 }; 77 };
61 78
62 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_ 79 #endif // CHROME_RENDERER_EXTENSIONS_EXTENSION_REQUEST_SENDER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/extension_helper.cc ('k') | chrome/renderer/extensions/extension_request_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698