Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Unified Diff: webkit/blob/blob_storage_context.h

Issue 14139026: New blobstoragecontext for use in the main browser process, not plugged in yet. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/blob/blob_storage_context.h
===================================================================
--- webkit/blob/blob_storage_context.h (revision 189105)
+++ webkit/blob/blob_storage_context.h (working copy)
@@ -1,16 +1,22 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 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 WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_
-#define WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_
+#ifndef WEBKIT_BLOB_BLOB_STORAGE_CONTEXT_H_
+#define WEBKIT_BLOB_BLOB_STORAGE_CONTEXT_H_
#include <map>
+#include <set>
#include <string>
+#include <utility>
+#include "base/gtest_prod_util.h"
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
#include "base/process.h"
+#include "base/shared_memory.h"
+#include "base/supports_user_data.h"
#include "webkit/blob/blob_data.h"
#include "webkit/storage/webkit_storage_export.h"
@@ -18,65 +24,134 @@
namespace base {
class FilePath;
+class SequencedTaskRunner;
class Time;
}
namespace webkit_blob {
-// This class handles the logistics of blob Storage within the browser process.
-class WEBKIT_STORAGE_EXPORT BlobStorageController {
+class BlobDataHandle;
+class BlobStorageHost;
+class BlobStorageContext;
+
+// A scoper object for use in chrome's main browser process, ensures
+// the underlying BlobData and its uuid remain in BlobStorageContext's
+// collection for the duration. This object has delete semantics and
+// maybe deleted on any thread.
+class WEBKIT_STORAGE_EXPORT BlobDataHandle
kinuko 2013/04/18 02:36:35 As a generic comment can we split files for these
michaeln 2013/04/18 20:42:19 We could, would it help? I'm refactoring the curre
kinuko 2013/04/23 05:30:39 I usually find it helpful to find files/classes. T
michaeln 2013/04/23 19:27:16 ok, will do in a later snapshot
+ : public base::SupportsUserData::Data {
public:
- BlobStorageController();
- ~BlobStorageController();
+ virtual ~BlobDataHandle(); // Maybe be deleted on any thread.
+ BlobData* data() const; // May only be accessed on the IO thread.
- void StartBuildingBlob(const GURL& url);
- void AppendBlobDataItem(const GURL& url, const BlobData::Item& data_item);
- void FinishBuildingBlob(const GURL& url, const std::string& content_type);
- void AddFinishedBlob(const GURL& url, const BlobData* blob_data);
- void CloneBlob(const GURL& url, const GURL& src_url);
- void RemoveBlob(const GURL& url);
- BlobData* GetBlobDataFromUrl(const GURL& url);
+ private:
+ friend class BlobStorageContext;
+ BlobDataHandle(BlobData* blob_data, BlobStorageContext* context,
+ base::SequencedTaskRunner* task_runner);
ericu 2013/04/18 02:01:58 Should we document that it can only be created on
michaeln 2013/04/19 21:55:51 should we? i hadn't since it's private and pretty
ericu 2013/04/22 17:25:14 OK.
+ static void DeleteHelper(
+ scoped_ptr<base::WeakPtr<BlobStorageContext> > context,
+ scoped_refptr<BlobData> blob_data);
+
+ scoped_refptr<BlobData> blob_data_;
+ scoped_ptr<base::WeakPtr<BlobStorageContext> > context_;
kinuko 2013/04/18 02:36:35 whoa... I'll see when I go on reading the patch bu
michaeln 2013/04/18 20:42:19 Better than a raw ptr and a comment that sayz "foo
kinuko 2013/04/23 05:30:39 Yup, if this was a mere weak_ptr it would have bee
michaeln 2013/04/23 19:27:16 The comments in weak_ptr.h read as if we don't nee
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
+};
+
+// This class handles the logistics of blob storage for a single child process.
+// There is generally one instance per child process. When the child process
ericu 2013/04/18 02:01:58 Generally, or always?
michaeln 2013/04/19 21:55:51 always i guess, but i can imagine other use cases
michaeln 2013/04/20 00:31:02 Done.
+// terminates all blob references attibutable to that process go away upon
+// destruction of the instance. The class is single threaded and should
+// only be used on the IO thread.
+class WEBKIT_STORAGE_EXPORT BlobStorageHost {
+ public:
+ explicit BlobStorageHost(BlobStorageContext* context);
+ ~BlobStorageHost();
+
+ // Methods to support the IPC message protocol.
+ void StartBuildingBlob(const std::string& uuid);
+ void AppendBlobDataItem(const std::string& uuid,
+ const BlobData::Item& data_item);
+ void CancelBuildingBlob(const std::string& uuid);
+ void FinishBuildingBlob(const std::string& uuid, const std::string& type);
+ void AddFinishedBlob(const BlobData* blob_data);
+ void IncrementBlobRefCount(const std::string& uuid);
+ void DecrementBlobRefCount(const std::string& uuid);
+ void RegisterPublicBlobURL(const GURL& blob_url, const std::string& uuid);
+ void RevokePublicBlobURL(const GURL& blob_url);
+
private:
- friend class ViewBlobInternalsJob;
+ typedef std::map<std::string, int> BlobReferenceMap;
- typedef base::hash_map<std::string, scoped_refptr<BlobData> > BlobMap;
- typedef std::map<BlobData*, int> BlobDataUsageMap;
+ // Collection of blob ids and a count of how many usages
+ // of that id are attributable to this consumer.
+ BlobReferenceMap blobs_inuse_map_;
+ // The set of public blob urls coined by this consumer.
+ std::set<GURL> public_blob_urls_;
+
+ base::WeakPtr<BlobStorageContext> context_;
+};
+
+// This class handles the logistics of blob Storage within the browser process,
+// and maintains a mapping from blob uuid to the data. The class is single
+// threaded and should only be used on the IO thread.
+// In chromium, there is one instance per profile.
+class WEBKIT_STORAGE_EXPORT BlobStorageContext
+ : public base::SupportsWeakPtr<BlobStorageContext> {
+ public:
+ BlobStorageContext();
+ ~BlobStorageContext();
+
+ scoped_ptr<BlobDataHandle> GetBlobDataFromUUID(const std::string& uuid);
+ scoped_ptr<BlobDataHandle> GetBlobDataFromPublicURL(const GURL& url);
+
+ private:
+ friend class BlobDataHandle;
+ friend class BlobStorageHost;
+
+ typedef std::map<std::string, std::pair<int, scoped_refptr<BlobData> > >
+ BlobMap;
+ typedef std::map<GURL, std::string> BlobURLMap;
+
+ void StartBuildingBlob(const std::string& uuid);
+ void AppendBlobDataItem(const std::string& uuid,
+ const BlobData::Item& data_item);
+ void FinishBuildingBlob(const std::string& uuid, const std::string& type);
+ void CancelBuildingBlob(const std::string& uuid);
+ void AddFinishedBlob(const BlobData* blob_data);
+ void IncrementBlobRefCount(const std::string& uuid);
+ void DecrementBlobRefCount(const std::string& uuid);
+ void RegisterPublicBlobURL(const GURL& url, const std::string& uuid);
+ void RevokePublicBlobURL(const GURL& url);
+
void AppendStorageItems(BlobData* target_blob_data,
BlobData* src_blob_data,
uint64 offset,
uint64 length);
void AppendFileItem(BlobData* target_blob_data,
- const base::FilePath& file_path, uint64 offset,
- uint64 length,
+ const base::FilePath& file_path,
+ uint64 offset, uint64 length,
const base::Time& expected_modification_time);
void AppendFileSystemFileItem(
BlobData* target_blob_data,
const GURL& url, uint64 offset, uint64 length,
const base::Time& expected_modification_time);
- bool RemoveFromMapHelper(BlobMap* map, const GURL& url);
+ bool DecrementBlobRefCountHelper(BlobMap* map, const std::string& uuid);
- void IncrementBlobDataUsage(BlobData* blob_data);
- // Returns true if no longer in use.
- bool DecrementBlobDataUsage(BlobData* blob_data);
-
BlobMap blob_map_;
BlobMap unfinalized_blob_map_;
+ BlobURLMap public_blob_urls_;
// Used to keep track of how much memory is being utitlized for blob data,
// we count only the items of TYPE_DATA which are held in memory and not
// items of TYPE_FILE.
int64 memory_usage_;
- // Multiple urls can refer to the same blob data, this map keeps track of
- // how many urls refer to a BlobData.
- BlobDataUsageMap blob_data_usage_count_;
-
- DISALLOW_COPY_AND_ASSIGN(BlobStorageController);
+ DISALLOW_COPY_AND_ASSIGN(BlobStorageContext);
};
} // namespace webkit_blob
-#endif // WEBKIT_BLOB_BLOB_STORAGE_CONTROLLER_H_
+#endif // WEBKIT_BLOB_BLOB_STORAGE_CONTEXT_H_

Powered by Google App Engine
This is Rietveld 408576698