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

Side by Side Diff: media/cdm/ppapi/cdm_file_io_impl.cc

Issue 568623003: CdmAdapter: Report size of the file read by CDM via FileIO. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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/cdm_file_io_impl.h" 5 #include "media/cdm/ppapi/cdm_file_io_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <sstream> 8 #include <sstream>
9 9
10 #include "media/cdm/ppapi/cdm_logging.h" 10 #include "media/cdm/ppapi/cdm_logging.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 CdmFileIOImpl::ResourceTracker::ResourceTracker() { 50 CdmFileIOImpl::ResourceTracker::ResourceTracker() {
51 // Do nothing here since we lazy-initialize CdmFileIOImpl::file_lock_map_ 51 // Do nothing here since we lazy-initialize CdmFileIOImpl::file_lock_map_
52 // in CdmFileIOImpl::AcquireFileLock(). 52 // in CdmFileIOImpl::AcquireFileLock().
53 } 53 }
54 54
55 CdmFileIOImpl::ResourceTracker::~ResourceTracker() { 55 CdmFileIOImpl::ResourceTracker::~ResourceTracker() {
56 delete CdmFileIOImpl::file_lock_map_; 56 delete CdmFileIOImpl::file_lock_map_;
57 } 57 }
58 58
59 CdmFileIOImpl::CdmFileIOImpl(cdm::FileIOClient* client, PP_Instance pp_instance) 59 CdmFileIOImpl::CdmFileIOImpl(
60 cdm::FileIOClient* client,
61 PP_Instance pp_instance,
62 const pp::CompletionCallback& file_read_cb)
60 : state_(FILE_UNOPENED), 63 : state_(FILE_UNOPENED),
61 client_(client), 64 client_(client),
62 pp_instance_handle_(pp_instance), 65 pp_instance_handle_(pp_instance),
63 callback_factory_(this), 66 callback_factory_(this),
64 io_offset_(0) { 67 io_offset_(0),
68 file_read_cb_(file_read_cb) {
65 PP_DCHECK(IsMainThread()); 69 PP_DCHECK(IsMainThread());
66 PP_DCHECK(pp_instance); // 0 indicates a "NULL handle". 70 PP_DCHECK(pp_instance); // 0 indicates a "NULL handle".
67 } 71 }
68 72
69 CdmFileIOImpl::~CdmFileIOImpl() { 73 CdmFileIOImpl::~CdmFileIOImpl() {
70 PP_DCHECK(state_ == FILE_CLOSED); 74 PP_DCHECK(state_ == FILE_CLOSED);
71 } 75 }
72 76
73 // Call sequence: Open() -> OpenFileSystem() -> OpenFile() -> FILE_OPENED. 77 // Call sequence: Open() -> OpenFileSystem() -> OpenFile() -> FILE_OPENED.
74 void CdmFileIOImpl::Open(const char* file_name, uint32_t file_name_size) { 78 void CdmFileIOImpl::Open(const char* file_name, uint32_t file_name_size) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 io_buffer_.clear(); 335 io_buffer_.clear();
332 io_offset_ = 0; 336 io_offset_ = 0;
333 // Clear |cumulative_read_buffer_| in case OnReadComplete() calls Read() or 337 // Clear |cumulative_read_buffer_| in case OnReadComplete() calls Read() or
334 // Write(). 338 // Write().
335 std::vector<char> local_buffer; 339 std::vector<char> local_buffer;
336 std::swap(cumulative_read_buffer_, local_buffer); 340 std::swap(cumulative_read_buffer_, local_buffer);
337 341
338 state_ = FILE_OPENED; 342 state_ = FILE_OPENED;
339 const uint8_t* data = local_buffer.empty() ? 343 const uint8_t* data = local_buffer.empty() ?
340 NULL : reinterpret_cast<const uint8_t*>(&local_buffer[0]); 344 NULL : reinterpret_cast<const uint8_t*>(&local_buffer[0]);
345
346 // Call this before OnReadComplete() so that we always have the latest file
347 // size before CDM fires errors.
348 file_read_cb_.Run(local_buffer.size());
349
341 client_->OnReadComplete( 350 client_->OnReadComplete(
342 cdm::FileIOClient::kSuccess, data, local_buffer.size()); 351 cdm::FileIOClient::kSuccess, data, local_buffer.size());
343 } 352 }
344 353
345 void CdmFileIOImpl::SetLength(uint32_t length) { 354 void CdmFileIOImpl::SetLength(uint32_t length) {
346 PP_DCHECK(state_ == WRITING_FILE); 355 PP_DCHECK(state_ == WRITING_FILE);
347 356
348 pp::CompletionCallback cb = 357 pp::CompletionCallback cb =
349 callback_factory_.NewCallback(&CdmFileIOImpl::OnLengthSet); 358 callback_factory_.NewCallback(&CdmFileIOImpl::OnLengthSet);
350 CHECK_PP_OK_COMPLETIONPENDING(file_io_.SetLength(length, cb), WRITE_ERROR); 359 CHECK_PP_OK_COMPLETIONPENDING(file_io_.SetLength(length, cb), WRITE_ERROR);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 467
459 void CdmFileIOImpl::ReportClosingStateUMA(State state) { 468 void CdmFileIOImpl::ReportClosingStateUMA(State state) {
460 #if defined(OS_CHROMEOS) 469 #if defined(OS_CHROMEOS)
461 pp::UMAPrivate uma_interface(pp_instance_handle_); 470 pp::UMAPrivate uma_interface(pp_instance_handle_);
462 uma_interface.HistogramEnumeration( 471 uma_interface.HistogramEnumeration(
463 "Media.EME.CdmFileIO.ClosingState", state, STATE_MAX); 472 "Media.EME.CdmFileIO.ClosingState", state, STATE_MAX);
464 #endif 473 #endif
465 } 474 }
466 475
467 } // namespace media 476 } // namespace media
OLDNEW
« media/cdm/ppapi/cdm_file_io_impl.h ('K') | « media/cdm/ppapi/cdm_file_io_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698