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

Side by Side Diff: media/cdm/ppapi/external_clear_key/clear_key_cdm.cc

Issue 2773283002: media: Simplify CdmHostFile(s) (Closed)
Patch Set: media: Simplify CdmHostFile(s) Created 3 years, 9 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 | « media/base/media_switches.cc ('k') | no next file » | 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 "media/cdm/ppapi/external_clear_key/clear_key_cdm.h" 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <sstream> 9 #include <sstream>
10 #include <utility> 10 #include <utility>
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 const char* GetCdmVersion() { 266 const char* GetCdmVersion() {
267 return kClearKeyCdmVersion; 267 return kClearKeyCdmVersion;
268 } 268 }
269 269
270 static bool g_verify_host_files_result = false; 270 static bool g_verify_host_files_result = false;
271 271
272 // Makes sure files and corresponding signature files are readable but not 272 // Makes sure files and corresponding signature files are readable but not
273 // writable. 273 // writable.
274 bool VerifyCdmHost_0(const cdm::HostFile* host_files, uint32_t num_files) { 274 bool VerifyCdmHost_0(const cdm::HostFile* host_files, uint32_t num_files) {
275 DVLOG(1) << __func__; 275 DVLOG(1) << __func__ << ": " << num_files;
276 276
277 // We should always have the CDM and CDM adapter. 277 // We should always have the CDM and CDM adapter and at lease one common file.
278 // We might not have any common CDM host file (e.g. chrome) since we are 278 // The common CDM host file (e.g. chrome) might not exist since we are running
279 // running in browser_tests. 279 // in browser_tests.
280 if (num_files < 2) { 280 if (num_files < 3) {
Haoming Chen 2017/03/31 16:46:53 nit: kNumRequiredHostFile or kMinimumNumHostFile?
xhwang 2017/03/31 18:05:37 Done.
281 LOG(ERROR) << "Too few host files: " << num_files; 281 LOG(ERROR) << "Too few host files: " << num_files;
282 g_verify_host_files_result = false; 282 g_verify_host_files_result = false;
283 return true; 283 return true;
284 } 284 }
285 285
286 int num_opened_files = 0;
286 for (uint32_t i = 0; i < num_files; ++i) { 287 for (uint32_t i = 0; i < num_files; ++i) {
287 const int kBytesToRead = 10; 288 const int kBytesToRead = 10;
288 std::vector<char> buffer(kBytesToRead); 289 std::vector<char> buffer(kBytesToRead);
289 290
290 base::File file(static_cast<base::PlatformFile>(host_files[i].file)); 291 base::File file(static_cast<base::PlatformFile>(host_files[i].file));
292 if (!file.IsValid())
293 continue;
294
295 num_opened_files++;
296
291 int bytes_read = file.Read(0, buffer.data(), buffer.size()); 297 int bytes_read = file.Read(0, buffer.data(), buffer.size());
292 if (bytes_read != kBytesToRead) { 298 if (bytes_read != kBytesToRead) {
293 LOG(ERROR) << "File bytes read: " << bytes_read; 299 LOG(ERROR) << "File bytes read: " << bytes_read;
294 g_verify_host_files_result = false; 300 g_verify_host_files_result = false;
295 return true; 301 return true;
296 } 302 }
297 303
298 // TODO(xhwang): Check that the files are not writable. 304 // TODO(xhwang): Check that the files are not writable.
299 // TODO(xhwang): Also verify the signature file when it's available. 305 // TODO(xhwang): Also verify the signature file when it's available.
300 } 306 }
301 307
308 // We should always have the CDM and CDM adapter opened.
309 if (num_opened_files < 2) {
Haoming Chen 2017/03/31 16:46:53 nit: kNumCdmFiles?
xhwang 2017/03/31 18:05:37 Done.
310 LOG(ERROR) << "Too few opened files: " << num_opened_files;
311 g_verify_host_files_result = false;
312 return true;
313 }
314
302 g_verify_host_files_result = true; 315 g_verify_host_files_result = true;
303 return true; 316 return true;
304 } 317 }
305 318
306 namespace media { 319 namespace media {
307 320
308 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, 321 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host,
309 const std::string& key_system, 322 const std::string& key_system,
310 const GURL& origin) 323 const GURL& origin)
311 : decryptor_(new AesDecryptor( 324 : decryptor_(new AesDecryptor(
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 challenge.data(), challenge.size()); 1060 challenge.data(), challenge.size());
1048 } 1061 }
1049 1062
1050 void ClearKeyCdm::VerifyCdmHostTest() { 1063 void ClearKeyCdm::VerifyCdmHostTest() {
1051 // VerifyCdmHost() should have already been called and test result stored 1064 // VerifyCdmHost() should have already been called and test result stored
1052 // in |g_verify_host_files_result|. 1065 // in |g_verify_host_files_result|.
1053 OnUnitTestComplete(g_verify_host_files_result); 1066 OnUnitTestComplete(g_verify_host_files_result);
1054 } 1067 }
1055 1068
1056 } // namespace media 1069 } // namespace media
OLDNEW
« no previous file with comments | « media/base/media_switches.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698