Chromium Code Reviews| Index: content/browser/media/android/url_provision_fetcher.cc |
| diff --git a/content/browser/media/android/url_provision_fetcher.cc b/content/browser/media/android/url_provision_fetcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2612260bf39be7b0fee5459de3144a48dfd54e27 |
| --- /dev/null |
| +++ b/content/browser/media/android/url_provision_fetcher.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2015 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. |
| + |
| +#include "content/browser/media/android/url_provision_fetcher.h" |
| + |
| +#include <sstream> |
| + |
| +#include "content/public/browser/android/cdm_provision_fetcher.h" |
| +#include "media/base/bind_to_current_loop.h" |
| +#include "net/url_request/url_fetcher.h" |
| + |
| +namespace content { |
| + |
| +using net::URLFetcher; |
| + |
| +URLProvisionFetcher::URLProvisionFetcher(net::URLRequestContextGetter* context) |
| + : url_request_context_(context) {} |
| + |
| +URLProvisionFetcher::~URLProvisionFetcher() {} |
| + |
| +void URLProvisionFetcher::Retrieve( |
| + const std::string& default_url, |
| + const std::string& request_data, |
| + const media::ProvisionFetcher::ResponseCB& response_cb) { |
|
xhwang
2015/11/06 23:08:18
I suppose we can't make multiple requests? How abo
Tima Vaisburd
2015/11/11 03:03:33
Done.
|
| + response_cb_ = media::BindToCurrentLoop(response_cb); |
|
xhwang
2015/11/06 23:08:18
Will Retrieve() and OnURLFetchComplete() be called
|
| + |
| + std::ostringstream os; |
| + os << default_url << "&signedRequest=" << request_data; |
|
xhwang
2015/11/06 23:08:18
Is this "signedRequest" part documented anywhere?
Tima Vaisburd
2015/11/11 03:03:33
This is what the java code did. The only doc I fou
xhwang
2015/11/11 09:53:21
Yeah, it's like magic...
+qinmin, do you remember
|
| + DVLOG(1) << __FUNCTION__ << ": request:" << os.str(); |
| + |
| + request_ = URLFetcher::Create(GURL(os.str()), URLFetcher::POST, this); |
|
xhwang
2015/11/06 23:08:18
sorry for the bikeshedding...
I think we use stre
Tima Vaisburd
2015/11/11 03:03:33
Yes, we can.
I think it would be nice to know wha
xhwang
2015/11/11 09:53:20
I won't worry about performance here, it's really
Tima Vaisburd
2015/11/11 23:26:35
My stubbornness won't stretch pass this point. Don
|
| + |
| + // SetUploadData is mandatory even if we are not uploading anything. |
| + request_->SetUploadData("", ""); |
| + request_->AddExtraRequestHeader("User-Agent: Widevine CDM v1.0"); |
| + request_->AddExtraRequestHeader("Content-Type: application/json"); |
| + |
| + DCHECK(url_request_context_); |
| + request_->SetRequestContext(url_request_context_); |
| + |
| + request_->Start(); |
| +} |
| + |
| +void URLProvisionFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
| + DCHECK(source); |
| + |
| + int response_code = source->GetResponseCode(); |
| + DVLOG(1) << __FUNCTION__ << ": response code:" << source->GetResponseCode(); |
| + |
| + std::string response; |
| + bool success = false; |
| + if (response_code == 200) { |
| + success = source->GetResponseAsString(&response); |
| + if (!success) |
| + DVLOG(1) << __FUNCTION__ << ": GetResponseAsString() failed"; |
|
xhwang
2015/11/06 23:08:18
nit: Use DVLOG_IF
Tima Vaisburd
2015/11/11 03:03:33
Done.
|
| + } else { |
| + DVLOG(1) << "CDM provision: server returned error code " << response_code; |
| + } |
| + |
| + request_.reset(); |
| + |
| + DCHECK(!response_cb_.is_null()); |
| + response_cb_.Run(success, response); |
| +} |
| + |
| +// CDMProvisionFetcher implementation. |
| + |
| +// static |
| +scoped_ptr<media::ProvisionFetcher> CDMProvisionFetcher::CreateWithURLContext( |
|
xhwang
2015/11/06 23:08:18
Why do we need CDMProvisionFetcher?
Tima Vaisburd
2015/11/11 03:03:33
According to the current dependency rules chrome/
xhwang
2015/11/11 09:53:20
Oh I see. I missed that.
No we should not change
Tima Vaisburd
2015/11/11 23:26:35
Yes, created a factory function CreateProvisionFet
|
| + net::URLRequestContextGetter* context) { |
| + return scoped_ptr<media::ProvisionFetcher>(new URLProvisionFetcher(context)); |
| +} |
| + |
| +} // namespace content |