| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | |
| 9 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 10 #include "base/macros.h" | 9 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/ref_counted.h" |
| 12 #include "chrome/common/extensions/media_parser.mojom.h" | 11 #include "chrome/common/extensions/media_parser.mojom.h" |
| 13 #include "content/public/browser/utility_process_host_client.h" | 12 #include "content/public/browser/utility_process_mojo_client.h" |
| 14 #include "storage/browser/fileapi/copy_or_move_file_validator.h" | 13 #include "storage/browser/fileapi/copy_or_move_file_validator.h" |
| 15 | 14 |
| 16 namespace content { | |
| 17 class UtilityProcessHost; | |
| 18 } | |
| 19 | |
| 20 // Uses a utility process to validate a media file. If the callback returns | 15 // Uses a utility process to validate a media file. If the callback returns |
| 21 // File::FILE_OK, then the file appears to be a valid media file. This does | 16 // File::FILE_OK, then file appears to be valid. File validation does not |
| 22 // not attempt to decode the entire file, which may take a considerable amount | 17 // attempt to decode the entire file since that could take a considerable |
| 23 // of time. This class may be constructed on any thread, but should run on the | 18 // amount of time. This class can be constructed on any thread, but should |
| 24 // IO thread. | 19 // run on the IO thread. |
| 25 class SafeAudioVideoChecker : public content::UtilityProcessHostClient { | 20 class SafeAudioVideoChecker |
| 21 : public base::RefCountedThreadSafe<SafeAudioVideoChecker> { |
| 26 public: | 22 public: |
| 27 // Takes responsibility for closing |file|. | 23 // Takes responsibility for closing |file|. |
| 28 SafeAudioVideoChecker( | 24 SafeAudioVideoChecker( |
| 29 base::File file, | 25 base::File file, |
| 30 const storage::CopyOrMoveFileValidator::ResultCallback& callback); | 26 const storage::CopyOrMoveFileValidator::ResultCallback& callback); |
| 31 | 27 |
| 32 // Must be called on the IO thread. | 28 // Check the file: must be called on the IO thread. |
| 33 void Start(); | 29 void Start(); |
| 34 | 30 |
| 35 private: | 31 private: |
| 36 enum State { | 32 friend class base::RefCountedThreadSafe<SafeAudioVideoChecker>; |
| 37 INITIAL_STATE, | |
| 38 STARTED_STATE, | |
| 39 FINISHED_STATE | |
| 40 }; | |
| 41 | 33 |
| 42 ~SafeAudioVideoChecker() override; | 34 ~SafeAudioVideoChecker(); |
| 43 | 35 |
| 44 // Notification of the result from the utility process. | 36 // Media file check result. |
| 45 void OnCheckingFinished(bool valid); | 37 void CheckMediaFileDone(bool valid); |
| 46 | 38 |
| 47 // UtilityProcessHostClient implementation. | 39 // Media file to check. |
| 48 void OnProcessCrashed(int exit_code) override; | |
| 49 bool OnMessageReceived(const IPC::Message& message) override; | |
| 50 | |
| 51 State state_; | |
| 52 | |
| 53 base::File file_; | 40 base::File file_; |
| 54 | 41 |
| 42 // Utility process used to check |file_|. |
| 43 std::unique_ptr< |
| 44 content::UtilityProcessMojoClient<extensions::mojom::MediaParser>> |
| 45 utility_process_mojo_client_; |
| 46 |
| 47 // Report the check result to |callback_|. |
| 55 const storage::CopyOrMoveFileValidator::ResultCallback callback_; | 48 const storage::CopyOrMoveFileValidator::ResultCallback callback_; |
| 56 | 49 |
| 57 base::WeakPtr<content::UtilityProcessHost> utility_process_host_; | |
| 58 | |
| 59 extensions::mojom::MediaParserPtr interface_; | |
| 60 | |
| 61 DISALLOW_COPY_AND_ASSIGN(SafeAudioVideoChecker); | 50 DISALLOW_COPY_AND_ASSIGN(SafeAudioVideoChecker); |
| 62 }; | 51 }; |
| 63 | 52 |
| 64 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ | 53 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_SAFE_AUDIO_VIDEO_CHECKER_H_ |
| OLD | NEW |