Currently the cdm::FileIO interface [1] has a simple interface. When the CDM needs to determine if a file exists, it calls Open() followed by Read(). Read() returns 0 bytes if the file doesn't exist. The problem is that Open() doesn't know if the file is being opened for read or write. As a result it calls storage::AsyncFileUtil::CreateOrOpen() when opening the file (from [2]) with FLAG_OPEN_ALWAYS, which will create the file if it doesn't exist. If the CDM is simply checking to see if the file exists, this leaves an empty file around.
Possible solutions:
1) Change the cdm::FileIO interface to specify read/write options (and only create the file if writable).
2) Change the cdm::FileIO interface to allow Exists() (and maybe other things like Delete(), DirList()).
3) Delay actually opening the file until Read() or Write() is called.
4) When Close() is called, if the file has 0 bytes, delete it.
5) As writes are done through a temporary file, don't create the file if it doesn't exist and handle base::File errors for FILE_ERROR_NOT_FOUND.
Should also check that writing a file with no data does end up deleting the file as well.
[1] https://cs.chromium.org/chromium/src/media/cdm/api/content_decryption_module.h?l=627
[2] https://cs.chromium.org/chromium/src/content/browser/media/cdm_file_impl.cc?l=199