[email protected] | 890146b | 2014-04-10 13:59:11 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
tfarina | bccc34c7 | 2015-02-27 21:32:15 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_FILEAPI_BLOB_STORAGE_HOST_H_ |
6 | #define CONTENT_BROWSER_FILEAPI_BLOB_STORAGE_HOST_H_ | ||||
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 7 | |
8 | #include <map> | ||||
9 | #include <set> | ||||
10 | #include <string> | ||||
11 | |||||
12 | #include "base/compiler_specific.h" | ||||
13 | #include "base/memory/weak_ptr.h" | ||||
[email protected] | 890146b | 2014-04-10 13:59:11 | [diff] [blame] | 14 | #include "content/common/content_export.h" |
dmurph | bff2e53 | 2015-01-23 09:18:56 | [diff] [blame] | 15 | #include "storage/common/data_element.h" |
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 16 | |
17 | class GURL; | ||||
18 | |||||
[email protected] | cd501a7 | 2014-08-22 19:58:31 | [diff] [blame] | 19 | namespace storage { |
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 20 | class BlobDataHandle; |
21 | class BlobStorageHost; | ||||
22 | class BlobStorageContext; | ||||
[email protected] | 890146b | 2014-04-10 13:59:11 | [diff] [blame] | 23 | } |
24 | |||||
[email protected] | 890146b | 2014-04-10 13:59:11 | [diff] [blame] | 25 | namespace content { |
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 26 | |
27 | // This class handles the logistics of blob storage for a single child process. | ||||
28 | // There is one instance per child process. When the child process | ||||
29 | // terminates all blob references attibutable to that process go away upon | ||||
30 | // destruction of the instance. The class is single threaded and should | ||||
31 | // only be used on the IO thread. | ||||
[email protected] | 890146b | 2014-04-10 13:59:11 | [diff] [blame] | 32 | class CONTENT_EXPORT BlobStorageHost { |
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 33 | public: |
dmurph | bff2e53 | 2015-01-23 09:18:56 | [diff] [blame] | 34 | explicit BlobStorageHost(storage::BlobStorageContext* context); |
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 35 | ~BlobStorageHost(); |
36 | |||||
37 | // Methods to support the IPC message protocol. | ||||
38 | // A false return indicates a problem with the inputs | ||||
39 | // like a non-existent or pre-existent uuid or url. | ||||
40 | bool StartBuildingBlob(const std::string& uuid) WARN_UNUSED_RESULT; | ||||
41 | bool AppendBlobDataItem(const std::string& uuid, | ||||
dmurph | bff2e53 | 2015-01-23 09:18:56 | [diff] [blame] | 42 | const storage::DataElement& data_item) |
43 | WARN_UNUSED_RESULT; | ||||
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 44 | bool CancelBuildingBlob(const std::string& uuid) WARN_UNUSED_RESULT; |
45 | bool FinishBuildingBlob(const std::string& uuid, | ||||
46 | const std::string& type) WARN_UNUSED_RESULT; | ||||
47 | bool IncrementBlobRefCount(const std::string& uuid) WARN_UNUSED_RESULT; | ||||
48 | bool DecrementBlobRefCount(const std::string& uuid) WARN_UNUSED_RESULT; | ||||
49 | bool RegisterPublicBlobURL(const GURL& blob_url, | ||||
50 | const std::string& uuid) WARN_UNUSED_RESULT; | ||||
51 | bool RevokePublicBlobURL(const GURL& blob_url) WARN_UNUSED_RESULT; | ||||
52 | |||||
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 53 | private: |
54 | typedef std::map<std::string, int> BlobReferenceMap; | ||||
55 | |||||
56 | bool IsInUseInHost(const std::string& uuid); | ||||
57 | bool IsBeingBuiltInHost(const std::string& uuid); | ||||
58 | bool IsUrlRegisteredInHost(const GURL& blob_url); | ||||
59 | |||||
60 | // Collection of blob ids and a count of how many usages | ||||
61 | // of that id are attributable to this consumer. | ||||
62 | BlobReferenceMap blobs_inuse_map_; | ||||
63 | |||||
64 | // The set of public blob urls coined by this consumer. | ||||
65 | std::set<GURL> public_blob_urls_; | ||||
66 | |||||
dmurph | bff2e53 | 2015-01-23 09:18:56 | [diff] [blame] | 67 | base::WeakPtr<storage::BlobStorageContext> context_; |
[email protected] | 8438889 | 2013-09-07 04:20:18 | [diff] [blame] | 68 | |
69 | DISALLOW_COPY_AND_ASSIGN(BlobStorageHost); | ||||
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 70 | }; |
71 | |||||
[email protected] | 890146b | 2014-04-10 13:59:11 | [diff] [blame] | 72 | } // namespace content |
[email protected] | 23d951f | 2013-05-01 21:28:33 | [diff] [blame] | 73 | |
tfarina | bccc34c7 | 2015-02-27 21:32:15 | [diff] [blame] | 74 | #endif // CONTENT_BROWSER_FILEAPI_BLOB_STORAGE_HOST_H_ |