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

Side by Side 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: Reformatted media/ 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 unified diff | Download patch
OLDNEW
(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 using net::URLFetcher;
12
13 namespace content {
14
15 // Implementation of URLProvisionFetcher.
16
17 URLProvisionFetcher::URLProvisionFetcher(
18 net::URLRequestContextGetter* context_getter)
19 : context_getter_(context_getter) {}
20
21 URLProvisionFetcher::~URLProvisionFetcher() {}
22
23 void URLProvisionFetcher::Retrieve(
24 const std::string& default_url,
25 const std::string& request_data,
26 const media::ProvisionFetcher::ResponseCB& response_cb) {
27 response_cb_ = response_cb;
28
29 const std::string request_string =
30 default_url + "&signedRequest=" + request_data;
31 DVLOG(1) << __FUNCTION__ << ": request:" << request_string;
32
33 DCHECK(!request_);
34 request_ = URLFetcher::Create(GURL(request_string), URLFetcher::POST, this);
35
36 // SetUploadData is mandatory even if we are not uploading anything.
37 request_->SetUploadData("", "");
38 request_->AddExtraRequestHeader("User-Agent: Widevine CDM v1.0");
39 request_->AddExtraRequestHeader("Content-Type: application/json");
40
41 DCHECK(context_getter_);
42 request_->SetRequestContext(context_getter_);
43
44 request_->Start();
45 }
46
47 void URLProvisionFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
48 DCHECK(source);
49
50 int response_code = source->GetResponseCode();
51 DVLOG(1) << __FUNCTION__ << ": response code:" << source->GetResponseCode();
52
53 std::string response;
54 bool success = false;
55 if (response_code == 200) {
56 success = source->GetResponseAsString(&response);
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 // 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 content public method CreateProvisionFetcher().
70
71 scoped_ptr<media::ProvisionFetcher> CreateProvisionFetcher(
72 net::URLRequestContextGetter* context_getter) {
73 DCHECK(context_getter);
74 return make_scoped_ptr(new URLProvisionFetcher(context_getter));
75 }
76
77 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/android/url_provision_fetcher.h ('k') | content/browser/media/cdm/browser_cdm_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698