blob: 5ac0abd79b40ef3d0edac3bb48ff8e9dd38be857 [file] [log] [blame]
Malay Keshav218c3922018-08-31 01:01:481// 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
15namespace base {
16class FilePath;
17class SequencedTaskRunner;
18} // namespace base
19
20namespace 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
25class VideoSource : public content::URLDataSource {
26 public:
27 VideoSource();
28 ~VideoSource() override;
29
30 // content::URLDataSource:
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:0431 std::string GetSource() override;
danakjf4b9e942019-11-29 15:43:0432 void StartDataRequest(
33 const GURL& url,
34 const content::WebContents::Getter& wc_getter,
35 content::URLDataSource::GotDataCallback got_data_callback) override;
Lucas Furukawa Gadani4b4eed02019-06-04 23:12:0436 std::string GetMimeType(const std::string& path) override;
Malay Keshav218c3922018-08-31 01:01:4837
38 private:
39 // Continuation from StartDataRequest().
40 void StartDataRequestAfterPathExists(
41 const base::FilePath& video_path,
danakjf4b9e942019-11-29 15:43:0442 content::URLDataSource::GotDataCallback got_data_callback,
Malay Keshav218c3922018-08-31 01:01:4843 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 Roman47d432e2019-08-20 14:24:0048 base::WeakPtrFactory<VideoSource> weak_factory_{this};
Malay Keshav218c3922018-08-31 01:01:4849
50 DISALLOW_COPY_AND_ASSIGN(VideoSource);
51};
52
53} // namespace chromeos
54
55#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_VIDEO_SOURCE_H_