summaryrefslogtreecommitdiffstats
path: root/webkit/common/blob/blob_data.cc
blob: 8d6acff77cb76a9cbf64d419c6fc98e6cee00dd5 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) 2012 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.

#include "webkit/common/blob/blob_data.h"

#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time.h"

namespace webkit_blob {

BlobData::BlobData() {}
BlobData::BlobData(const std::string& uuid)
    : uuid_(uuid) {
}

BlobData::~BlobData() {}

void BlobData::AppendData(const char* data, size_t length) {
  DCHECK(length > 0);
  items_.push_back(Item());
  items_.back().SetToBytes(data, length);
}

void BlobData::AppendFile(const base::FilePath& file_path,
                          uint64 offset, uint64 length,
                          const base::Time& expected_modification_time) {
  DCHECK(length > 0);
  items_.push_back(Item());
  items_.back().SetToFilePathRange(file_path, offset, length,
                                   expected_modification_time);
}

void BlobData::AppendBlob(const GURL& blob_url, uint64 offset, uint64 length) {
  DCHECK_GT(length, 0ul);
  items_.push_back(Item());
  items_.back().SetToBlobUrlRange(blob_url, offset, length);
}

void BlobData::AppendBlob(const std::string& uuid,
                          uint64 offset, uint64 length) {
  DCHECK_GT(length, 0ul);
  items_.push_back(Item());
  items_.back().SetToBlobRange(uuid, offset, length);
}

void BlobData::AppendFileSystemFile(
    const GURL& url, uint64 offset,
    uint64 length,
    const base::Time& expected_modification_time) {
  DCHECK(length > 0);
  items_.push_back(Item());
  items_.back().SetToFileSystemUrlRange(url, offset, length,
                                        expected_modification_time);
}

int64 BlobData::GetMemoryUsage() const {
  int64 memory = 0;
  for (std::vector<Item>::const_iterator iter = items_.begin();
       iter != items_.end(); ++iter) {
    if (iter->type() == Item::TYPE_BYTES)
      memory += iter->length();
  }
  return memory;
}

}  // namespace webkit_blob