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

Side by Side Diff: third_party/WebKit/Source/core/loader/resource/ImageResourceContent.h

Issue 2746343002: Phase III Step 1: Make ImageResourceContent manage its own ResourceStatus (Closed)
Patch Set: Reflect comments Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 ImageResourceContent_h 5 #ifndef ImageResourceContent_h
6 #define ImageResourceContent_h 6 #define ImageResourceContent_h
7 7
8 #include <memory> 8 #include <memory>
9 #include "core/CoreExport.h" 9 #include "core/CoreExport.h"
10 #include "platform/geometry/IntRect.h" 10 #include "platform/geometry/IntRect.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 void AddObserver(ImageResourceObserver*); 87 void AddObserver(ImageResourceObserver*);
88 void RemoveObserver(ImageResourceObserver*); 88 void RemoveObserver(ImageResourceObserver*);
89 89
90 bool IsSizeAvailable() const { 90 bool IsSizeAvailable() const {
91 return size_available_ == Image::kSizeAvailable; 91 return size_available_ == Image::kSizeAvailable;
92 } 92 }
93 93
94 DECLARE_TRACE(); 94 DECLARE_TRACE();
95 95
96 // Content status and deriving predicates.
97 // https://docs.google.com/document/d/1O-fB83mrE0B_V8gzXNqHgmRLCvstTB4MMi3RnVL r8bE/edit#heading=h.6cyqmir0f30h
98 // Normal transitions:
99 // kNotStarted -> kPending -> kCached|kLoadError|kDecodeError.
100 // Additional transitions in multipart images:
101 // kCached -> kLoadError|kDecodeError.
102 // Transitions due to revalidation:
103 // kCached -> kPending.
104 // Transitions due to reload:
105 // kCached|kLoadError|kDecodeError -> kPending.
106 //
107 // ImageResourceContent::GetContentStatus() can be different from
108 // ImageResource::GetStatus(). Use ImageResourceContent::GetContentStatus().
109 ResourceStatus GetContentStatus() const;
110 bool IsLoaded() const;
111 bool IsLoading() const;
112 bool ErrorOccurred() const;
113 bool LoadFailedOrCanceled() const;
114
96 // Redirecting methods to Resource. 115 // Redirecting methods to Resource.
97 const KURL& Url() const; 116 const KURL& Url() const;
98 bool IsAccessAllowed(SecurityOrigin*); 117 bool IsAccessAllowed(SecurityOrigin*);
99 const ResourceResponse& GetResponse() const; 118 const ResourceResponse& GetResponse() const;
100 bool IsLoaded() const;
101 bool IsLoading() const;
102 bool ErrorOccurred() const;
103 bool LoadFailedOrCanceled() const;
104 ResourceStatus GetStatus() const;
105 const ResourceError& GetResourceError() const; 119 const ResourceError& GetResourceError() const;
106 120
107 // For FrameSerializer. 121 // For FrameSerializer.
108 bool HasCacheControlNoStoreHeader() const; 122 bool HasCacheControlNoStoreHeader() const;
109 123
110 void EmulateLoadStartedForInspector(ResourceFetcher*, 124 void EmulateLoadStartedForInspector(ResourceFetcher*,
111 const KURL&, 125 const KURL&,
112 const AtomicString& initiator_name); 126 const AtomicString& initiator_name);
113 127
114 void SetNotRefetchableDataFromDiskCache() { 128 void SetNotRefetchableDataFromDiskCache() {
(...skipping 20 matching lines...) Expand all
135 kClearImageAndNotifyObservers, 149 kClearImageAndNotifyObservers,
136 }; 150 };
137 enum class UpdateImageResult { 151 enum class UpdateImageResult {
138 kNoDecodeError, 152 kNoDecodeError,
139 153
140 // Decode error occurred. Observers are not notified. 154 // Decode error occurred. Observers are not notified.
141 // Only occurs when UpdateImage or ClearAndUpdateImage is specified. 155 // Only occurs when UpdateImage or ClearAndUpdateImage is specified.
142 kShouldDecodeError, 156 kShouldDecodeError,
143 }; 157 };
144 WARN_UNUSED_RESULT UpdateImageResult UpdateImage(PassRefPtr<SharedBuffer>, 158 WARN_UNUSED_RESULT UpdateImageResult UpdateImage(PassRefPtr<SharedBuffer>,
159 ResourceStatus,
145 UpdateImageOption, 160 UpdateImageOption,
146 bool all_data_received); 161 bool all_data_received);
147 162
163 void NotifyStartLoad();
148 void DestroyDecodedData(); 164 void DestroyDecodedData();
149 void DoResetAnimation(); 165 void DoResetAnimation();
150 166
151 void SetImageResourceInfo(ImageResourceInfo*); 167 void SetImageResourceInfo(ImageResourceInfo*);
152 168
153 ResourcePriority PriorityFromObservers() const; 169 ResourcePriority PriorityFromObservers() const;
154 PassRefPtr<const SharedBuffer> ResourceBuffer() const; 170 PassRefPtr<const SharedBuffer> ResourceBuffer() const;
155 bool ShouldUpdateImageImmediately() const; 171 bool ShouldUpdateImageImmediately() const;
156 bool HasObservers() const { 172 bool HasObservers() const {
157 return !observers_.IsEmpty() || !finished_observers_.IsEmpty(); 173 return !observers_.IsEmpty() || !finished_observers_.IsEmpty();
(...skipping 13 matching lines...) Expand all
171 187
172 PassRefPtr<Image> CreateImage(); 188 PassRefPtr<Image> CreateImage();
173 void ClearImage(); 189 void ClearImage();
174 190
175 enum NotifyFinishOption { kShouldNotifyFinish, kDoNotNotifyFinish }; 191 enum NotifyFinishOption { kShouldNotifyFinish, kDoNotNotifyFinish };
176 192
177 // If not null, changeRect is the changed part of the image. 193 // If not null, changeRect is the changed part of the image.
178 void NotifyObservers(NotifyFinishOption, 194 void NotifyObservers(NotifyFinishOption,
179 const IntRect* change_rect = nullptr); 195 const IntRect* change_rect = nullptr);
180 void MarkObserverFinished(ImageResourceObserver*); 196 void MarkObserverFinished(ImageResourceObserver*);
197 void UpdateToLoadedContentStatus(ResourceStatus);
181 198
182 class ProhibitAddRemoveObserverInScope : public AutoReset<bool> { 199 class ProhibitAddRemoveObserverInScope : public AutoReset<bool> {
183 public: 200 public:
184 ProhibitAddRemoveObserverInScope(const ImageResourceContent* content) 201 ProhibitAddRemoveObserverInScope(const ImageResourceContent* content)
185 : AutoReset(&content->is_add_remove_observer_prohibited_, true) {} 202 : AutoReset(&content->is_add_remove_observer_prohibited_, true) {}
186 }; 203 };
187 204
188 Member<ImageResourceInfo> info_; 205 Member<ImageResourceInfo> info_;
206 ResourceStatus content_status_ = ResourceStatus::kNotStarted;
189 207
190 RefPtr<blink::Image> image_; 208 RefPtr<blink::Image> image_;
191 209
192 HashCountedSet<ImageResourceObserver*> observers_; 210 HashCountedSet<ImageResourceObserver*> observers_;
193 HashCountedSet<ImageResourceObserver*> finished_observers_; 211 HashCountedSet<ImageResourceObserver*> finished_observers_;
194 212
195 Image::SizeAvailability size_available_ = Image::kSizeUnavailable; 213 Image::SizeAvailability size_available_ = Image::kSizeUnavailable;
196 214
197 // Indicates if this resource's encoded image data can be purged and refetched 215 // Indicates if this resource's encoded image data can be purged and refetched
198 // from disk cache to save memory usage. See crbug/664437. 216 // from disk cache to save memory usage. See crbug/664437.
199 bool is_refetchable_data_from_disk_cache_; 217 bool is_refetchable_data_from_disk_cache_;
200 218
201 mutable bool is_add_remove_observer_prohibited_ = false; 219 mutable bool is_add_remove_observer_prohibited_ = false;
202 220
203 #if DCHECK_IS_ON() 221 #if DCHECK_IS_ON()
204 bool is_update_image_being_called_ = false; 222 bool is_update_image_being_called_ = false;
205 #endif 223 #endif
206 }; 224 };
207 225
208 } // namespace blink 226 } // namespace blink
209 227
210 #endif 228 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698