| OLD | NEW | 
|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "ios/web/webui/url_fetcher_block_adapter.h" | 5 #include "ios/web/webui/url_fetcher_block_adapter.h" | 
| 6 | 6 | 
| 7 #include "base/logging.h" | 7 #include "base/logging.h" | 
| 8 #include "net/url_request/url_fetcher.h" | 8 #include "net/url_request/url_fetcher.h" | 
| 9 #include "net/url_request/url_request_context_getter.h" | 9 #include "net/url_request/url_request_context_getter.h" | 
| 10 | 10 | 
| 11 namespace web { | 11 namespace web { | 
| 12 | 12 | 
| 13 URLFetcherBlockAdapter::URLFetcherBlockAdapter( | 13 URLFetcherBlockAdapter::URLFetcherBlockAdapter( | 
| 14     const GURL& url, | 14     const GURL& url, | 
| 15     net::URLRequestContextGetter* request_context, | 15     net::URLRequestContextGetter* request_context, | 
| 16     web::URLFetcherBlockAdapterCompletion completion_handler) | 16     web::URLFetcherBlockAdapterCompletion completion_handler) | 
| 17     : url_(url), | 17     : url_(url), | 
| 18       request_context_(request_context), | 18       request_context_(request_context), | 
| 19       completion_handler_([completion_handler copy]) { | 19       completion_handler_([completion_handler copy]) { | 
| 20 } | 20 } | 
| 21 | 21 | 
| 22 URLFetcherBlockAdapter::~URLFetcherBlockAdapter() { | 22 URLFetcherBlockAdapter::~URLFetcherBlockAdapter() { | 
| 23 } | 23 } | 
| 24 | 24 | 
| 25 void URLFetcherBlockAdapter::Start() { | 25 void URLFetcherBlockAdapter::Start() { | 
| 26   fetcher_.reset(net::URLFetcher::Create(url_, net::URLFetcher::GET, this)); | 26   fetcher_ = net::URLFetcher::Create(url_, net::URLFetcher::GET, this); | 
| 27   fetcher_->SetRequestContext(request_context_); | 27   fetcher_->SetRequestContext(request_context_); | 
| 28   fetcher_->Start(); | 28   fetcher_->Start(); | 
| 29 } | 29 } | 
| 30 | 30 | 
| 31 void URLFetcherBlockAdapter::OnURLFetchComplete(const net::URLFetcher* source) { | 31 void URLFetcherBlockAdapter::OnURLFetchComplete(const net::URLFetcher* source) { | 
| 32   std::string response; | 32   std::string response; | 
| 33   if (!source->GetResponseAsString(&response)) { | 33   if (!source->GetResponseAsString(&response)) { | 
| 34     DLOG(WARNING) << "String for resource URL not found" << source->GetURL(); | 34     DLOG(WARNING) << "String for resource URL not found" << source->GetURL(); | 
| 35   } | 35   } | 
| 36   NSData* data = | 36   NSData* data = | 
| 37       [NSData dataWithBytes:response.c_str() length:response.length()]; | 37       [NSData dataWithBytes:response.c_str() length:response.length()]; | 
| 38   completion_handler_.get()(data, this); | 38   completion_handler_.get()(data, this); | 
| 39 } | 39 } | 
| 40 | 40 | 
| 41 }  // namespace web | 41 }  // namespace web | 
| OLD | NEW | 
|---|