Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 #include "content/browser/media/android/url_provision_fetcher.h" | |
| 6 | |
| 7 #include <sstream> | |
| 8 | |
| 9 #include "content/public/browser/android/cdm_provision_fetcher.h" | |
| 10 #include "media/base/bind_to_current_loop.h" | |
| 11 #include "net/url_request/url_fetcher.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 using net::URLFetcher; | |
| 16 | |
| 17 URLProvisionFetcher::URLProvisionFetcher(net::URLRequestContextGetter* context) | |
| 18 : url_request_context_(context) {} | |
| 19 | |
| 20 URLProvisionFetcher::~URLProvisionFetcher() {} | |
| 21 | |
| 22 void URLProvisionFetcher::Retrieve( | |
| 23 const std::string& default_url, | |
| 24 const std::string& request_data, | |
| 25 const media::ProvisionFetcher::ResponseCB& response_cb) { | |
| 26 response_cb_ = media::BindToCurrentLoop(response_cb); | |
|
xhwang
2015/11/11 09:53:21
Can response_cb_ be fired on a different thread? I
Tima Vaisburd
2015/11/11 23:26:35
Yes, this was unaswered in PS2. The URLFetcher imp
xhwang
2015/11/12 22:27:03
This should really be part of the URLFetcher's pub
| |
| 27 | |
| 28 std::ostringstream os; | |
| 29 os << default_url << "&signedRequest=" << request_data; | |
| 30 DVLOG(1) << __FUNCTION__ << ": request:" << os.str(); | |
| 31 | |
| 32 DCHECK(!request_); | |
| 33 request_ = URLFetcher::Create(GURL(os.str()), URLFetcher::POST, this); | |
| 34 | |
| 35 // SetUploadData is mandatory even if we are not uploading anything. | |
| 36 request_->SetUploadData("", ""); | |
| 37 request_->AddExtraRequestHeader("User-Agent: Widevine CDM v1.0"); | |
| 38 request_->AddExtraRequestHeader("Content-Type: application/json"); | |
| 39 | |
| 40 DCHECK(url_request_context_); | |
| 41 request_->SetRequestContext(url_request_context_); | |
| 42 | |
| 43 request_->Start(); | |
| 44 } | |
| 45 | |
| 46 void URLProvisionFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | |
| 47 DCHECK(source); | |
| 48 | |
| 49 int response_code = source->GetResponseCode(); | |
| 50 DVLOG(1) << __FUNCTION__ << ": response code:" << source->GetResponseCode(); | |
| 51 | |
| 52 std::string response; | |
| 53 bool success = false; | |
| 54 if (response_code == 200) { | |
| 55 success = source->GetResponseAsString(&response); | |
| 56 (void)(success); | |
|
xhwang
2015/11/11 09:53:21
not needed?
Tima Vaisburd
2015/11/11 23:26:35
Sorry, it was bad thinking about unused variable.
| |
| 57 DVLOG_IF(1, !success) << __FUNCTION__ << ": GetResponseAsString() failed"; | |
| 58 } else { | |
| 59 DVLOG(1) << "CDM provision: server returned error code " << response_code; | |
| 60 } | |
| 61 | |
| 62 request_.reset(); | |
| 63 | |
| 64 DCHECK(!response_cb_.is_null()); | |
| 65 response_cb_.Run(success, response); | |
| 66 } | |
| 67 | |
| 68 // CDMProvisionFetcher implementation. | |
| 69 | |
| 70 // static | |
| 71 scoped_ptr<media::ProvisionFetcher> CDMProvisionFetcher::CreateWithURLContext( | |
| 72 net::URLRequestContextGetter* context) { | |
| 73 return scoped_ptr<media::ProvisionFetcher>(new URLProvisionFetcher(context)); | |
| 74 } | |
| 75 | |
| 76 } // namespace content | |
| OLD | NEW |