1// Copyright (c) 2012 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. 4 5#ifndef CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ 6#define CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ 7 8#include "base/memory/ref_counted.h" 9#include "base/memory/scoped_ptr.h" 10#include "base/sequenced_task_runner_helpers.h" 11#include "content/common/content_export.h" 12 13namespace webkit_blob { 14class BlobStorageContext; 15} 16 17namespace content { 18class BlobHandle; 19class BrowserContext; 20struct ChromeBlobStorageContextDeleter; 21 22// A context class that keeps track of BlobStorageController used by the chrome. 23// There is an instance associated with each BrowserContext. There could be 24// multiple URLRequestContexts in the same browser context that refers to the 25// same instance. 26// 27// All methods, except the ctor, are expected to be called on 28// the IO thread (unless specifically called out in doc comments). 29class CONTENT_EXPORT ChromeBlobStorageContext 30 : public base::RefCountedThreadSafe<ChromeBlobStorageContext, 31 ChromeBlobStorageContextDeleter> { 32 public: 33 ChromeBlobStorageContext(); 34 35 static ChromeBlobStorageContext* GetFor( 36 BrowserContext* browser_context); 37 38 void InitializeOnIOThread(); 39 40 webkit_blob::BlobStorageContext* context() const { 41 return context_.get(); 42 } 43 44 // Returns a NULL scoped_ptr on failure. 45 scoped_ptr<BlobHandle> CreateMemoryBackedBlob(const char* data, 46 size_t length); 47 48 protected: 49 virtual ~ChromeBlobStorageContext(); 50 51 private: 52 friend class base::DeleteHelper<ChromeBlobStorageContext>; 53 friend class base::RefCountedThreadSafe<ChromeBlobStorageContext, 54 ChromeBlobStorageContextDeleter>; 55 friend struct ChromeBlobStorageContextDeleter; 56 57 void DeleteOnCorrectThread() const; 58 59 scoped_ptr<webkit_blob::BlobStorageContext> context_; 60}; 61 62struct ChromeBlobStorageContextDeleter { 63 static void Destruct(const ChromeBlobStorageContext* context) { 64 context->DeleteOnCorrectThread(); 65 } 66}; 67 68} // namespace content 69 70#endif // CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ 71