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

Side by Side Diff: Source/core/xmlhttprequest/XMLHttpRequestProgressEventThrottle.h

Issue 1200413004: Oilpan: make XHR progress event throttling finalization safe. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move XMLHttpRequestProgressEventThrottle to the heap instead Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/xmlhttprequest/XMLHttpRequest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org> 2 * Copyright (C) 2010 Julien Chaffraix <jchaffraix@webkit.org>
3 * All right reserved. 3 * All right reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // "dispatch a progress event named progress about every 50ms or for every 42 // "dispatch a progress event named progress about every 50ms or for every
43 // byte received, whichever is least frequent". 43 // byte received, whichever is least frequent".
44 // 44 //
45 // readystatechange events also go through this class since ProgressEvents and 45 // readystatechange events also go through this class since ProgressEvents and
46 // readystatechange events affect each other. 46 // readystatechange events affect each other.
47 // 47 //
48 // In the comments for this class: 48 // In the comments for this class:
49 // - "progress" event means an event named "progress" 49 // - "progress" event means an event named "progress"
50 // - ProgressEvent means an event using the ProgressEvent interface defined in 50 // - ProgressEvent means an event using the ProgressEvent interface defined in
51 // the spec. 51 // the spec.
52 class XMLHttpRequestProgressEventThrottle final : public TimerBase { 52 class XMLHttpRequestProgressEventThrottle final : public NoBaseWillBeGarbageColl ectedFinalized<XMLHttpRequestProgressEventThrottle>, public TimerBase {
53 DISALLOW_ALLOCATION();
54 public: 53 public:
54 static PassOwnPtrWillBeRawPtr<XMLHttpRequestProgressEventThrottle> create(Ev entTarget* eventTarget)
55 {
56 return adoptPtrWillBeNoop(new XMLHttpRequestProgressEventThrottle(eventT arget));
57 }
58 virtual ~XMLHttpRequestProgressEventThrottle();
59
55 enum DeferredEventAction { 60 enum DeferredEventAction {
56 Ignore, 61 Ignore,
57 Clear, 62 Clear,
58 Flush, 63 Flush,
59 }; 64 };
60 65
61 explicit XMLHttpRequestProgressEventThrottle(EventTarget*);
62 virtual ~XMLHttpRequestProgressEventThrottle();
63
64 // Dispatches a ProgressEvent. 66 // Dispatches a ProgressEvent.
65 // 67 //
66 // Special treatment for events named "progress" is implemented to dispatch 68 // Special treatment for events named "progress" is implemented to dispatch
67 // them at the required frequency. If this object is suspended, the given 69 // them at the required frequency. If this object is suspended, the given
68 // ProgressEvent overwrites the existing. I.e. only the latest one gets 70 // ProgressEvent overwrites the existing. I.e. only the latest one gets
69 // queued. If the timer is running, this method just updates 71 // queued. If the timer is running, this method just updates
70 // m_lengthComputable, m_loaded and m_total. They'll be used on next 72 // m_lengthComputable, m_loaded and m_total. They'll be used on next
71 // fired() call. 73 // fired() call.
72 void dispatchProgressEvent(const AtomicString&, bool lengthComputable, unsig ned long long loaded, unsigned long long total); 74 void dispatchProgressEvent(const AtomicString&, bool lengthComputable, unsig ned long long loaded, unsigned long long total);
73 // Dispatches the given event after operation about the "progress" event 75 // Dispatches the given event after operation about the "progress" event
74 // depending on the value of the ProgressEventAction argument. 76 // depending on the value of the ProgressEventAction argument.
75 void dispatchReadyStateChangeEvent(PassRefPtrWillBeRawPtr<Event>, DeferredEv entAction); 77 void dispatchReadyStateChangeEvent(PassRefPtrWillBeRawPtr<Event>, DeferredEv entAction);
76 78
77 void suspend(); 79 void suspend();
78 void resume(); 80 void resume();
79 81
82 // Need to promptly stop this timer when it is deemed finalizable.
83 EAGERLY_FINALIZE();
80 DECLARE_TRACE(); 84 DECLARE_TRACE();
81 85
82 private: 86 private:
87 explicit XMLHttpRequestProgressEventThrottle(EventTarget*);
88
83 // The main purpose of this class is to throttle the "progress" 89 // The main purpose of this class is to throttle the "progress"
84 // ProgressEvent dispatching. This class represents such a deferred 90 // ProgressEvent dispatching. This class represents such a deferred
85 // "progress" ProgressEvent. 91 // "progress" ProgressEvent.
86 class DeferredEvent; 92 class DeferredEvent;
87 static const double minimumProgressEventDispatchingIntervalInSeconds; 93 static const double minimumProgressEventDispatchingIntervalInSeconds;
88 94
89 virtual void fired() override; 95 virtual void fired() override;
90 void dispatchDeferredEvent(); 96 void dispatchDeferredEvent();
91 97
92 // Non-Oilpan, keep a weak pointer to our XMLHttpRequest object as it is 98 // Non-Oilpan, keep a weak pointer to our XMLHttpRequest object as it is
93 // the one holding us. With Oilpan, a simple strong Member can be used - 99 // the one holding us. With Oilpan, a simple strong Member can be used -
94 // this XMLHttpRequestProgressEventThrottle (part) object dies together 100 // this XMLHttpRequestProgressEventThrottle (part) object dies together
95 // with the XMLHttpRequest object. 101 // with the XMLHttpRequest object.
96 RawPtrWillBeMember<EventTarget> m_target; 102 RawPtrWillBeMember<EventTarget> m_target;
97 103
98 // A slot for the deferred "progress" ProgressEvent. When multiple events 104 // A slot for the deferred "progress" ProgressEvent. When multiple events
99 // arrive, only the last one is stored and others are discarded. 105 // arrive, only the last one is stored and others are discarded.
100 const OwnPtr<DeferredEvent> m_deferred; 106 const OwnPtr<DeferredEvent> m_deferred;
101 }; 107 };
102 108
103 } // namespace blink 109 } // namespace blink
104 110
105 #endif // XMLHttpRequestProgressEventThrottle_h 111 #endif // XMLHttpRequestProgressEventThrottle_h
OLDNEW
« no previous file with comments | « Source/core/xmlhttprequest/XMLHttpRequest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698