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

Side by Side Diff: content/child/permissions/permission_dispatcher.h

Issue 1260193009: renderer: implement multiple permission requesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permissions-request-multiple
Patch Set: Created 5 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ 5 #ifndef CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_
6 #define CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ 6 #define CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback_forward.h" 10 #include "base/callback_forward.h"
(...skipping 25 matching lines...) Expand all
36 explicit PermissionDispatcher(ServiceRegistry* service_registry); 36 explicit PermissionDispatcher(ServiceRegistry* service_registry);
37 virtual ~PermissionDispatcher(); 37 virtual ~PermissionDispatcher();
38 38
39 // blink::WebPermissionClient implementation. 39 // blink::WebPermissionClient implementation.
40 virtual void queryPermission(blink::WebPermissionType type, 40 virtual void queryPermission(blink::WebPermissionType type,
41 const blink::WebURL& origin, 41 const blink::WebURL& origin,
42 blink::WebPermissionCallback* callback); 42 blink::WebPermissionCallback* callback);
43 virtual void requestPermission(blink::WebPermissionType, 43 virtual void requestPermission(blink::WebPermissionType,
44 const blink::WebURL& origin, 44 const blink::WebURL& origin,
45 blink::WebPermissionCallback* callback); 45 blink::WebPermissionCallback* callback);
46 virtual void requestPermissions(
47 const blink::WebVector<blink::WebPermissionType>& types,
48 const blink::WebURL& origin,
49 blink::WebPermissionsCallback* callback);
46 virtual void revokePermission(blink::WebPermissionType, 50 virtual void revokePermission(blink::WebPermissionType,
47 const blink::WebURL& origin, 51 const blink::WebURL& origin,
48 blink::WebPermissionCallback* callback); 52 blink::WebPermissionCallback* callback);
49 virtual void startListening(blink::WebPermissionType type, 53 virtual void startListening(blink::WebPermissionType type,
50 const blink::WebURL& origin, 54 const blink::WebURL& origin,
51 blink::WebPermissionObserver* observer); 55 blink::WebPermissionObserver* observer);
52 virtual void stopListening(blink::WebPermissionObserver* observer); 56 virtual void stopListening(blink::WebPermissionObserver* observer);
53 57
54 // The following methods must be called by workers on the main thread. 58 // The following methods must be called by workers on the main thread.
55 void QueryPermissionForWorker(blink::WebPermissionType type, 59 void QueryPermissionForWorker(blink::WebPermissionType type,
56 const std::string& origin, 60 const std::string& origin,
57 blink::WebPermissionCallback* callback, 61 blink::WebPermissionCallback* callback,
58 int worker_thread_id); 62 int worker_thread_id);
59 void RequestPermissionForWorker(blink::WebPermissionType type, 63 void RequestPermissionForWorker(blink::WebPermissionType type,
60 const std::string& origin, 64 const std::string& origin,
61 blink::WebPermissionCallback* callback, 65 blink::WebPermissionCallback* callback,
62 int worker_thread_id); 66 int worker_thread_id);
67 void RequestPermissionsForWorker(
68 const blink::WebVector<blink::WebPermissionType>& types,
69 const std::string& origin,
70 blink::WebPermissionsCallback* callback,
71 int worker_thread_id);
63 void RevokePermissionForWorker(blink::WebPermissionType type, 72 void RevokePermissionForWorker(blink::WebPermissionType type,
64 const std::string& origin, 73 const std::string& origin,
65 blink::WebPermissionCallback* callback, 74 blink::WebPermissionCallback* callback,
66 int worker_thread_id); 75 int worker_thread_id);
67 void StartListeningForWorker( 76 void StartListeningForWorker(
68 blink::WebPermissionType type, 77 blink::WebPermissionType type,
69 const std::string& origin, 78 const std::string& origin,
70 int worker_thread_id, 79 int worker_thread_id,
71 const base::Callback<void(blink::WebPermissionStatus)>& callback); 80 const base::Callback<void(blink::WebPermissionStatus)>& callback);
72 void GetNextPermissionChangeForWorker( 81 void GetNextPermissionChangeForWorker(
73 blink::WebPermissionType type, 82 blink::WebPermissionType type,
74 const std::string& origin, 83 const std::string& origin,
75 blink::WebPermissionStatus status, 84 blink::WebPermissionStatus status,
76 int worker_thread_id, 85 int worker_thread_id,
77 const base::Callback<void(blink::WebPermissionStatus)>& callback); 86 const base::Callback<void(blink::WebPermissionStatus)>& callback);
78 87
79 private: 88 private:
80 // Runs the given |callback| with |status| as a parameter. It has to be run 89 // Runs the given |callback| with |status| as a parameter. It has to be run
81 // on a worker thread. 90 // on a worker thread.
82 static void RunCallbackOnWorkerThread( 91 static void RunCallbackOnWorkerThread(
83 blink::WebPermissionCallback* callback, 92 blink::WebPermissionCallback* callback,
84 scoped_ptr<blink::WebPermissionStatus> status); 93 scoped_ptr<blink::WebPermissionStatus> status);
94 static void RunMultiCallbackOnWorkerThread(
mlamouri (slow - plz ping) 2015/08/18 13:37:15 I think it's find to overload RunCallbackOnWorkerT
Lalit Maganti 2015/08/20 14:23:30 Can't actually do this because I use it in a callb
95 blink::WebPermissionsCallback* callback,
96 scoped_ptr<blink::WebVector<blink::WebPermissionStatus>> statuses);
85 97
86 // Helper method that returns an initialized PermissionServicePtr. 98 // Helper method that returns an initialized PermissionServicePtr.
87 PermissionServicePtr& GetPermissionServicePtr(); 99 PermissionServicePtr& GetPermissionServicePtr();
88 100
89 void QueryPermissionInternal(blink::WebPermissionType type, 101 void QueryPermissionInternal(blink::WebPermissionType type,
90 const std::string& origin, 102 const std::string& origin,
91 blink::WebPermissionCallback* callback, 103 blink::WebPermissionCallback* callback,
92 int worker_thread_id); 104 int worker_thread_id);
93 void RequestPermissionInternal(blink::WebPermissionType type, 105 void RequestPermissionInternal(blink::WebPermissionType type,
94 const std::string& origin, 106 const std::string& origin,
95 blink::WebPermissionCallback* callback, 107 blink::WebPermissionCallback* callback,
96 int worker_thread_id); 108 int worker_thread_id);
109 void RequestPermissionsInternal(
110 const blink::WebVector<blink::WebPermissionType>& types,
111 const std::string& origin,
112 blink::WebPermissionsCallback* callback,
113 int worker_thread_id);
97 void RevokePermissionInternal(blink::WebPermissionType type, 114 void RevokePermissionInternal(blink::WebPermissionType type,
98 const std::string& origin, 115 const std::string& origin,
99 blink::WebPermissionCallback* callback, 116 blink::WebPermissionCallback* callback,
100 int worker_thread_id); 117 int worker_thread_id);
101 118
102 // This is the callback function used for query and revoke 119 // This is the callback function used for query and revoke
103 void OnPermissionResponse(int request_id, 120 void OnPermissionResponse(int request_id,
104 PermissionStatus status); 121 PermissionStatus status);
122 void OnPermissionsResponse(int request_id,
123 const mojo::Array<PermissionStatus>& status);
105 void OnPermissionChanged(blink::WebPermissionType type, 124 void OnPermissionChanged(blink::WebPermissionType type,
106 const std::string& origin, 125 const std::string& origin,
107 blink::WebPermissionObserver* observer, 126 blink::WebPermissionObserver* observer,
108 PermissionStatus status); 127 PermissionStatus status);
109 void OnPermissionChangedForWorker( 128 void OnPermissionChangedForWorker(
110 int worker_thread_id, 129 int worker_thread_id,
111 const base::Callback<void(blink::WebPermissionStatus)>& callback, 130 const base::Callback<void(blink::WebPermissionStatus)>& callback,
112 PermissionStatus status); 131 PermissionStatus status);
113 132
114 void GetNextPermissionChange(blink::WebPermissionType type, 133 void GetNextPermissionChange(blink::WebPermissionType type,
115 const std::string& origin, 134 const std::string& origin,
116 blink::WebPermissionObserver* observer, 135 blink::WebPermissionObserver* observer,
117 PermissionStatus current_status); 136 PermissionStatus current_status);
118 137
119 // Saves some basic information about the callback in order to be able to run 138 // Saves some basic information about the callback in order to be able to run
120 // it in the right thread. 139 // it in the right thread.
140 template<typename T>
121 class CallbackInformation { 141 class CallbackInformation {
122 public: 142 public:
123 CallbackInformation(blink::WebPermissionCallback* callback, 143 CallbackInformation(T* callback,
124 int worker_thread_id); 144 int worker_thread_id)
125 ~CallbackInformation(); 145 : callback_(callback),
146 worker_thread_id_(worker_thread_id) {
147 }
126 148
127 blink::WebPermissionCallback* callback() const; 149 ~CallbackInformation() {}
mlamouri (slow - plz ping) 2015/08/18 13:37:15 nit: = default.
Lalit Maganti 2015/08/20 14:23:30 Removed class.
128 int worker_thread_id() const;
129 150
130 blink::WebPermissionCallback* ReleaseCallback(); 151 T* callback() const {
152 return callback_.get();
153 }
154
155 int worker_thread_id() const {
156 return worker_thread_id_;
157 }
158
159 T* ReleaseCallback() {
160 return callback_.release();
161 }
131 162
132 private: 163 private:
133 scoped_ptr<blink::WebPermissionCallback> callback_; 164 scoped_ptr<T> callback_;
134 int worker_thread_id_; 165 int worker_thread_id_;
135 166
136 DISALLOW_COPY_AND_ASSIGN(CallbackInformation); 167 DISALLOW_COPY_AND_ASSIGN(CallbackInformation);
137 }; 168 };
138 using CallbackMap = IDMap<CallbackInformation, IDMapOwnPointer>; 169
170 using SingleCallbackInfo = CallbackInformation<blink::WebPermissionCallback>;
mlamouri (slow - plz ping) 2015/08/18 13:37:15 I dislike the name to be honest. Maybe you could c
Lalit Maganti 2015/08/20 14:23:30 The reason I put the using is because the lines be
171 using CallbackMap = IDMap<SingleCallbackInfo, IDMapOwnPointer>;
139 CallbackMap pending_callbacks_; 172 CallbackMap pending_callbacks_;
140 173
174 using MultiCallbackInfo = CallbackInformation<blink::WebPermissionsCallback>;
mlamouri (slow - plz ping) 2015/08/18 13:37:15 ditto.
Lalit Maganti 2015/08/20 14:23:30 Acknowledged.
175 using MultipleCallbackMap = IDMap<MultiCallbackInfo, IDMapOwnPointer>;
mlamouri (slow - plz ping) 2015/08/18 13:37:15 Again, the name isn't clear. At least, add a comme
Lalit Maganti 2015/08/20 14:23:30 Acknowledged.
176 MultipleCallbackMap multiple_pending_callbacks_;
177
141 ServiceRegistry* service_registry_; 178 ServiceRegistry* service_registry_;
142 PermissionServicePtr permission_service_; 179 PermissionServicePtr permission_service_;
143 180
144 DISALLOW_COPY_AND_ASSIGN(PermissionDispatcher); 181 DISALLOW_COPY_AND_ASSIGN(PermissionDispatcher);
145 }; 182 };
146 183
147 } // namespace content 184 } // namespace content
148 185
149 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_ 186 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698