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

Side by Side Diff: content/browser/android/scoped_surface_request_manager.cc

Issue 2285593002: Add ScopedSurfaceRequestManager (Closed)
Patch Set: Update to UnguessableToken. Addressed comments. Created 4 years, 3 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
(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 #include "content/browser/android/scoped_surface_request_manager.h"
6
7 #include "content/public/browser/browser_thread.h"
8
9 namespace content {
10
11 // static
12 ScopedSurfaceRequestManager* ScopedSurfaceRequestManager::GetInstance() {
13 return base::Singleton<
14 ScopedSurfaceRequestManager,
15 base::LeakySingletonTraits<ScopedSurfaceRequestManager>>::get();
16 }
17
18 base::UnguessableToken
19 ScopedSurfaceRequestManager::RegisterScopedSurfaceRequest(
20 ScopedSurfaceRequestCB request_cb) {
21 DCHECK_CURRENTLY_ON(BrowserThread::UI);
22 DCHECK(!request_cb.is_null());
23
24 base::UnguessableToken request_token = base::UnguessableToken::Create();
25
26 DCHECK(!request_callbacks_.count(request_token));
27 request_callbacks_.insert(std::make_pair(request_token, request_cb));
28
29 return request_token;
30 }
31
32 void ScopedSurfaceRequestManager::UnregisterScopedSurfaceRequest(
33 const base::UnguessableToken& request_token) {
34 DCHECK_CURRENTLY_ON(BrowserThread::UI);
35 GetAndUnregisterInternal(request_token);
36 }
37
38 ScopedSurfaceRequestManager::ScopedSurfaceRequestCB
39 ScopedSurfaceRequestManager::GetAndUnregisterInternal(
40 const base::UnguessableToken& request_token) {
41 DCHECK_CURRENTLY_ON(BrowserThread::UI);
42 DCHECK(!request_token.is_empty());
43
44 ScopedSurfaceRequestManager::ScopedSurfaceRequestCB request;
45
46 auto it = request_callbacks_.find(request_token);
47 if (it != request_callbacks_.end()) {
48 request = it->second;
49 request_callbacks_.erase(it);
50 }
51
52 return request;
53 }
54
55 void ScopedSurfaceRequestManager::ForwardSurfaceTextureForSurfaceRequest(
56 const base::UnguessableToken& request_token,
57 const gl::SurfaceTexture* surface_texture) {
58 FulfillScopedSurfaceRequest(request_token,
59 gl::ScopedJavaSurface(surface_texture));
60 }
61
62 void ScopedSurfaceRequestManager::FulfillScopedSurfaceRequest(
63 const base::UnguessableToken& request_token,
64 gl::ScopedJavaSurface surface) {
65 // base::Unretained is safe because the lifetime of this object is tied to
66 // the lifetime of the browser process.
67 BrowserThread::PostTask(
68 BrowserThread::UI, FROM_HERE,
69 base::Bind(&ScopedSurfaceRequestManager::CompleteRequestOnUiThread,
70 base::Unretained(this), request_token,
71 base::Passed(std::move(surface))));
dcheng 2016/09/20 06:50:35 base::Passed(&surface) is shorthand for this.
tguilbert 2016/09/20 20:59:19 TIL TY!
72 }
73
74 void ScopedSurfaceRequestManager::CompleteRequestOnUiThread(
tguilbert 2016/09/20 03:08:40 Style question because I didn't find any official
dcheng 2016/09/20 06:50:35 The consensus is that the style guide states this
tguilbert 2016/09/20 20:59:19 Ok, thanks.
75 const base::UnguessableToken& request_token,
76 gl::ScopedJavaSurface surface) {
77 DCHECK_CURRENTLY_ON(BrowserThread::UI);
78
79 ScopedSurfaceRequestManager::ScopedSurfaceRequestCB request =
80 GetAndUnregisterInternal(request_token);
81
82 if (!request.is_null())
83 request.Run(std::move(surface));
84 }
85
86 ScopedSurfaceRequestManager::ScopedSurfaceRequestManager() {}
87
88 ScopedSurfaceRequestManager::~ScopedSurfaceRequestManager() {}
89
90 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698