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 13 namespace webkit_blob { 14 class BlobStorageController; 15 } 16 17 namespace content { 18 class BrowserContext; 19 struct ChromeBlobStorageContextDeleter; 20 21 // A context class that keeps track of BlobStorageController used by the chrome. 22 // There is an instance associated with each BrowserContext. There could be 23 // multiple URLRequestContexts in the same browser context that refers to the 24 // same instance. 25 // 26 // All methods, except the ctor, are expected to be called on 27 // the IO thread (unless specifically called out in doc comments). 28 class CONTENT_EXPORT ChromeBlobStorageContext 29 : public base::RefCountedThreadSafe<ChromeBlobStorageContext, 30 ChromeBlobStorageContextDeleter> { 31 public: 32 ChromeBlobStorageContext(); 33 34 static ChromeBlobStorageContext* GetFor( 35 BrowserContext* browser_context); 36 37 void InitializeOnIOThread(); 38 39 webkit_blob::BlobStorageController* controller() const { 40 return controller_.get(); 41 } 42 43 protected: 44 virtual ~ChromeBlobStorageContext(); 45 46 private: 47 friend class base::DeleteHelper<ChromeBlobStorageContext>; 48 friend class base::RefCountedThreadSafe<ChromeBlobStorageContext, 49 ChromeBlobStorageContextDeleter>; 50 friend struct ChromeBlobStorageContextDeleter; 51 52 void DeleteOnCorrectThread() const; 53 54 scoped_ptr<webkit_blob::BlobStorageController> controller_; 55 }; 56 57 struct ChromeBlobStorageContextDeleter { 58 static void Destruct(const ChromeBlobStorageContext* context) { 59 context->DeleteOnCorrectThread(); 60 } 61 }; 62 63 } // namespace content 64 65 #endif // CONTENT_BROWSER_FILEAPI_CHROME_BLOB_STORAGE_CONTEXT_H_ 66