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

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: comments addressed 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
« no previous file with comments | « media/cdm/ppapi/cdm_file_io_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('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 "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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 CdmFileIOImpl::ResourceTracker::ResourceTracker() { 49 CdmFileIOImpl::ResourceTracker::ResourceTracker() {
50 // Do nothing here since we lazy-initialize CdmFileIOImpl::file_lock_map_ 50 // Do nothing here since we lazy-initialize CdmFileIOImpl::file_lock_map_
51 // in CdmFileIOImpl::AcquireFileLock(). 51 // in CdmFileIOImpl::AcquireFileLock().
52 } 52 }
53 53
54 CdmFileIOImpl::ResourceTracker::~ResourceTracker() { 54 CdmFileIOImpl::ResourceTracker::~ResourceTracker() {
55 delete CdmFileIOImpl::file_lock_map_; 55 delete CdmFileIOImpl::file_lock_map_;
56 } 56 }
57 57
58 CdmFileIOImpl::CdmFileIOImpl(cdm::FileIOClient* client, PP_Instance pp_instance) 58 CdmFileIOImpl::CdmFileIOImpl(
59 cdm::FileIOClient* client,
60 PP_Instance pp_instance,
61 const pp::CompletionCallback& first_file_read_cb)
59 : state_(FILE_UNOPENED), 62 : state_(FILE_UNOPENED),
60 client_(client), 63 client_(client),
61 pp_instance_handle_(pp_instance), 64 pp_instance_handle_(pp_instance),
62 callback_factory_(this), 65 callback_factory_(this),
63 io_offset_(0) { 66 io_offset_(0),
67 first_file_read_reported_(false),
68 first_file_read_cb_(first_file_read_cb) {
64 PP_DCHECK(IsMainThread()); 69 PP_DCHECK(IsMainThread());
65 PP_DCHECK(pp_instance); // 0 indicates a "NULL handle". 70 PP_DCHECK(pp_instance); // 0 indicates a "NULL handle".
66 } 71 }
67 72
68 CdmFileIOImpl::~CdmFileIOImpl() { 73 CdmFileIOImpl::~CdmFileIOImpl() {
69 PP_DCHECK(state_ == FILE_CLOSED); 74 PP_DCHECK(state_ == FILE_CLOSED);
70 } 75 }
71 76
72 // Call sequence: Open() -> OpenFileSystem() -> OpenFile() -> FILE_OPENED. 77 // Call sequence: Open() -> OpenFileSystem() -> OpenFile() -> FILE_OPENED.
73 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 io_buffer_.clear(); 334 io_buffer_.clear();
330 io_offset_ = 0; 335 io_offset_ = 0;
331 // Clear |cumulative_read_buffer_| in case OnReadComplete() calls Read() or 336 // Clear |cumulative_read_buffer_| in case OnReadComplete() calls Read() or
332 // Write(). 337 // Write().
333 std::vector<char> local_buffer; 338 std::vector<char> local_buffer;
334 std::swap(cumulative_read_buffer_, local_buffer); 339 std::swap(cumulative_read_buffer_, local_buffer);
335 340
336 state_ = FILE_OPENED; 341 state_ = FILE_OPENED;
337 const uint8_t* data = local_buffer.empty() ? 342 const uint8_t* data = local_buffer.empty() ?
338 NULL : reinterpret_cast<const uint8_t*>(&local_buffer[0]); 343 NULL : reinterpret_cast<const uint8_t*>(&local_buffer[0]);
344
345 // Call this before OnReadComplete() so that we always have the latest file
346 // size before CDM fires errors.
347 if (!first_file_read_reported_) {
348 first_file_read_cb_.Run(local_buffer.size());
349 first_file_read_reported_ = true;
350 }
351
339 client_->OnReadComplete( 352 client_->OnReadComplete(
340 cdm::FileIOClient::kSuccess, data, local_buffer.size()); 353 cdm::FileIOClient::kSuccess, data, local_buffer.size());
341 } 354 }
342 355
343 void CdmFileIOImpl::SetLength(uint32_t length) { 356 void CdmFileIOImpl::SetLength(uint32_t length) {
344 PP_DCHECK(state_ == WRITING_FILE); 357 PP_DCHECK(state_ == WRITING_FILE);
345 358
346 pp::CompletionCallback cb = 359 pp::CompletionCallback cb =
347 callback_factory_.NewCallback(&CdmFileIOImpl::OnLengthSet); 360 callback_factory_.NewCallback(&CdmFileIOImpl::OnLengthSet);
348 CHECK_PP_OK_COMPLETIONPENDING(file_io_.SetLength(length, cb), WRITE_ERROR); 361 CHECK_PP_OK_COMPLETIONPENDING(file_io_.SetLength(length, cb), WRITE_ERROR);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 case READ_WHILE_IN_USE: 461 case READ_WHILE_IN_USE:
449 client_->OnReadComplete(cdm::FileIOClient::kInUse, NULL, 0); 462 client_->OnReadComplete(cdm::FileIOClient::kInUse, NULL, 0);
450 break; 463 break;
451 case WRITE_WHILE_IN_USE: 464 case WRITE_WHILE_IN_USE:
452 client_->OnWriteComplete(cdm::FileIOClient::kInUse); 465 client_->OnWriteComplete(cdm::FileIOClient::kInUse);
453 break; 466 break;
454 } 467 }
455 } 468 }
456 469
457 } // namespace media 470 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/ppapi/cdm_file_io_impl.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698