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

Side by Side Diff: content/renderer/media/webcontentdecryptionmodulesession_impl.cc

Issue 604283003: Refactor CdmPromise and related classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase + override Created 6 years, 2 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
« no previous file with comments | « content/renderer/media/webcontentdecryptionmodule_impl.cc ('k') | media/base/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h" 5 #include "content/renderer/media/webcontentdecryptionmodulesession_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/renderer/media/cdm_result_promise.h" 12 #include "content/renderer/media/cdm_result_promise.h"
13 #include "content/renderer/media/cdm_session_adapter.h" 13 #include "content/renderer/media/cdm_session_adapter.h"
14 #include "media/base/cdm_promise.h" 14 #include "media/base/cdm_promise.h"
15 #include "third_party/WebKit/public/platform/WebURL.h" 15 #include "third_party/WebKit/public/platform/WebURL.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 const char kCreateSessionUMAName[] = "CreateSession"; 19 const char kCreateSessionUMAName[] = "CreateSession";
20 20
21 typedef base::Callback<blink::WebContentDecryptionModuleResult::SessionStatus(
22 const std::string& web_session_id)> SessionInitializedCB;
23
24 class NewSessionCdmResultPromise : public CdmResultPromise<std::string> {
25 public:
26 NewSessionCdmResultPromise(blink::WebContentDecryptionModuleResult result,
27 std::string uma_name,
28 const SessionInitializedCB& new_session_created_cb)
29 : CdmResultPromise<std::string>(result, uma_name),
30 new_session_created_cb_(new_session_created_cb) {}
31
32 protected:
33 virtual void OnResolve(const std::string& web_session_id) OVERRIDE {
34 blink::WebContentDecryptionModuleResult::SessionStatus status =
35 new_session_created_cb_.Run(web_session_id);
36 web_cdm_result_.completeWithSession(status);
37 }
38
39 private:
40 SessionInitializedCB new_session_created_cb_;
41 };
42
43 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl( 21 WebContentDecryptionModuleSessionImpl::WebContentDecryptionModuleSessionImpl(
44 const scoped_refptr<CdmSessionAdapter>& adapter) 22 const scoped_refptr<CdmSessionAdapter>& adapter)
45 : adapter_(adapter), 23 : adapter_(adapter),
46 is_closed_(false), 24 is_closed_(false),
47 weak_ptr_factory_(this) { 25 weak_ptr_factory_(this) {
48 } 26 }
49 27
50 WebContentDecryptionModuleSessionImpl:: 28 WebContentDecryptionModuleSessionImpl::
51 ~WebContentDecryptionModuleSessionImpl() { 29 ~WebContentDecryptionModuleSessionImpl() {
52 if (!web_session_id_.empty()) 30 if (!web_session_id_.empty())
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized, 96 &WebContentDecryptionModuleSessionImpl::OnSessionInitialized,
119 base::Unretained(this))))); 97 base::Unretained(this)))));
120 } 98 }
121 99
122 void WebContentDecryptionModuleSessionImpl::update( 100 void WebContentDecryptionModuleSessionImpl::update(
123 const uint8* response, 101 const uint8* response,
124 size_t response_length, 102 size_t response_length,
125 blink::WebContentDecryptionModuleResult result) { 103 blink::WebContentDecryptionModuleResult result) {
126 DCHECK(response); 104 DCHECK(response);
127 DCHECK(!web_session_id_.empty()); 105 DCHECK(!web_session_id_.empty());
128 adapter_->UpdateSession( 106 adapter_->UpdateSession(web_session_id_,
129 web_session_id_, 107 response,
130 response, 108 response_length,
131 response_length, 109 scoped_ptr<media::SimpleCdmPromise>(
132 scoped_ptr<media::SimpleCdmPromise>(new SimpleCdmResultPromise(result))); 110 new CdmResultPromise<>(result, std::string())));
133 } 111 }
134 112
135 void WebContentDecryptionModuleSessionImpl::close( 113 void WebContentDecryptionModuleSessionImpl::close(
136 blink::WebContentDecryptionModuleResult result) { 114 blink::WebContentDecryptionModuleResult result) {
137 DCHECK(!web_session_id_.empty()); 115 DCHECK(!web_session_id_.empty());
138 adapter_->CloseSession( 116 adapter_->CloseSession(web_session_id_,
139 web_session_id_, 117 scoped_ptr<media::SimpleCdmPromise>(
140 scoped_ptr<media::SimpleCdmPromise>(new SimpleCdmResultPromise(result))); 118 new CdmResultPromise<>(result, std::string())));
141 } 119 }
142 120
143 void WebContentDecryptionModuleSessionImpl::remove( 121 void WebContentDecryptionModuleSessionImpl::remove(
144 blink::WebContentDecryptionModuleResult result) { 122 blink::WebContentDecryptionModuleResult result) {
145 DCHECK(!web_session_id_.empty()); 123 DCHECK(!web_session_id_.empty());
146 adapter_->RemoveSession( 124 adapter_->RemoveSession(web_session_id_,
147 web_session_id_, 125 scoped_ptr<media::SimpleCdmPromise>(
148 scoped_ptr<media::SimpleCdmPromise>(new SimpleCdmResultPromise(result))); 126 new CdmResultPromise<>(result, std::string())));
149 } 127 }
150 128
151 void WebContentDecryptionModuleSessionImpl::getUsableKeyIds( 129 void WebContentDecryptionModuleSessionImpl::getUsableKeyIds(
152 blink::WebContentDecryptionModuleResult result) { 130 blink::WebContentDecryptionModuleResult result) {
153 DCHECK(!web_session_id_.empty()); 131 DCHECK(!web_session_id_.empty());
154 adapter_->GetUsableKeyIds( 132 adapter_->GetUsableKeyIds(
155 web_session_id_, 133 web_session_id_,
156 scoped_ptr<media::KeyIdsPromise>( 134 scoped_ptr<media::KeyIdsPromise>(
157 new CdmResultPromise<media::KeyIdsVector>(result))); 135 new CdmResultPromise<media::KeyIdsVector>(result, std::string())));
158 } 136 }
159 137
160 void WebContentDecryptionModuleSessionImpl::release( 138 void WebContentDecryptionModuleSessionImpl::release(
161 blink::WebContentDecryptionModuleResult result) { 139 blink::WebContentDecryptionModuleResult result) {
162 close(result); 140 close(result);
163 } 141 }
164 142
165 void WebContentDecryptionModuleSessionImpl::OnSessionMessage( 143 void WebContentDecryptionModuleSessionImpl::OnSessionMessage(
166 const std::vector<uint8>& message, 144 const std::vector<uint8>& message,
167 const GURL& destination_url) { 145 const GURL& destination_url) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 199
222 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set."; 200 DCHECK(web_session_id_.empty()) << "Session ID may not be changed once set.";
223 web_session_id_ = web_session_id; 201 web_session_id_ = web_session_id;
224 return adapter_->RegisterSession(web_session_id_, 202 return adapter_->RegisterSession(web_session_id_,
225 weak_ptr_factory_.GetWeakPtr()) 203 weak_ptr_factory_.GetWeakPtr())
226 ? blink::WebContentDecryptionModuleResult::NewSession 204 ? blink::WebContentDecryptionModuleResult::NewSession
227 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists; 205 : blink::WebContentDecryptionModuleResult::SessionAlreadyExists;
228 } 206 }
229 207
230 } // namespace content 208 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webcontentdecryptionmodule_impl.cc ('k') | media/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698