Implement a URLDataSource to load videos from disk for OOBE
This patch implements a URLDataSource that loads oobe video assets from
disk based on the provided chrome URL. It also installs the same for
the oobe web ui.
Bug: 878594
Change-Id: I443144d4e5ab65d313c0e56d8b988a9cb05e6109
Component: Video source, oobe
Reviewed-on: https://chromium-review.googlesource.com/1196145
Reviewed-by: Michael Giuffrida <[email protected]>
Commit-Queue: Malay Keshav <[email protected]>
Cr-Commit-Position: refs/heads/master@{#587889}
diff --git a/chrome/browser/ui/webui/chromeos/video_source.h b/chrome/browser/ui/webui/chromeos/video_source.h
new file mode 100644
index 0000000..12a1a88
--- /dev/null
+++ b/chrome/browser/ui/webui/chromeos/video_source.h
@@ -0,0 +1,56 @@
+// Copyright 2018 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_VIDEO_SOURCE_H_
+#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_VIDEO_SOURCE_H_
+
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/scoped_refptr.h"
+#include "base/memory/weak_ptr.h"
+#include "content/public/browser/url_data_source.h"
+
+namespace base {
+class FilePath;
+class SequencedTaskRunner;
+} // namespace base
+
+namespace chromeos {
+
+// Data source that reads videos from the file system.
+// It provides resources from chrome urls of type:
+// chrome://chromeos-asset/<whitelisted directories>/*.webm
+class VideoSource : public content::URLDataSource {
+ public:
+ VideoSource();
+ ~VideoSource() override;
+
+ // content::URLDataSource:
+ std::string GetSource() const override;
+ void StartDataRequest(
+ const std::string& path,
+ const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
+ const content::URLDataSource::GotDataCallback& got_data_callback)
+ override;
+ std::string GetMimeType(const std::string& path) const override;
+
+ private:
+ // Continuation from StartDataRequest().
+ void StartDataRequestAfterPathExists(
+ const base::FilePath& video_path,
+ const content::URLDataSource::GotDataCallback& got_data_callback,
+ bool path_exists);
+
+ // The background task runner on which file I/O is performed.
+ scoped_refptr<base::SequencedTaskRunner> task_runner_;
+
+ base::WeakPtrFactory<VideoSource> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(VideoSource);
+};
+
+} // namespace chromeos
+
+#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_VIDEO_SOURCE_H_