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.
5 #ifndef IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_
6 #define IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_
8 #import <Foundation/Foundation.h>
10 #include "base/mac/scoped_block.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "net/url_request/url_fetcher_delegate.h"
17 class URLRequestContextGetter
;
22 // Class for use of URLFetcher from Objective-C with a completion handler block.
23 class URLFetcherBlockAdapter
;
24 // Block type for URLFetcherBlockAdapter callbacks.
25 typedef void (^URLFetcherBlockAdapterCompletion
)(NSData
*,
26 URLFetcherBlockAdapter
*);
28 // Class to manage retrieval of WebUI resources.
29 class URLFetcherBlockAdapter
: public net::URLFetcherDelegate
{
31 // Creates URLFetcherBlockAdapter for resource at |url| with
33 // |completion_handler| is called with results of the fetch.
34 URLFetcherBlockAdapter(
36 net::URLRequestContextGetter
* request_context
,
37 web::URLFetcherBlockAdapterCompletion completion_handler
);
38 ~URLFetcherBlockAdapter() override
;
43 // net::URLFetcherDelegate implementation.
44 void OnURLFetchComplete(const net::URLFetcher
* source
) override
;
49 // The request context.
50 net::URLRequestContextGetter
* request_context_
;
51 // Callback for resource load.
52 base::mac::ScopedBlock
<web::URLFetcherBlockAdapterCompletion
>
54 // URLFetcher for retrieving data from net stack.
55 scoped_ptr
<net::URLFetcher
> fetcher_
;
60 #endif // IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_