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

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

Issue 2773283002: media: Simplify CdmHostFile(s) (Closed)
Patch Set: comments addressed Created 3 years, 8 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
277 // We should always have the CDM and CDM adapter and at lease one common file.
278 // The common CDM host file (e.g. chrome) might not exist since we are running
279 // in browser_tests.
280 const uint32_t kMinNumHostFiles = 3;
276 281
277 // We should always have the CDM and CDM adapter. 282 // We should always have the CDM and CDM adapter.
278 // We might not have any common CDM host file (e.g. chrome) since we are 283 const int kNumCdmFiles = 2;
279 // running in browser_tests. 284
280 if (num_files < 2) { 285 if (num_files < kMinNumHostFiles) {
281 LOG(ERROR) << "Too few host files: " << num_files; 286 LOG(ERROR) << "Too few host files: " << num_files;
282 g_verify_host_files_result = false; 287 g_verify_host_files_result = false;
283 return true; 288 return true;
284 } 289 }
285 290
291 int num_opened_files = 0;
286 for (uint32_t i = 0; i < num_files; ++i) { 292 for (uint32_t i = 0; i < num_files; ++i) {
287 const int kBytesToRead = 10; 293 const int kBytesToRead = 10;
288 std::vector<char> buffer(kBytesToRead); 294 std::vector<char> buffer(kBytesToRead);
289 295
290 base::File file(static_cast<base::PlatformFile>(host_files[i].file)); 296 base::File file(static_cast<base::PlatformFile>(host_files[i].file));
297 if (!file.IsValid())
298 continue;
299
300 num_opened_files++;
301
291 int bytes_read = file.Read(0, buffer.data(), buffer.size()); 302 int bytes_read = file.Read(0, buffer.data(), buffer.size());
292 if (bytes_read != kBytesToRead) { 303 if (bytes_read != kBytesToRead) {
293 LOG(ERROR) << "File bytes read: " << bytes_read; 304 LOG(ERROR) << "File bytes read: " << bytes_read;
294 g_verify_host_files_result = false; 305 g_verify_host_files_result = false;
295 return true; 306 return true;
296 } 307 }
297 308
298 // TODO(xhwang): Check that the files are not writable. 309 // TODO(xhwang): Check that the files are not writable.
299 // TODO(xhwang): Also verify the signature file when it's available. 310 // TODO(xhwang): Also verify the signature file when it's available.
300 } 311 }
301 312
313 // We should always have CDM files opened.
314 if (num_opened_files < kNumCdmFiles) {
315 LOG(ERROR) << "Too few opened files: " << num_opened_files;
316 g_verify_host_files_result = false;
317 return true;
318 }
319
302 g_verify_host_files_result = true; 320 g_verify_host_files_result = true;
303 return true; 321 return true;
304 } 322 }
305 323
306 namespace media { 324 namespace media {
307 325
308 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host, 326 ClearKeyCdm::ClearKeyCdm(ClearKeyCdmHost* host,
309 const std::string& key_system, 327 const std::string& key_system,
310 const GURL& origin) 328 const GURL& origin)
311 : decryptor_(new AesDecryptor( 329 : decryptor_(new AesDecryptor(
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 challenge.data(), challenge.size()); 1065 challenge.data(), challenge.size());
1048 } 1066 }
1049 1067
1050 void ClearKeyCdm::VerifyCdmHostTest() { 1068 void ClearKeyCdm::VerifyCdmHostTest() {
1051 // VerifyCdmHost() should have already been called and test result stored 1069 // VerifyCdmHost() should have already been called and test result stored
1052 // in |g_verify_host_files_result|. 1070 // in |g_verify_host_files_result|.
1053 OnUnitTestComplete(g_verify_host_files_result); 1071 OnUnitTestComplete(g_verify_host_files_result);
1054 } 1072 }
1055 1073
1056 } // namespace media 1074 } // 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