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 "chrome/browser/media/android/provision/url_provision_fetcher.h" | |
| 6 | |
| 7 #include <sstream> | |
| 8 | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/browser/profiles/profile_manager.h" | |
| 11 #include "net/url_request/url_fetcher.h" | |
| 12 | |
| 13 namespace media { | |
| 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(const std::string& default_url, | |
| 23 const std::string& request_data, | |
| 24 ResponseCallback response_cb) { | |
| 25 DVLOG(1) << __FUNCTION__; | |
| 26 | |
| 27 response_cb_ = response_cb; | |
| 28 | |
| 29 std::ostringstream os; | |
| 30 os << default_url << "&signedRequest=" << request_data; | |
| 31 DVLOG(1) << __FUNCTION__ << ": request:" << os.str(); | |
|
xhwang
2015/11/02 20:37:04
You'll end up with "os" not used in release build.
Tima Vaisburd
2015/11/05 02:24:06
|os| is used on l.33 ?
| |
| 32 | |
| 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 DVLOG(1) << __FUNCTION__; | |
| 48 | |
| 49 DCHECK(source); | |
| 50 | |
| 51 int response_code = source->GetResponseCode(); | |
| 52 DVLOG(1) << __FUNCTION__ << ": response code:" << source->GetResponseCode(); | |
|
xhwang
2015/11/02 20:37:04
Can you replace l.47 with this line?
Tima Vaisburd
2015/11/05 02:24:06
Done.
| |
| 53 | |
| 54 std::string response; | |
| 55 bool success = false; | |
| 56 if (response_code == 200) { | |
| 57 success = source->GetResponseAsString(&response); | |
| 58 if (!success) | |
| 59 DVLOG(1) << __FUNCTION__ << ": GetResponseAsString() failed"; | |
| 60 } else { | |
| 61 DVLOG(1) << "CDM provision: server returned error code " << response_code; | |
| 62 } | |
| 63 | |
| 64 request_.reset(); | |
| 65 | |
| 66 DCHECK(!response_cb_.is_null()); | |
| 67 response_cb_.Run(response, success); | |
| 68 } | |
| 69 | |
| 70 scoped_ptr<ProvisionFetcher> URLProvisionFetcherFactory::CreateFetcher() const { | |
| 71 // Retrieve URL fetcher context from profile. | |
| 72 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 73 net::URLRequestContextGetter* context = profile->GetRequestContext(); | |
| 74 | |
| 75 return scoped_ptr<ProvisionFetcher>(new URLProvisionFetcher(context)); | |
| 76 } | |
| 77 | |
| 78 } // namespace media | |
| OLD | NEW |