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

Side by Side Diff: third_party/WebKit/Source/platform/PurgeableVector.h

Issue 2247073007: Make SharedBuffer in Resource non-discardable and remove PurgeableVector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SharedBuffer_DoNotUnlock
Patch Set: Rebase. Created 4 years, 3 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
(Empty)
1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #ifndef PurgeableVector_h
32 #define PurgeableVector_h
33
34 #include "platform/PlatformExport.h"
35 #include "wtf/Forward.h"
36 #include "wtf/Noncopyable.h"
37 #include "wtf/Vector.h"
38
39 #include <memory>
40
41 namespace base {
42 class DiscardableMemory;
43 }
44
45 namespace blink {
46
47 class WebProcessMemoryDump;
48
49 // A simple vector implementation that supports purgeable memory.
50 // TODO(hiroshige): PurgeableVector is about to be removed and some
51 // functionality has already been removed https://crbug.com/603791.
52 class PLATFORM_EXPORT PurgeableVector {
53 DISALLOW_NEW();
54 WTF_MAKE_NONCOPYABLE(PurgeableVector);
55 public:
56 enum PurgeableOption {
57 NotPurgeable,
58 Purgeable,
59 };
60
61 PurgeableVector(PurgeableOption = Purgeable);
62
63 ~PurgeableVector();
64
65 void adopt(Vector<char>& other);
66
67 void append(const char* data, size_t length);
68
69 void grow(size_t);
70
71 void clear();
72
73 char* data();
74
75 size_t size() const;
76
77 // Note that this method should be used carefully since it may not use
78 // exponential growth internally. This means that repeated/invalid uses of
79 // it can result in O(N^2) append(). If you don't exactly know what you are
80 // doing then you should probably not call this method.
81 void reserveCapacity(size_t capacity);
82
83 void onMemoryDump(const String& dumpPrefix, WebProcessMemoryDump*) const;
84
85 private:
86 enum PurgeableAllocationStrategy {
87 UseExactCapacity,
88 UseExponentialGrowth,
89 };
90
91 // Copies data from the discardable buffer to the vector and clears the
92 // discardable buffer.
93 void moveDataFromDiscardableToVector();
94
95 void clearDiscardable();
96
97 bool reservePurgeableCapacity(size_t capacity, PurgeableAllocationStrategy);
98
99 size_t adjustPurgeableCapacity(size_t capacity) const;
100
101 // Vector used when the instance is constructed without the purgeability
102 // hint or when discardable memory allocation fails.
103 // Note that there can't be data both in |m_vector| and
104 // |m_discardable|, i.e. only one of them is used at a given time.
105 Vector<char> m_vector;
106 std::unique_ptr<base::DiscardableMemory> m_discardable;
107 size_t m_discardableCapacity;
108 size_t m_discardableSize;
109 bool m_isPurgeable;
110 };
111
112 } // namespace blink
113
114 #endif // PurgeableVector_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/Resource.cpp ('k') | third_party/WebKit/Source/platform/PurgeableVector.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698