Make it harder to leak temp files on devices

This extracts the device temp file creation deletion into a context
manager. This context manager will delete the temporary file when
leaving the with: scope.

Also changes logic for finding a temp file from a linear search from 0
to just using a random number (still checking that the file doesn't
exist). Both of these approaches could return the same file in
consecutive calls if the earlier files aren't written to (though it is
nearly impossible with the random number approach instead of essentially
guaranteed).

Removed the temp file name patterns and just added a prefix+suffix
argument to DeviceTempFile (like tempfile.NamedTemporaryFile).

BUG=371054

Review URL: https://codereview.chromium.org/276813002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270917 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 9eaaa4a671c891fd6fa20fb7aac7249d28a72eb8
2 files changed
tree: 37219614b606e2755eeb2f081fb4c2ad8b2baa75
  1. base/
  2. build/
  3. components/
  4. dbus/
  5. device/
  6. ipc/
  7. mojo/
  8. testing/
  9. third_party/
  10. ui/