summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/blob_reader.h
blob: 1cf464b86924ddb2d957d20deb963e34d7064e39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_EXTENSIONS_BLOB_READER_H_
#define CHROME_BROWSER_EXTENSIONS_BLOB_READER_H_

#include <stdint.h>

#include <string>

#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "net/base/io_buffer.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request.h"
#include "url/gurl.h"

class Profile;
namespace net {
class URLFetcher;
}

// This class may only be used from the UI thread.
class BlobReader : public net::URLFetcherDelegate {
 public:
  // |blob_data| contains the portion of the Blob requested. |blob_total_size|
  // is the total size of the Blob, and may be larger than |blob_data->size()|.
  // |blob_total_size| is -1 if it cannot be determined.
  typedef base::Callback<void(scoped_ptr<std::string> blob_data,
                              int64_t blob_total_size)> BlobReadCallback;

  BlobReader(Profile* profile,
             const std::string& blob_uuid,
             BlobReadCallback callback);
  ~BlobReader() override;

  void SetByteRange(int64_t offset, int64_t length);

  void Start();

 private:
  // Overridden from net::URLFetcherDelegate.
  void OnURLFetchComplete(const net::URLFetcher* source) override;

  BlobReadCallback callback_;
  scoped_ptr<net::URLFetcher> fetcher_;

  DISALLOW_COPY_AND_ASSIGN(BlobReader);
};

#endif  // CHROME_BROWSER_EXTENSIONS_BLOB_READER_H_