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 "content/public/browser/android/provision_fetcher_factory.h" | |
| 8 #include "media/base/bind_to_current_loop.h" | |
| 9 #include "net/url_request/url_fetcher.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 using net::URLFetcher; | |
| 14 | |
| 15 // Implementation of URLProvisionFetcher. | |
| 16 | |
| 17 URLProvisionFetcher::URLProvisionFetcher(net::URLRequestContextGetter* context) | |
| 18 : 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_ = response_cb; | |
| 27 | |
| 28 std::string request_string = default_url + "&signedRequest=" + request_data; | |
| 29 DVLOG(1) << __FUNCTION__ << ": request:" << request_string; | |
| 30 | |
| 31 DCHECK(!request_); | |
| 32 request_ = URLFetcher::Create(GURL(request_string), URLFetcher::POST, this); | |
| 33 | |
| 34 // SetUploadData is mandatory even if we are not uploading anything. | |
| 35 request_->SetUploadData("", ""); | |
| 36 request_->AddExtraRequestHeader("User-Agent: Widevine CDM v1.0"); | |
| 37 request_->AddExtraRequestHeader("Content-Type: application/json"); | |
| 38 | |
| 39 DCHECK(context_); | |
| 40 request_->SetRequestContext(context_); | |
| 41 | |
| 42 request_->Start(); | |
| 43 } | |
| 44 | |
| 45 void URLProvisionFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | |
| 46 DCHECK(source); | |
| 47 | |
| 48 int response_code = source->GetResponseCode(); | |
| 49 DVLOG(1) << __FUNCTION__ << ": response code:" << source->GetResponseCode(); | |
| 50 | |
| 51 std::string response; | |
| 52 bool success = false; | |
| 53 if (response_code == 200) { | |
| 54 success = source->GetResponseAsString(&response); | |
| 55 DVLOG_IF(1, !success) << __FUNCTION__ << ": GetResponseAsString() failed"; | |
| 56 } else { | |
| 57 DVLOG(1) << "CDM provision: server returned error code " << response_code; | |
| 58 } | |
| 59 | |
| 60 request_.reset(); | |
| 61 | |
| 62 DCHECK(!response_cb_.is_null()); | |
| 63 | |
| 64 // URLFetcher implementation calls OnURLFetchComplete() on the same thread | |
| 65 // that called Start() and it does this asynchronously. | |
| 66 response_cb_.Run(success, response); | |
| 67 } | |
| 68 | |
| 69 // Implementation of URLProvisionFetcherFactory. | |
| 70 | |
| 71 URLProvisionFetcherFactory::URLProvisionFetcherFactory( | |
| 72 net::URLRequestContextGetter* context) | |
| 73 : context_(context) {} | |
| 74 | |
| 75 URLProvisionFetcherFactory::~URLProvisionFetcherFactory() {} | |
| 76 | |
| 77 scoped_ptr<media::ProvisionFetcher> URLProvisionFetcherFactory::CreateFetcher() | |
| 78 const { | |
| 79 return scoped_ptr<media::ProvisionFetcher>(new URLProvisionFetcher(context_)); | |
| 80 } | |
| 81 | |
| 82 // Implementation of content public method CreateProvisionFetcherFactory(). | |
| 83 | |
| 84 media::ProvisionFetcherFactory* CreateURLProvisionFetcherFactory( | |
|
xhwang
2015/11/12 22:27:03
This should CreateProvisionFetcherFactory since th
Tima Vaisburd
2015/11/13 03:13:10
The function now creates the fetcher instead of a
| |
| 85 net::URLRequestContextGetter* context) { | |
| 86 return new URLProvisionFetcherFactory(context); | |
| 87 } | |
| 88 | |
| 89 } // namespace content | |
| OLD | NEW |