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

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: 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 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 namespace content {
12
13 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.
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 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
30 DVLOG(1) << __FUNCTION__ << ": request:" << request_string;
31
32 DCHECK(!request_);
33 request_ = URLFetcher::Create(GURL(request_string), 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(context_getter_);
41 request_->SetRequestContext(context_getter_);
42
43 request_->Start();
44 }
45
46 void URLProvisionFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
47 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
48
49 int response_code = source->GetResponseCode();
50 DVLOG(1) << __FUNCTION__ << ": response code:" << source->GetResponseCode();
51
52 std::string response;
53 bool success = false;
54 if (response_code == 200) {
55 success = source->GetResponseAsString(&response);
56 DVLOG_IF(1, !success) << __FUNCTION__ << ": GetResponseAsString() failed";
57 } else {
58 DVLOG(1) << "CDM provision: server returned error code " << response_code;
59 }
60
61 request_.reset();
62
63 DCHECK(!response_cb_.is_null());
qinmin 2015/11/13 19:07:40 no need
Tima Vaisburd 2015/11/13 21:04:43 Removed.
64
65 // URLFetcher implementation calls OnURLFetchComplete() on the same thread
66 // that called Start() and it does this asynchronously.
67 response_cb_.Run(success, response);
68 }
69
70 // Implementation of content public method CreateProvisionFetcher().
71
72 scoped_ptr<media::ProvisionFetcher> CreateProvisionFetcher(
73 net::URLRequestContextGetter* context_getter) {
xhwang 2015/11/13 05:15:42 DCHECK(context_getter);
Tima Vaisburd 2015/11/13 21:04:43 Done.
74 return scoped_ptr<media::ProvisionFetcher>(
75 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.
76 }
77
78 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698