1 // Copyright (c) 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.
5 #ifndef WEBKIT_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_
6 #define WEBKIT_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "webkit/browser/webkit_storage_browser_export.h"
15 #include "webkit/common/blob/blob_data.h"
24 namespace webkit_blob
{
28 // This class handles the logistics of blob Storage within the browser process,
29 // and maintains a mapping from blob uuid to the data. The class is single
30 // threaded and should only be used on the IO thread.
31 // In chromium, there is one instance per profile.
32 class WEBKIT_STORAGE_BROWSER_EXPORT BlobStorageContext
33 : public base::SupportsWeakPtr
<BlobStorageContext
> {
36 ~BlobStorageContext();
38 scoped_ptr
<BlobDataHandle
> GetBlobDataFromUUID(const std::string
& uuid
);
39 scoped_ptr
<BlobDataHandle
> GetBlobDataFromPublicURL(const GURL
& url
);
41 // Useful for coining blobs from within the browser process. If the
42 // blob cannot be added due to memory consumption, returns NULL.
43 scoped_ptr
<BlobDataHandle
> AddFinishedBlob(const BlobData
* blob_data
);
46 friend class BlobDataHandle
;
47 friend class BlobStorageHost
;
51 EXCEEDED_MEMORY
= 1 << 1,
57 scoped_refptr
<BlobData
> data
;
60 BlobMapEntry(int refcount
, int flags
, BlobData
* data
);
64 typedef std::map
<std::string
, BlobMapEntry
>
66 typedef std::map
<GURL
, std::string
> BlobURLMap
;
68 void StartBuildingBlob(const std::string
& uuid
);
69 void AppendBlobDataItem(const std::string
& uuid
,
70 const BlobData::Item
& data_item
);
71 void FinishBuildingBlob(const std::string
& uuid
, const std::string
& type
);
72 void CancelBuildingBlob(const std::string
& uuid
);
73 void IncrementBlobRefCount(const std::string
& uuid
);
74 void DecrementBlobRefCount(const std::string
& uuid
);
75 void RegisterPublicBlobURL(const GURL
& url
, const std::string
& uuid
);
76 void RevokePublicBlobURL(const GURL
& url
);
78 bool ExpandStorageItems(BlobData
* target_blob_data
,
79 BlobData
* src_blob_data
,
82 bool AppendBytesItem(BlobData
* target_blob_data
,
83 const char* data
, int64 length
);
84 void AppendFileItem(BlobData
* target_blob_data
,
85 const base::FilePath
& file_path
,
86 uint64 offset
, uint64 length
,
87 const base::Time
& expected_modification_time
);
88 void AppendFileSystemFileItem(
89 BlobData
* target_blob_data
,
90 const GURL
& url
, uint64 offset
, uint64 length
,
91 const base::Time
& expected_modification_time
);
93 bool IsInUse(const std::string
& uuid
);
94 bool IsBeingBuilt(const std::string
& uuid
);
95 bool IsUrlRegistered(const GURL
& blob_url
);
98 BlobURLMap public_blob_urls_
;
100 // Used to keep track of how much memory is being utitlized for blob data,
101 // we count only the items of TYPE_DATA which are held in memory and not
102 // items of TYPE_FILE.
105 DISALLOW_COPY_AND_ASSIGN(BlobStorageContext
);
108 } // namespace webkit_blob
110 #endif // WEBKIT_BROWSER_BLOB_BLOB_STORAGE_CONTEXT_H_