Index: chrome/browser/media/android/provision/url_provision_fetcher.cc |
diff --git a/chrome/browser/media/android/provision/url_provision_fetcher.cc b/chrome/browser/media/android/provision/url_provision_fetcher.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..61b9577f39e0478b794e77c62e7b4716bf834c82 |
--- /dev/null |
+++ b/chrome/browser/media/android/provision/url_provision_fetcher.cc |
@@ -0,0 +1,78 @@ |
+// 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 "chrome/browser/media/android/provision/url_provision_fetcher.h" |
+ |
+#include <sstream> |
+ |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/profiles/profile_manager.h" |
+#include "net/url_request/url_fetcher.h" |
+ |
+namespace media { |
+ |
+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, |
+ ResponseCallback response_cb) { |
+ DVLOG(1) << __FUNCTION__; |
+ |
+ response_cb_ = response_cb; |
+ |
+ std::ostringstream os; |
+ os << default_url << "&signedRequest=" << request_data; |
+ 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 ?
|
+ |
+ request_ = URLFetcher::Create(GURL(os.str()), URLFetcher::POST, this); |
+ |
+ // 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) { |
+ DVLOG(1) << __FUNCTION__; |
+ |
+ DCHECK(source); |
+ |
+ int response_code = source->GetResponseCode(); |
+ 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.
|
+ |
+ std::string response; |
+ bool success = false; |
+ if (response_code == 200) { |
+ success = source->GetResponseAsString(&response); |
+ if (!success) |
+ DVLOG(1) << __FUNCTION__ << ": GetResponseAsString() failed"; |
+ } else { |
+ DVLOG(1) << "CDM provision: server returned error code " << response_code; |
+ } |
+ |
+ request_.reset(); |
+ |
+ DCHECK(!response_cb_.is_null()); |
+ response_cb_.Run(response, success); |
+} |
+ |
+scoped_ptr<ProvisionFetcher> URLProvisionFetcherFactory::CreateFetcher() const { |
+ // Retrieve URL fetcher context from profile. |
+ Profile* profile = ProfileManager::GetActiveUserProfile(); |
+ net::URLRequestContextGetter* context = profile->GetRequestContext(); |
+ |
+ return scoped_ptr<ProvisionFetcher>(new URLProvisionFetcher(context)); |
+} |
+ |
+} // namespace media |