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

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

Issue 145463002: Extensions: Send the tab id to platform apps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix null pointer deref Created 6 years, 10 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_REQUEST_SENDER_H_ 5 #ifndef CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_
6 #define CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ 6 #define CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <map> 9 #include <map>
10 10
(...skipping 24 matching lines...) Expand all
35 virtual ~Source() {} 35 virtual ~Source() {}
36 36
37 virtual ChromeV8Context* GetContext() = 0; 37 virtual ChromeV8Context* GetContext() = 0;
38 virtual void OnResponseReceived(const std::string& name, 38 virtual void OnResponseReceived(const std::string& name,
39 int request_id, 39 int request_id,
40 bool success, 40 bool success,
41 const base::ListValue& response, 41 const base::ListValue& response,
42 const std::string& error) = 0; 42 const std::string& error) = 0;
43 }; 43 };
44 44
45 // Helper class to (re)set the |source_tab_id_| below.
46 class ScopedTabID {
47 public:
48 ScopedTabID(RequestSender* request_sender, int tab_id);
49 ~ScopedTabID();
50
51 private:
52 RequestSender* const request_sender_;
53 const int tab_id_;
54 const int previous_tab_id_;
55
56 DISALLOW_COPY_AND_ASSIGN(ScopedTabID);
57 };
58
45 explicit RequestSender(Dispatcher* dispatcher); 59 explicit RequestSender(Dispatcher* dispatcher);
46 ~RequestSender(); 60 ~RequestSender();
47 61
48 // In order to avoid collision, all |request_id|s passed into StartRequest() 62 // In order to avoid collision, all |request_id|s passed into StartRequest()
49 // should be generated by this method. 63 // should be generated by this method.
50 int GetNextRequestId() const; 64 int GetNextRequestId() const;
51 65
52 // Makes a call to the API function |name| that is to be handled by the 66 // Makes a call to the API function |name| that is to be handled by the
53 // extension host. The response to this request will be received in 67 // extension host. The response to this request will be received in
54 // HandleResponse(). 68 // HandleResponse().
(...skipping 11 matching lines...) Expand all
66 void HandleResponse(int request_id, 80 void HandleResponse(int request_id,
67 bool success, 81 bool success,
68 const base::ListValue& response, 82 const base::ListValue& response,
69 const std::string& error); 83 const std::string& error);
70 84
71 // Notifies this that a request source is no longer valid. 85 // Notifies this that a request source is no longer valid.
72 // TODO(kalman): Do this in a generic/safe way. 86 // TODO(kalman): Do this in a generic/safe way.
73 void InvalidateSource(Source* source); 87 void InvalidateSource(Source* source);
74 88
75 private: 89 private:
90 friend class ScopedTabID;
76 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap; 91 typedef std::map<int, linked_ptr<PendingRequest> > PendingRequestMap;
77 92
78 void InsertRequest(int request_id, PendingRequest* pending_request); 93 void InsertRequest(int request_id, PendingRequest* pending_request);
79 linked_ptr<PendingRequest> RemoveRequest(int request_id); 94 linked_ptr<PendingRequest> RemoveRequest(int request_id);
80 95
81 Dispatcher* dispatcher_; 96 Dispatcher* dispatcher_;
82 PendingRequestMap pending_requests_; 97 PendingRequestMap pending_requests_;
83 98
99 int source_tab_id_; // Id of the tab sending the request, or -1 if no tab.
100
84 DISALLOW_COPY_AND_ASSIGN(RequestSender); 101 DISALLOW_COPY_AND_ASSIGN(RequestSender);
85 }; 102 };
86 103
87 } // namespace extensions 104 } // namespace extensions
88 105
89 #endif // CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_ 106 #endif // CHROME_RENDERER_EXTENSIONS_REQUEST_SENDER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/messaging_bindings.cc ('k') | chrome/renderer/extensions/request_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698