Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Unified Diff: content/browser/media/android/url_provision_fetcher.cc

Issue 1427183002: Move MediaDrmBridge provision communication to native side. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bound network context into callback function instead of using factory Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..03bccb2c7ab3515d0affa6f8f4928e1b77d3a7d1
--- /dev/null
+++ b/content/browser/media/android/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 "content/browser/media/android/url_provision_fetcher.h"
+
+#include "content/public/browser/android/provision_fetcher_factory.h"
+#include "media/base/bind_to_current_loop.h"
+#include "net/url_request/url_fetcher.h"
+
+namespace content {
+
+using net::URLFetcher;
qinmin 2015/11/13 19:07:40 nit: move this out side namespace content
Tima Vaisburd 2015/11/13 21:04:43 Done.
+
+// Implementation of URLProvisionFetcher.
+
+URLProvisionFetcher::URLProvisionFetcher(
+ net::URLRequestContextGetter* context_getter)
+ : context_getter_(context_getter) {}
+
+URLProvisionFetcher::~URLProvisionFetcher() {}
+
+void URLProvisionFetcher::Retrieve(
+ const std::string& default_url,
+ const std::string& request_data,
+ const media::ProvisionFetcher::ResponseCB& response_cb) {
+ response_cb_ = response_cb;
+
+ std::string request_string = default_url + "&signedRequest=" + request_data;
qinmin 2015/11/13 19:07:40 nit: consider using constants for all the const st
Tima Vaisburd 2015/11/13 21:04:43 Changed this to const std::string, the second one
+ DVLOG(1) << __FUNCTION__ << ": request:" << request_string;
+
+ DCHECK(!request_);
+ request_ = URLFetcher::Create(GURL(request_string), 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(context_getter_);
+ request_->SetRequestContext(context_getter_);
+
+ request_->Start();
+}
+
+void URLProvisionFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
+ DCHECK(source);
qinmin 2015/11/13 19:07:40 no need
Tima Vaisburd 2015/11/13 21:04:43 Xiaohan seems to encourage DCHECKs for every input
+
+ 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);
+ DVLOG_IF(1, !success) << __FUNCTION__ << ": GetResponseAsString() failed";
+ } else {
+ DVLOG(1) << "CDM provision: server returned error code " << response_code;
+ }
+
+ request_.reset();
+
+ DCHECK(!response_cb_.is_null());
qinmin 2015/11/13 19:07:40 no need
Tima Vaisburd 2015/11/13 21:04:43 Removed.
+
+ // URLFetcher implementation calls OnURLFetchComplete() on the same thread
+ // that called Start() and it does this asynchronously.
+ response_cb_.Run(success, response);
+}
+
+// Implementation of content public method CreateProvisionFetcher().
+
+scoped_ptr<media::ProvisionFetcher> CreateProvisionFetcher(
+ net::URLRequestContextGetter* context_getter) {
xhwang 2015/11/13 05:15:42 DCHECK(context_getter);
Tima Vaisburd 2015/11/13 21:04:43 Done.
+ return scoped_ptr<media::ProvisionFetcher>(
+ new URLProvisionFetcher(context_getter));
xhwang 2015/11/13 05:15:42 will make_scoped_ptr(new URLProvisionFetcher(conte
Tima Vaisburd 2015/11/13 21:04:43 Done.
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698