OLD | NEW |
---|---|
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 16 matching lines...) Expand all Loading... | |
27 | 27 |
28 #include "core/dom/Document.h" | 28 #include "core/dom/Document.h" |
29 #include "core/dom/Node.h" | 29 #include "core/dom/Node.h" |
30 #include "core/dom/TaskRunnerHelper.h" | 30 #include "core/dom/TaskRunnerHelper.h" |
31 #include "core/editing/EditingUtilities.h" | 31 #include "core/editing/EditingUtilities.h" |
32 #include "core/editing/markers/DocumentMarkerController.h" | 32 #include "core/editing/markers/DocumentMarkerController.h" |
33 #include "core/editing/spellcheck/SpellChecker.h" | 33 #include "core/editing/spellcheck/SpellChecker.h" |
34 #include "core/frame/LocalFrame.h" | 34 #include "core/frame/LocalFrame.h" |
35 #include "core/frame/Settings.h" | 35 #include "core/frame/Settings.h" |
36 #include "core/html/TextControlElement.h" | 36 #include "core/html/TextControlElement.h" |
37 #include "platform/Histogram.h" | |
37 #include "platform/text/TextCheckerClient.h" | 38 #include "platform/text/TextCheckerClient.h" |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
41 SpellCheckRequest::SpellCheckRequest(Range* checking_range, | 42 SpellCheckRequest::SpellCheckRequest(Range* checking_range, |
42 const String& text, | 43 const String& text, |
43 int request_number) | 44 int request_number) |
44 : requester_(nullptr), | 45 : requester_(nullptr), |
45 checking_range_(checking_range), | 46 checking_range_(checking_range), |
46 root_editable_element_( | 47 root_editable_element_( |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 DCHECK(!requester_); | 119 DCHECK(!requester_); |
119 DCHECK_EQ(request_data_.Sequence(), kUnrequestedTextCheckingSequence); | 120 DCHECK_EQ(request_data_.Sequence(), kUnrequestedTextCheckingSequence); |
120 requester_ = requester; | 121 requester_ = requester; |
121 request_data_.SetSequence(sequence); | 122 request_data_.SetSequence(sequence); |
122 } | 123 } |
123 | 124 |
124 SpellCheckRequester::SpellCheckRequester(LocalFrame& frame) | 125 SpellCheckRequester::SpellCheckRequester(LocalFrame& frame) |
125 : frame_(&frame), | 126 : frame_(&frame), |
126 last_request_sequence_(0), | 127 last_request_sequence_(0), |
127 last_processed_sequence_(0), | 128 last_processed_sequence_(0), |
129 last_request_time_(0.0), | |
128 timer_to_process_queued_request_( | 130 timer_to_process_queued_request_( |
129 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, &frame), | 131 TaskRunnerHelper::Get(TaskType::kUnspecedTimer, &frame), |
130 this, | 132 this, |
131 &SpellCheckRequester::TimerFiredToProcessQueuedRequest) {} | 133 &SpellCheckRequester::TimerFiredToProcessQueuedRequest) {} |
132 | 134 |
133 SpellCheckRequester::~SpellCheckRequester() {} | 135 SpellCheckRequester::~SpellCheckRequester() {} |
134 | 136 |
135 TextCheckerClient& SpellCheckRequester::Client() const { | 137 TextCheckerClient& SpellCheckRequester::Client() const { |
136 return GetFrame().GetSpellChecker().TextChecker(); | 138 return GetFrame().GetSpellChecker().TextChecker(); |
137 } | 139 } |
138 | 140 |
139 void SpellCheckRequester::TimerFiredToProcessQueuedRequest(TimerBase*) { | 141 void SpellCheckRequester::TimerFiredToProcessQueuedRequest(TimerBase*) { |
140 DCHECK(!request_queue_.IsEmpty()); | 142 DCHECK(!request_queue_.IsEmpty()); |
141 if (request_queue_.IsEmpty()) | 143 if (request_queue_.IsEmpty()) |
142 return; | 144 return; |
143 | 145 |
144 InvokeRequest(request_queue_.TakeFirst()); | 146 InvokeRequest(request_queue_.TakeFirst()); |
145 } | 147 } |
146 | 148 |
147 void SpellCheckRequester::RequestCheckingFor(const EphemeralRange& range) { | 149 void SpellCheckRequester::RequestCheckingFor(const EphemeralRange& range) { |
148 RequestCheckingFor(range, 0); | 150 RequestCheckingFor(range, 0); |
149 } | 151 } |
150 | 152 |
151 void SpellCheckRequester::RequestCheckingFor(const EphemeralRange& range, | 153 void SpellCheckRequester::RequestCheckingFor(const EphemeralRange& range, |
152 int request_num) { | 154 int request_num) { |
153 SpellCheckRequest* request = SpellCheckRequest::Create(range, request_num); | 155 SpellCheckRequest* request = SpellCheckRequest::Create(range, request_num); |
154 if (!request) | 156 if (!request) |
155 return; | 157 return; |
156 | 158 |
159 DEFINE_STATIC_LOCAL(CustomCountHistogram, | |
160 spell_checker_request_interval_histogram, | |
161 ("WebCore.SpellChecker.RequestInterval", 0, 10000, 50)); | |
162 double current_request_time = MonotonicallyIncreasingTime(); | |
yosin_UTC9
2017/05/12 04:33:34
nit: s/double/const double/
Xiaocheng
2017/05/12 18:35:14
Done.
| |
163 if (request_num == 0 && last_request_time_ > 0) { | |
164 double interval_ms = (current_request_time - last_request_time_) * 1000.0; | |
yosin_UTC9
2017/05/12 04:33:34
nit: s/double/const double/
Xiaocheng
2017/05/12 18:35:14
Done.
| |
165 spell_checker_request_interval_histogram.Count(interval_ms); | |
166 } | |
167 last_request_time_ = current_request_time; | |
168 | |
157 DCHECK_EQ(request->Data().Sequence(), kUnrequestedTextCheckingSequence); | 169 DCHECK_EQ(request->Data().Sequence(), kUnrequestedTextCheckingSequence); |
158 int sequence = ++last_request_sequence_; | 170 int sequence = ++last_request_sequence_; |
159 if (sequence == kUnrequestedTextCheckingSequence) | 171 if (sequence == kUnrequestedTextCheckingSequence) |
160 sequence = ++last_request_sequence_; | 172 sequence = ++last_request_sequence_; |
161 | 173 |
162 request->SetCheckerAndSequence(this, sequence); | 174 request->SetCheckerAndSequence(this, sequence); |
163 | 175 |
164 if (timer_to_process_queued_request_.IsActive() || processing_request_) { | 176 if (timer_to_process_queued_request_.IsActive() || processing_request_) { |
165 EnqueueRequest(request); | 177 EnqueueRequest(request); |
166 return; | 178 return; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 DidCheck(sequence, results); | 289 DidCheck(sequence, results); |
278 } | 290 } |
279 | 291 |
280 DEFINE_TRACE(SpellCheckRequester) { | 292 DEFINE_TRACE(SpellCheckRequester) { |
281 visitor->Trace(frame_); | 293 visitor->Trace(frame_); |
282 visitor->Trace(processing_request_); | 294 visitor->Trace(processing_request_); |
283 visitor->Trace(request_queue_); | 295 visitor->Trace(request_queue_); |
284 } | 296 } |
285 | 297 |
286 } // namespace blink | 298 } // namespace blink |
OLD | NEW |