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

Side by Side Diff: third_party/WebKit/Source/core/dom/PendingScript.h

Issue 2828193003: Explicitly track the lifecycle of PendingScript. (Closed)
Patch Set: document, and replace watching_for_load_ Created 3 years, 8 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 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void MarkParserBlockingLoadStartTime(); 83 void MarkParserBlockingLoadStartTime();
84 // Returns the time the load of this script started blocking the parser, or 84 // Returns the time the load of this script started blocking the parser, or
85 // zero if this script hasn't yet blocked the parser, in 85 // zero if this script hasn't yet blocked the parser, in
86 // monotonicallyIncreasingTime. 86 // monotonicallyIncreasingTime.
87 double ParserBlockingLoadStartTime() const { 87 double ParserBlockingLoadStartTime() const {
88 return parser_blocking_load_start_time_; 88 return parser_blocking_load_start_time_;
89 } 89 }
90 90
91 void WatchForLoad(PendingScriptClient*); 91 void WatchForLoad(PendingScriptClient*);
92 void StopWatchingForLoad(); 92 void StopWatchingForLoad();
93 bool WatchingForLoad() const { return client_; }
93 94
94 ScriptElementBase* GetElement() const; 95 ScriptElementBase* GetElement() const;
95 96
96 DECLARE_TRACE(); 97 DECLARE_TRACE();
97 98
98 ClassicScript* GetSource(const KURL& document_url, 99 ClassicScript* GetSource(const KURL& document_url,
99 bool& error_occurred) const; 100 bool& error_occurred) const;
100 101
101 void SetStreamer(ScriptStreamer*); 102 void SetStreamer(ScriptStreamer*);
102 void StreamingFinished(); 103 void StreamingFinished();
103 104
104 bool IsReady() const; 105 bool IsReady() const {
105 bool ErrorOccurred() const; 106 CheckState();
107 return ready_state_ >= kReady;
108 }
109 bool ErrorOccurred() const {
110 CheckState();
111 return ready_state_ == kErrorOccurred;
112 }
106 113
107 void StartStreamingIfPossible(Document*, ScriptStreamer::Type); 114 void StartStreamingIfPossible(Document*, ScriptStreamer::Type);
108 void Dispose(); 115 void Dispose();
109 116
110 private: 117 private:
111 PendingScript(ScriptElementBase*, 118 PendingScript(ScriptElementBase*,
112 ScriptResource*, 119 ScriptResource*,
113 const TextPosition&, 120 const TextPosition&,
114 bool is_for_testing = false); 121 bool is_for_testing = false);
115 PendingScript() = delete; 122 PendingScript() = delete;
116 123
117 void CheckState() const; 124 void CheckState() const;
118 125
119 // ScriptResourceClient 126 // ScriptResourceClient
120 void NotifyFinished(Resource*) override; 127 void NotifyFinished(Resource*) override;
121 String DebugName() const override { return "PendingScript"; } 128 String DebugName() const override { return "PendingScript"; }
122 void NotifyAppendData(ScriptResource*) override; 129 void NotifyAppendData(ScriptResource*) override;
123 130
124 // MemoryCoordinatorClient 131 // MemoryCoordinatorClient
125 void OnPurgeMemory() override; 132 void OnPurgeMemory() override;
126 133
127 bool watching_for_load_; 134 enum ReadyState {
135 // These states are considered "not ready".
136 kWaitingForResource,
137 kWaitingForStreaming,
138 // These states are considered "ready".
139 kReady,
140 kErrorOccurred,
141 };
142
143 // Advances the current state of the script, reporting to the client is
hiroshige 2017/04/24 19:16:53 nit: reporting to the client *if*?
jbroman 2017/05/01 15:08:02 Done.
144 // appropriate.
145 void AdvanceReadyState(ReadyState);
146
147 ReadyState ready_state_;
128 148
129 // |m_element| must points to the corresponding ScriptLoader's 149 // |m_element| must points to the corresponding ScriptLoader's
130 // ScriptElementBase and thus must be non-null before dispose() is called 150 // ScriptElementBase and thus must be non-null before dispose() is called
131 // (except for unit tests). 151 // (except for unit tests).
132 Member<ScriptElementBase> element_; 152 Member<ScriptElementBase> element_;
133 153
134 TextPosition starting_position_; // Only used for inline script tags. 154 TextPosition starting_position_; // Only used for inline script tags.
135 bool integrity_failure_; 155 bool integrity_failure_;
136 double parser_blocking_load_start_time_; 156 double parser_blocking_load_start_time_;
137 157
138 Member<ScriptStreamer> streamer_; 158 Member<ScriptStreamer> streamer_;
139 Member<PendingScriptClient> client_; 159 Member<PendingScriptClient> client_;
140 160
141 // This flag is used to skip non-null checks of |m_element| in unit 161 // This flag is used to skip non-null checks of |m_element| in unit
142 // tests, because |m_element| can be null in unit tests. 162 // tests, because |m_element| can be null in unit tests.
143 const bool is_for_testing_; 163 const bool is_for_testing_;
144 }; 164 };
145 165
146 } // namespace blink 166 } // namespace blink
147 167
148 #endif // PendingScript_h 168 #endif // PendingScript_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698