Home | History | Annotate | Download | only in extensions
      1 // Copyright 2013 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 #ifndef CHROME_BROWSER_EXTENSIONS_BLOB_READER_H_
      6 #define CHROME_BROWSER_EXTENSIONS_BLOB_READER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/callback.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "net/base/io_buffer.h"
     13 #include "net/url_request/url_fetcher_delegate.h"
     14 #include "net/url_request/url_request.h"
     15 #include "url/gurl.h"
     16 
     17 class Profile;
     18 namespace net {
     19 class URLFetcher;
     20 }
     21 
     22 // This class may only be used from the UI thread.
     23 class BlobReader : public net::URLFetcherDelegate {
     24  public:
     25   // |blob_data| contains the portion of the Blob requested. |blob_total_size|
     26   // is the total size of the Blob, and may be larger than |blob_data->size()|.
     27   // |blob_total_size| is -1 if it cannot be determined.
     28   typedef base::Callback<void(scoped_ptr<std::string> blob_data,
     29                               int64 blob_total_size)>
     30       BlobReadCallback;
     31 
     32   BlobReader(Profile* profile,
     33              const std::string& blob_uuid,
     34              BlobReadCallback callback);
     35   virtual ~BlobReader();
     36 
     37   void SetByteRange(int64 offset, int64 length);
     38 
     39   void Start();
     40 
     41  private:
     42   // Overridden from net::URLFetcherDelegate.
     43   virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
     44 
     45   BlobReadCallback callback_;
     46   scoped_ptr<net::URLFetcher> fetcher_;
     47 
     48   DISALLOW_COPY_AND_ASSIGN(BlobReader);
     49 };
     50 
     51 #endif  // CHROME_BROWSER_EXTENSIONS_BLOB_READER_H_
     52