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

Side by Side Diff: storage/browser/blob/blob_storage_registry.h

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: comments/fixes Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/containers/scoped_ptr_hash_map.h" 15 #include "base/containers/scoped_ptr_hash_map.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/scoped_ptr.h"
17 #include "storage/browser/blob/internal_blob_data.h" 18 #include "storage/browser/blob/internal_blob_data.h"
18 #include "storage/browser/storage_browser_export.h" 19 #include "storage/browser/storage_browser_export.h"
20 #include "storage/common/blob_storage/blob_storage_constants.h"
19 21
20 class GURL; 22 class GURL;
21 23
22 namespace storage { 24 namespace storage {
23 25
24 // This class stores the blob data in the various states of construction, as 26 // This class stores the blob data in the various states of construction, as
25 // well as URL mappings to blob uuids. 27 // well as URL mappings to blob uuids.
26 // Implementation notes: 28 // Implementation notes:
27 // * There is no implicit refcounting in this class, except for setting the 29 // * There is no implicit refcounting in this class, except for setting the
28 // refcount to 1 on registration. 30 // refcount to 1 on registration.
29 // * When removing a uuid registration, we do not check for URL mappings to that 31 // * When removing a uuid registration, we do not check for URL mappings to that
30 // uuid. The user must keep track of these. 32 // uuid. The user must keep track of these.
31 class STORAGE_EXPORT BlobStorageRegistry { 33 class STORAGE_EXPORT BlobStorageRegistry {
32 public: 34 public:
33 enum class BlobState { 35 enum class BlobState {
34 // First the renderer reserves the uuid. 36 // The blob is pending transportation from the renderer.
35 RESERVED = 1, 37 PENDING,
36 // Second, we are asynchronously transporting data to the browser. 38 // The blob is complete and can be read from.
37 ASYNC_TRANSPORTATION, 39 COMPLETE,
38 // Third, we construct the blob when we have all of the data. 40 // The blob is broken and no longer holds data. This happens when there was
39 CONSTRUCTION, 41 // a problem constructing the blob, or we've run out of memory.
40 // Finally, the blob is built. 42 BROKEN
41 ACTIVE
42 }; 43 };
43 44
44 struct STORAGE_EXPORT Entry { 45 struct STORAGE_EXPORT Entry {
45 size_t refcount; 46 size_t refcount;
46 BlobState state; 47 BlobState state;
47 std::vector<base::Callback<void(bool)>> construction_complete_callbacks; 48 std::vector<base::Callback<void(bool)>> build_completion_callbacks;
48 49
49 // Flags 50 // Only applicable if the state == BROKEN.
50 bool exceeded_memory; 51 IPCBlobCreationCancelCode broken_reason =
52 IPCBlobCreationCancelCode::UNKNOWN;
51 53
52 // data and data_builder are mutually exclusive. 54 // data and data_builder are mutually exclusive.
53 scoped_ptr<InternalBlobData> data; 55 scoped_ptr<InternalBlobData> data;
54 scoped_ptr<InternalBlobData::Builder> data_builder; 56 scoped_ptr<InternalBlobData::Builder> data_builder;
55 57
58 std::string content_type;
59 std::string content_disposition;
60
56 Entry() = delete; 61 Entry() = delete;
57 Entry(int refcount, BlobState state); 62 Entry(int refcount, BlobState state);
58 ~Entry(); 63 ~Entry();
59 64
60 // Performs a test-and-set on the state of the given blob. If the state 65 // Performs a test-and-set on the state of the given blob. If the state
61 // isn't as expected, we return false. Otherwise we set the new state and 66 // isn't as expected, we return false. Otherwise we set the new state and
62 // return true. 67 // return true.
63 bool TestAndSetState(BlobState expected, BlobState set); 68 bool TestAndSetState(BlobState expected, BlobState set);
64 }; 69 };
65 70
66 BlobStorageRegistry(); 71 BlobStorageRegistry();
67 ~BlobStorageRegistry(); 72 ~BlobStorageRegistry();
68 73
69 // Creates the blob entry with a refcount of 1 and a state of RESERVED. If 74 // Creates the blob entry with a refcount of 1 and a state of RESERVED. If
70 // the blob is already in use, we return null. 75 // the blob is already in use, we return null.
71 Entry* CreateEntry(const std::string& uuid); 76 Entry* CreateEntry(const std::string& uuid);
72 77
73 // Removes the blob entry with the given uuid. This does not unmap any 78 // Removes the blob entry with the given uuid. This does not unmap any
74 // URLs that are pointing to this uuid. Returns if the entry existed. 79 // URLs that are pointing to this uuid. Returns if the entry existed.
75 bool DeleteEntry(const std::string& uuid); 80 bool DeleteEntry(const std::string& uuid);
76 81
82 bool HasEntry(const std::string& uuid) const;
83
77 // Gets the blob entry for the given uuid. Returns nullptr if the entry 84 // Gets the blob entry for the given uuid. Returns nullptr if the entry
78 // does not exist. 85 // does not exist.
79 Entry* GetEntry(const std::string& uuid); 86 Entry* GetEntry(const std::string& uuid);
87 const Entry* GetEntry(const std::string& uuid) const;
80 88
81 // Creates a url mapping from blob uuid to the given url. Returns false if 89 // Creates a url mapping from blob uuid to the given url. Returns false if
82 // the uuid isn't mapped to an entry or if there already is a map for the URL. 90 // the uuid isn't mapped to an entry or if there already is a map for the URL.
83 bool CreateUrlMapping(const GURL& url, const std::string& uuid); 91 bool CreateUrlMapping(const GURL& url, const std::string& uuid);
84 92
85 // Removes the given URL mapping. Optionally populates a uuid string of the 93 // Removes the given URL mapping. Optionally populates a uuid string of the
86 // removed entry uuid. Returns false if the url isn't mapped. 94 // removed entry uuid. Returns false if the url isn't mapped.
87 bool DeleteURLMapping(const GURL& url, std::string* uuid); 95 bool DeleteURLMapping(const GURL& url, std::string* uuid);
88 96
89 // Returns if the url is mapped to a blob uuid. 97 // Returns if the url is mapped to a blob uuid.
90 bool IsURLMapped(const GURL& blob_url) const; 98 bool IsURLMapped(const GURL& blob_url) const;
91 99
92 // Returns the entry from the given url, and optionally populates the uuid for 100 // Returns the entry from the given url, and optionally populates the uuid for
93 // that entry. Returns a nullptr if the mapping or entry doesn't exist. 101 // that entry. Returns a nullptr if the mapping or entry doesn't exist.
94 Entry* GetEntryFromURL(const GURL& url, std::string* uuid); 102 Entry* GetEntryFromURL(const GURL& url, std::string* uuid);
95 103
96 size_t blob_count() const { return blob_map_.size(); } 104 size_t blob_count() const { return blob_map_.size(); }
97 size_t url_count() const { return url_to_uuid_.size(); } 105 size_t url_count() const { return url_to_uuid_.size(); }
98 106
99 private: 107 private:
108 friend class ViewBlobInternalsJob;
100 using BlobMap = base::ScopedPtrHashMap<std::string, scoped_ptr<Entry>>; 109 using BlobMap = base::ScopedPtrHashMap<std::string, scoped_ptr<Entry>>;
101 using URLMap = std::map<GURL, std::string>; 110 using URLMap = std::map<GURL, std::string>;
102 111
103 BlobMap blob_map_; 112 BlobMap blob_map_;
104 URLMap url_to_uuid_; 113 URLMap url_to_uuid_;
105 114
106 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry); 115 DISALLOW_COPY_AND_ASSIGN(BlobStorageRegistry);
107 }; 116 };
108 117
109 } // namespace storage 118 } // namespace storage
110 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_ 119 #endif // STORAGE_BROWSER_BLOB_BLOB_STORAGE_REGISTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698