| 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 #ifndef IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_ | 5 #ifndef IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_ |
| 6 #define IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_ | 6 #define IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // Class for use of URLFetcher from Objective-C with a completion handler block. | 22 // Class for use of URLFetcher from Objective-C with a completion handler block. |
| 23 class URLFetcherBlockAdapter; | 23 class URLFetcherBlockAdapter; |
| 24 // Block type for URLFetcherBlockAdapter callbacks. | 24 // Block type for URLFetcherBlockAdapter callbacks. |
| 25 typedef void (^URLFetcherBlockAdapterCompletion)(NSData*, | 25 typedef void (^URLFetcherBlockAdapterCompletion)(NSData*, |
| 26 URLFetcherBlockAdapter*); | 26 URLFetcherBlockAdapter*); |
| 27 | 27 |
| 28 // Class to manage retrieval of WebUI resources. | 28 // Class to manage retrieval of WebUI resources. |
| 29 class URLFetcherBlockAdapter : public net::URLFetcherDelegate { | 29 class URLFetcherBlockAdapter : public net::URLFetcherDelegate { |
| 30 public: | 30 public: |
| 31 // Create URLFetcherBlockAdapter for resource at |url| with |request_context|. | 31 // Creates URLFetcherBlockAdapter for resource at |url| with |
| 32 // |request_context|. |
| 32 // |completion_handler| is called with results of the fetch. | 33 // |completion_handler| is called with results of the fetch. |
| 33 URLFetcherBlockAdapter( | 34 URLFetcherBlockAdapter( |
| 34 const GURL& url, | 35 const GURL& url, |
| 35 net::URLRequestContextGetter* request_context, | 36 net::URLRequestContextGetter* request_context, |
| 36 web::URLFetcherBlockAdapterCompletion completion_handler); | 37 web::URLFetcherBlockAdapterCompletion completion_handler); |
| 37 ~URLFetcherBlockAdapter() override; | 38 ~URLFetcherBlockAdapter() override; |
| 38 // Start the fetch. | 39 // Starts the fetch. |
| 39 void Start(); | 40 virtual void Start(); |
| 40 | 41 |
| 41 protected: | 42 protected: |
| 42 // net::URLFetcherDelegate implementation. | 43 // net::URLFetcherDelegate implementation. |
| 43 void OnURLFetchComplete(const net::URLFetcher* source) override; | 44 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 44 | 45 |
| 45 private: | 46 private: |
| 46 // The URL to fetch. | 47 // The URL to fetch. |
| 47 const GURL url_; | 48 const GURL url_; |
| 48 // The request context. | 49 // The request context. |
| 49 net::URLRequestContextGetter* request_context_; | 50 net::URLRequestContextGetter* request_context_; |
| 50 // Callback for resource load. | 51 // Callback for resource load. |
| 51 base::mac::ScopedBlock<web::URLFetcherBlockAdapterCompletion> | 52 base::mac::ScopedBlock<web::URLFetcherBlockAdapterCompletion> |
| 52 completion_handler_; | 53 completion_handler_; |
| 53 // URLFetcher for retrieving data from net stack. | 54 // URLFetcher for retrieving data from net stack. |
| 54 scoped_ptr<net::URLFetcher> fetcher_; | 55 scoped_ptr<net::URLFetcher> fetcher_; |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 } // namespace web | 58 } // namespace web |
| 58 | 59 |
| 59 #endif // IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_ | 60 #endif // IOS_WEB_WEBUI_URL_FETCHER_BLOCK_ADAPTER_H_ |
| OLD | NEW |