summaryrefslogtreecommitdiffstats
path: root/webkit/blob/blob_storage_controller.h
blob: 7f8d45c9b7a67541b7d927ffc76a8d19dcf20e3a (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
// Copyright (c) 2011 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 WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_
#define WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_

#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/process.h"

class GURL;
class FilePath;

namespace base {
class Time;
}
namespace net {
class UploadData;
}

namespace webkit_blob {

class BlobData;

// This class handles the logistics of blob Storage within the browser process.
class BlobStorageController {
 public:
  BlobStorageController();
  ~BlobStorageController();

  void RegisterBlobUrl(const GURL& url, const BlobData* blob_data);
  void RegisterBlobUrlFrom(const GURL& url, const GURL& src_url);
  void UnregisterBlobUrl(const GURL& url);
  BlobData* GetBlobDataFromUrl(const GURL& url);

  // If there is any blob reference in the upload data, it will get resolved
  // and updated in place.
  void ResolveBlobReferencesInUploadData(net::UploadData* upload_data);

 private:
  friend class ViewBlobInternalsJob;

  void AppendStorageItems(BlobData* target_blob_data,
                          BlobData* src_blob_data,
                          uint64 offset,
                          uint64 length);
  void AppendFileItem(BlobData* target_blob_data,
                      const FilePath& file_path, uint64 offset, uint64 length,
                      const base::Time& expected_modification_time);

  typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap;
  BlobMap blob_map_;

  DISALLOW_COPY_AND_ASSIGN(BlobStorageController);
};

}  // namespace webkit_blob

#endif  // WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_