Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / xmlhttprequest / XMLHttpRequestProgressEventThrottle.h
blob3c17f0f2b6d7036dd620c47df477b56ba25632d6
1 /*
2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org>
3 * All right reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef XMLHttpRequestProgressEventThrottle_h
28 #define XMLHttpRequestProgressEventThrottle_h
30 #include "platform/Timer.h"
31 #include "platform/heap/Handle.h"
32 #include "wtf/Forward.h"
33 #include "wtf/OwnPtr.h"
34 #include "wtf/PassRefPtr.h"
36 namespace blink {
38 class Event;
39 class XMLHttpRequest;
41 // This class implements the XHR2 ProgressEvent dispatching:
42 // "dispatch a progress event named progress about every 50ms or for every
43 // byte received, whichever is least frequent".
45 // readystatechange events also go through this class since ProgressEvents and
46 // readystatechange events affect each other.
48 // In the comments for this class:
49 // - "progress" event means an event named "progress"
50 // - ProgressEvent means an event using the ProgressEvent interface defined in
51 // the spec.
52 class XMLHttpRequestProgressEventThrottle final : public GarbageCollectedFinalized<XMLHttpRequestProgressEventThrottle>, public TimerBase {
53 public:
54 static XMLHttpRequestProgressEventThrottle* create(XMLHttpRequest* eventTarget)
56 return new XMLHttpRequestProgressEventThrottle(eventTarget);
58 ~XMLHttpRequestProgressEventThrottle() override;
60 enum DeferredEventAction {
61 Ignore,
62 Clear,
63 Flush,
66 // Dispatches a ProgressEvent.
68 // Special treatment for events named "progress" is implemented to dispatch
69 // them at the required frequency. If this object is suspended, the given
70 // ProgressEvent overwrites the existing. I.e. only the latest one gets
71 // queued. If the timer is running, this method just updates
72 // m_lengthComputable, m_loaded and m_total. They'll be used on next
73 // fired() call.
74 void dispatchProgressEvent(const AtomicString&, bool lengthComputable, unsigned long long loaded, unsigned long long total);
75 // Dispatches the given event after operation about the "progress" event
76 // depending on the value of the ProgressEventAction argument.
77 void dispatchReadyStateChangeEvent(PassRefPtrWillBeRawPtr<Event>, DeferredEventAction);
79 void suspend();
80 void resume();
82 // Need to promptly stop this timer when it is deemed finalizable.
83 EAGERLY_FINALIZE();
84 DECLARE_TRACE();
86 private:
87 explicit XMLHttpRequestProgressEventThrottle(XMLHttpRequest*);
89 // The main purpose of this class is to throttle the "progress"
90 // ProgressEvent dispatching. This class represents such a deferred
91 // "progress" ProgressEvent.
92 class DeferredEvent;
93 static const double minimumProgressEventDispatchingIntervalInSeconds;
95 void fired() override;
96 void dispatchDeferredEvent();
98 // Non-Oilpan, keep a weak pointer to our XMLHttpRequest object as it is
99 // the one holding us. With Oilpan, a simple strong Member can be used -
100 // this XMLHttpRequestProgressEventThrottle (part) object dies together
101 // with the XMLHttpRequest object.
102 Member<XMLHttpRequest> m_target;
104 // A slot for the deferred "progress" ProgressEvent. When multiple events
105 // arrive, only the last one is stored and others are discarded.
106 const OwnPtr<DeferredEvent> m_deferred;
109 } // namespace blink
111 #endif // XMLHttpRequestProgressEventThrottle_h