Commit 6df2d002 authored by Min Qin's avatar Min Qin Committed by Commit Bot

switch to TaskScheduler API and BindOnce for MediaResourceGetter.

This CL switches MediaResourceGetter to use TaskScheduler and BindOnce.

BUG=689520

Change-Id: Icbc98cb32de3a3e7b2a91e2692446747794f62eb
Reviewed-on: https://chromium-review.googlesource.com/559993Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#484970}
parent 047f5682
...@@ -43,34 +43,32 @@ class MediaResourceGetterImpl : public media::MediaResourceGetter { ...@@ -43,34 +43,32 @@ class MediaResourceGetterImpl : public media::MediaResourceGetter {
// media::MediaResourceGetter implementation. // media::MediaResourceGetter implementation.
// Must be called on the UI thread. // Must be called on the UI thread.
void GetAuthCredentials(const GURL& url, void GetAuthCredentials(const GURL& url,
const GetAuthCredentialsCB& callback) override; GetAuthCredentialsCB callback) override;
void GetCookies(const GURL& url, void GetCookies(const GURL& url,
const GURL& first_party_for_cookies, const GURL& first_party_for_cookies,
const GetCookieCB& callback) override; GetCookieCB callback) override;
void GetPlatformPathFromURL(const GURL& url, void GetPlatformPathFromURL(const GURL& url,
const GetPlatformPathCB& callback) override; GetPlatformPathCB callback) override;
void ExtractMediaMetadata(const std::string& url, void ExtractMediaMetadata(const std::string& url,
const std::string& cookies, const std::string& cookies,
const std::string& user_agent, const std::string& user_agent,
const ExtractMediaMetadataCB& callback) override; ExtractMediaMetadataCB callback) override;
void ExtractMediaMetadata(const int fd, void ExtractMediaMetadata(const int fd,
const int64_t offset, const int64_t offset,
const int64_t size, const int64_t size,
const ExtractMediaMetadataCB& callback) override; ExtractMediaMetadataCB callback) override;
private: private:
// Called when GetAuthCredentials() finishes. // Called when GetAuthCredentials() finishes.
void GetAuthCredentialsCallback( void GetAuthCredentialsCallback(GetAuthCredentialsCB callback,
const GetAuthCredentialsCB& callback, const net::AuthCredentials& credentials);
const net::AuthCredentials& credentials);
// Called when GetCookies() finishes. // Called when GetCookies() finishes.
void GetCookiesCallback( void GetCookiesCallback(GetCookieCB callback, const std::string& cookies);
const GetCookieCB& callback, const std::string& cookies);
// Called when GetPlatformPathFromFileSystemURL() finishes. // Called when GetPlatformPathFromFileSystemURL() finishes.
void GetPlatformPathCallback( void GetPlatformPathCallback(GetPlatformPathCB callback,
const GetPlatformPathCB& callback, const std::string& platform_path); const std::string& platform_path);
// BrowserContext to retrieve URLRequestContext and ResourceContext. // BrowserContext to retrieve URLRequestContext and ResourceContext.
BrowserContext* browser_context_; BrowserContext* browser_context_;
......
...@@ -85,6 +85,11 @@ MediaPlayerBridge::~MediaPlayerBridge() { ...@@ -85,6 +85,11 @@ MediaPlayerBridge::~MediaPlayerBridge() {
void MediaPlayerBridge::Initialize() { void MediaPlayerBridge::Initialize() {
cookies_.clear(); cookies_.clear();
if (url_.SchemeIsBlob()) {
NOTREACHED();
return;
}
if (url_.SchemeIsFile() || url_.SchemeIs("data")) { if (url_.SchemeIsFile() || url_.SchemeIs("data")) {
ExtractMediaMetadata(url_.spec()); ExtractMediaMetadata(url_.spec());
return; return;
...@@ -92,11 +97,10 @@ void MediaPlayerBridge::Initialize() { ...@@ -92,11 +97,10 @@ void MediaPlayerBridge::Initialize() {
media::MediaResourceGetter* resource_getter = media::MediaResourceGetter* resource_getter =
manager()->GetMediaResourceGetter(); manager()->GetMediaResourceGetter();
if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) { if (url_.SchemeIsFileSystem()) {
resource_getter->GetPlatformPathFromURL( resource_getter->GetPlatformPathFromURL(
url_, url_, base::BindOnce(&MediaPlayerBridge::ExtractMediaMetadata,
base::Bind(&MediaPlayerBridge::ExtractMediaMetadata, weak_factory_.GetWeakPtr()));
weak_factory_.GetWeakPtr()));
return; return;
} }
...@@ -144,12 +148,18 @@ void MediaPlayerBridge::SetVideoSurface(gl::ScopedJavaSurface surface) { ...@@ -144,12 +148,18 @@ void MediaPlayerBridge::SetVideoSurface(gl::ScopedJavaSurface surface) {
void MediaPlayerBridge::Prepare() { void MediaPlayerBridge::Prepare() {
DCHECK(j_media_player_bridge_.is_null()); DCHECK(j_media_player_bridge_.is_null());
if (url_.SchemeIsBlob()) {
NOTREACHED();
return;
}
CreateJavaMediaPlayerBridge(); CreateJavaMediaPlayerBridge();
if (url_.SchemeIsFileSystem() || url_.SchemeIsBlob()) {
if (url_.SchemeIsFileSystem()) {
manager()->GetMediaResourceGetter()->GetPlatformPathFromURL( manager()->GetMediaResourceGetter()->GetPlatformPathFromURL(
url_, url_, base::BindOnce(&MediaPlayerBridge::SetDataSource,
base::Bind(&MediaPlayerBridge::SetDataSource, weak_factory_.GetWeakPtr()));
weak_factory_.GetWeakPtr()));
return; return;
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <string> #include <string>
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "media/base/media_export.h" #include "media/base/media_export.h"
...@@ -23,49 +22,47 @@ namespace media { ...@@ -23,49 +22,47 @@ namespace media {
class MEDIA_EXPORT MediaResourceGetter { class MEDIA_EXPORT MediaResourceGetter {
public: public:
// Callback to get the cookies. Args: cookies string. // Callback to get the cookies. Args: cookies string.
typedef base::Callback<void(const std::string&)> GetCookieCB; typedef base::OnceCallback<void(const std::string&)> GetCookieCB;
// Callback to get the platform path. Args: platform path. // Callback to get the platform path. Args: platform path.
typedef base::Callback<void(const std::string&)> GetPlatformPathCB; typedef base::OnceCallback<void(const std::string&)> GetPlatformPathCB;
// Callback to get the auth credentials. Args: username and password. // Callback to get the auth credentials. Args: username and password.
typedef base::Callback<void(const base::string16&, const base::string16&)> typedef base::OnceCallback<void(const base::string16&, const base::string16&)>
GetAuthCredentialsCB; GetAuthCredentialsCB;
// Callback to get the media metadata. Args: duration, width, height, and // Callback to get the media metadata. Args: duration, width, height, and
// whether the information is retrieved successfully. // whether the information is retrieved successfully.
typedef base::Callback<void(base::TimeDelta, int, int, bool)> typedef base::OnceCallback<void(base::TimeDelta, int, int, bool)>
ExtractMediaMetadataCB; ExtractMediaMetadataCB;
virtual ~MediaResourceGetter(); virtual ~MediaResourceGetter();
// Method for getting the auth credentials for a URL. // Method for getting the auth credentials for a URL.
virtual void GetAuthCredentials(const GURL& url, virtual void GetAuthCredentials(const GURL& url,
const GetAuthCredentialsCB& callback) = 0; GetAuthCredentialsCB callback) = 0;
// Method for getting the cookies for a given URL. // Method for getting the cookies for a given URL.
virtual void GetCookies(const GURL& url, virtual void GetCookies(const GURL& url,
const GURL& first_party_for_cookies, const GURL& first_party_for_cookies,
const GetCookieCB& callback) = 0; GetCookieCB callback) = 0;
// Method for getting the platform path from a file system or blob URL. // Method for getting the platform path from a file system URL.
virtual void GetPlatformPathFromURL( virtual void GetPlatformPathFromURL(const GURL& url,
const GURL& url, GetPlatformPathCB callback) = 0;
const GetPlatformPathCB& callback) = 0;
// Extracts the metadata from a media URL. Once completed, the provided // Extracts the metadata from a media URL. Once completed, the provided
// callback function will be run. // callback function will be run.
virtual void ExtractMediaMetadata( virtual void ExtractMediaMetadata(const std::string& url,
const std::string& url, const std::string& cookies,
const std::string& cookies, const std::string& user_agent,
const std::string& user_agent, ExtractMediaMetadataCB callback) = 0;
const ExtractMediaMetadataCB& callback) = 0;
// Extracts the metadata from a file descriptor. Once completed, the // Extracts the metadata from a file descriptor. Once completed, the
// provided callback function will be run. // provided callback function will be run.
virtual void ExtractMediaMetadata(const int fd, virtual void ExtractMediaMetadata(const int fd,
const int64_t offset, const int64_t offset,
const int64_t size, const int64_t size,
const ExtractMediaMetadataCB& callback) = 0; ExtractMediaMetadataCB callback) = 0;
}; };
} // namespace media } // namespace media
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment