Malay Keshav | 218c392 | 2018-08-31 01:01:48 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_VIDEO_SOURCE_H_ |
| 6 | #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_VIDEO_SOURCE_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/macros.h" |
| 11 | #include "base/memory/scoped_refptr.h" |
| 12 | #include "base/memory/weak_ptr.h" |
| 13 | #include "content/public/browser/url_data_source.h" |
| 14 | |
| 15 | namespace base { |
| 16 | class FilePath; |
| 17 | class SequencedTaskRunner; |
| 18 | } // namespace base |
| 19 | |
| 20 | namespace chromeos { |
| 21 | |
| 22 | // Data source that reads videos from the file system. |
| 23 | // It provides resources from chrome urls of type: |
| 24 | // chrome://chromeos-asset/<whitelisted directories>/*.webm |
| 25 | class VideoSource : public content::URLDataSource { |
| 26 | public: |
| 27 | VideoSource(); |
| 28 | ~VideoSource() override; |
| 29 | |
| 30 | // content::URLDataSource: |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 31 | std::string GetSource() override; |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 32 | void StartDataRequest( |
| 33 | const GURL& url, |
| 34 | const content::WebContents::Getter& wc_getter, |
| 35 | content::URLDataSource::GotDataCallback got_data_callback) override; |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 36 | std::string GetMimeType(const std::string& path) override; |
Malay Keshav | 218c392 | 2018-08-31 01:01:48 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | // Continuation from StartDataRequest(). |
| 40 | void StartDataRequestAfterPathExists( |
| 41 | const base::FilePath& video_path, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 42 | content::URLDataSource::GotDataCallback got_data_callback, |
Malay Keshav | 218c392 | 2018-08-31 01:01:48 | [diff] [blame] | 43 | bool path_exists); |
| 44 | |
| 45 | // The background task runner on which file I/O is performed. |
| 46 | scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 47 | |
Jeremy Roman | 47d432e | 2019-08-20 14:24:00 | [diff] [blame] | 48 | base::WeakPtrFactory<VideoSource> weak_factory_{this}; |
Malay Keshav | 218c392 | 2018-08-31 01:01:48 | [diff] [blame] | 49 | |
| 50 | DISALLOW_COPY_AND_ASSIGN(VideoSource); |
| 51 | }; |
| 52 | |
| 53 | } // namespace chromeos |
| 54 | |
| 55 | #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_VIDEO_SOURCE_H_ |