OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_CHILD_PERMISSIONS_PERMISSION_MANAGER_H_ | |
6 #define CONTENT_CHILD_PERMISSIONS_PERMISSION_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "base/id_map.h" | |
12 #include "base/macros.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "content/common/permission_service.mojom.h" | |
15 #include "third_party/WebKit/public/platform/modules/permissions/WebPermissionCl ient.h" | |
16 | |
17 namespace content { | |
18 | |
19 class ServiceRegistry; | |
20 | |
21 // The PermissionManager is a layer between Blink and the Mojo PermissionService | |
22 // It implements blink::WebPermissionClient. It is being used from workers and | |
23 // frames independently. When called outside of the main thread, | |
24 // QueryPermissionForWorker is meant to be called. It will handle the thread | |
25 // jumping. | |
26 class PermissionManager : | |
27 public NON_EXPORTED_BASE(blink::WebPermissionClient) { | |
jochen (gone - plz use gerrit)
2015/03/11 16:06:56
more copy/paste?
mlamouri (slow - plz ping)
2015/03/11 17:13:19
No, that's just me being stupid :)
| |
28 public: | |
29 PermissionManager(ServiceRegistry& service_registry); | |
30 virtual ~PermissionManager(); | |
31 | |
32 // blink::WebPermissionClient implementation. | |
33 virtual void queryPermission(blink::WebPermissionType type, | |
34 const blink::WebURL& origin, | |
35 blink::WebPermissionQueryCallback* callback); | |
36 | |
37 void QueryPermissionForWorker(blink::WebPermissionType type, | |
38 const std::string& origin, | |
39 blink::WebPermissionQueryCallback* callback, | |
40 int worker_thread_id); | |
41 | |
42 protected: | |
43 void QueryPermissionInternal(blink::WebPermissionType type, | |
44 const std::string& origin, | |
45 blink::WebPermissionQueryCallback* callback, | |
46 int worker_thread_id); | |
47 | |
48 void OnQueryPermission(int request_id, PermissionStatus status); | |
49 | |
50 // Called from the main thread in order to run the callback in the thread it | |
51 // was created on. | |
52 static void RunCallbackOnWorkerThread( | |
53 blink::WebPermissionQueryCallback* callback, | |
54 scoped_ptr<blink::WebPermissionStatus> status); | |
55 | |
56 // Saves some basic information about the callback in order to be able to run | |
57 // it in the right thread. | |
58 class CallbackInformation { | |
59 public: | |
60 CallbackInformation(blink::WebPermissionQueryCallback* callback, | |
61 int worker_thread_id); | |
62 ~CallbackInformation(); | |
63 | |
64 blink::WebPermissionQueryCallback* callback() const; | |
65 int worker_thread_id() const; | |
66 | |
67 blink::WebPermissionQueryCallback* ReleaseCallback(); | |
68 | |
69 private: | |
70 scoped_ptr<blink::WebPermissionQueryCallback> callback_; | |
71 int worker_thread_id_; | |
72 | |
73 DISALLOW_COPY_AND_ASSIGN(CallbackInformation); | |
74 }; | |
75 using CallbackMap = IDMap<CallbackInformation, IDMapOwnPointer>; | |
76 CallbackMap pending_callbacks_; | |
77 | |
78 PermissionServicePtr permission_service_; | |
79 | |
80 DISALLOW_COPY_AND_ASSIGN(PermissionManager); | |
81 }; | |
82 | |
83 } // namespace content | |
84 | |
85 #endif // CONTENT_CHILD_PERMISSIONS_PERMISSION_MANAGER_H_ | |
OLD | NEW |