url_fetcher_delegate.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_URL_REQUEST_URL_FETCHER_DELEGATE_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_URL_REQUEST_URL_FETCHER_DELEGATE_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLFetcher; 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A delegate interface for users of URLFetcher. 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT URLFetcherDelegate { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will be called when the URL has been fetched, successfully or not. 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Use accessor methods on |source| to get the results. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnURLFetchComplete(const URLFetcher* source) = 0; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will be called when some part of the response is read. |current| 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // denotes the number of bytes received up to the call, and |total| is the 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // expected total size of the response (or -1 if not determined). 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnURLFetchDownloadProgress(const URLFetcher* source, 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 current, int64 total); 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will be called when some part of the response is read. 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |download_data| contains the current bytes received since the last call. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will be called after ShouldSendDownloadData() and only if the latter 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returns true. 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnURLFetchDownloadData(const URLFetcher* source, 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<std::string> download_data); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This indicates if OnURLFetchDownloadData should be called. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will be called before OnURLFetchDownloadData is called, and only if 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this returns true. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Default implementation is false. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool ShouldSendDownloadData(); 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will be called when uploading of POST or PUT requests proceeded. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |current| denotes the number of bytes sent so far, and |total| is the 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // total size of uploading data (or -1 if chunked upload is enabled). 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnURLFetchUploadProgress(const URLFetcher* source, 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64 current, int64 total); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~URLFetcherDelegate(); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_URL_REQUEST_URL_FETCHER_DELEGATE_H_ 57