OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <unordered_map> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/singleton.h" |
| 13 #include "content/common/content_export.h" |
| 14 #include "gpu/ipc/common/android/scoped_surface_request_conduit.h" |
| 15 #include "ui/gl/android/scoped_java_surface.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 // TODO(tguilbert): Change the 128 bit unguessable token from a base64 string |
| 20 // into the token base class, when crbug.com/643857 is completed. |
| 21 class CONTENT_EXPORT ScopedSurfaceRequestManager |
| 22 : public gpu::ScopedSurfaceRequestConduit { |
| 23 public: |
| 24 static ScopedSurfaceRequestManager* GetInstance(); |
| 25 |
| 26 using ScopedSurfaceRequestCB = base::Callback<void(gl::ScopedJavaSurface)>; |
| 27 |
| 28 // Registers a request, and returns the |request_token| that should be used to |
| 29 // call Fulfill at a later time. The caller is responsible for unregistering |
| 30 // the request, if it is destroyed before the request is fulfilled. |
| 31 // It is the requester's responsability to check the validity of the final |
| 32 // ScopedJavaSurface (as passing an empty surface is a valid operation). |
| 33 // Must be called on the UI thread. |
| 34 std::string RegisterScopedSurfaceRequest(ScopedSurfaceRequestCB request_cb); |
| 35 |
| 36 // Unregisters a request registered under |request_token| if it exists, |
| 37 // no-ops otherwise. |
| 38 // Must be called on the UI thread. |
| 39 void UnregisterScopedSurfaceRequest(std::string request_token); |
| 40 |
| 41 // Unregisters and runs the request callback identified by |request_token| if |
| 42 // one exists, no-ops otherwise. |
| 43 // Passing an empty |surface| is a valid operation that will complete the |
| 44 // request. |
| 45 // Can be called from any thread. The request will be run synchonously on the |
| 46 // UI thread. |
| 47 void FulfillScopedSurfaceRequest(std::string request_token, |
| 48 gl::ScopedJavaSurface surface); |
| 49 |
| 50 // Implementation of ScopedSurfaceRequestConduit. |
| 51 // To be used in the single process case. |
| 52 // Can be called from any thread. |
| 53 void ForwardSurfaceTextureForSurfaceRequest( |
| 54 std::string request_token, |
| 55 gl::SurfaceTexture* surface_texture) override; |
| 56 |
| 57 void clear_requests_for_testing() { request_callbacks_.clear(); } |
| 58 |
| 59 int request_count_for_testing() { return request_callbacks_.size(); } |
| 60 |
| 61 private: |
| 62 friend struct base::DefaultSingletonTraits<ScopedSurfaceRequestManager>; |
| 63 |
| 64 // Returns a 128 cryptographically secure token, encoded as a base64 string. |
| 65 std::string GetBase64UnguessableToken(); |
| 66 |
| 67 // Unregisters and returns the request identified by |request_token|. |
| 68 // Does not acquire |lock_|. |
| 69 ScopedSurfaceRequestCB GetAndUnregisterInternal(std::string request_token); |
| 70 |
| 71 // Map used to hold references to the registered callbacks. |
| 72 std::unordered_map<std::string, ScopedSurfaceRequestCB> request_callbacks_; |
| 73 |
| 74 ScopedSurfaceRequestManager(); |
| 75 ~ScopedSurfaceRequestManager() override; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ScopedSurfaceRequestManager); |
| 78 }; |
| 79 |
| 80 } // namespace content |
| 81 |
| 82 #endif // CONTENT_BROWSER_ANDROID_SCOPED_SURFACE_REQUEST_MANAGER_H_ |
OLD | NEW |