OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // The |FeedbackSender| object stores the user feedback to spellcheck | 5 // The |FeedbackSender| object stores the user feedback to spellcheck |
6 // suggestions in a |Feedback| object. | 6 // suggestions in a |Feedback| object. |
7 // | 7 // |
8 // When spelling service returns spellcheck results, these results first arrive | 8 // When spelling service returns spellcheck results, these results first arrive |
9 // in |FeedbackSender| to assign hash identifiers for each | 9 // in |FeedbackSender| to assign hash identifiers for each |
10 // misspelling-suggestion pair. If the spelling service identifies the same | 10 // misspelling-suggestion pair. If the spelling service identifies the same |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 static_cast<size_t>(misspelling_location + misspelling_length) <= | 138 static_cast<size_t>(misspelling_location + misspelling_length) <= |
139 text_length; | 139 text_length; |
140 } | 140 } |
141 | 141 |
142 // Returns the feedback API version. | 142 // Returns the feedback API version. |
143 std::string GetApiVersion() { | 143 std::string GetApiVersion() { |
144 // This guard is temporary. | 144 // This guard is temporary. |
145 // TODO(rouslan): Remove the guard. http://crbug.com/247726 | 145 // TODO(rouslan): Remove the guard. http://crbug.com/247726 |
146 if (base::FieldTrialList::FindFullName(kFeedbackFieldTrialName) == | 146 if (base::FieldTrialList::FindFullName(kFeedbackFieldTrialName) == |
147 kFeedbackFieldTrialEnabledGroupName && | 147 kFeedbackFieldTrialEnabledGroupName && |
148 CommandLine::ForCurrentProcess()->HasSwitch( | 148 base::CommandLine::ForCurrentProcess()->HasSwitch( |
149 switches::kEnableSpellingFeedbackFieldTrial)) { | 149 switches::kEnableSpellingFeedbackFieldTrial)) { |
150 return "v2-internal"; | 150 return "v2-internal"; |
151 } | 151 } |
152 return "v2"; | 152 return "v2"; |
153 } | 153 } |
154 | 154 |
155 } // namespace | 155 } // namespace |
156 | 156 |
157 FeedbackSender::FeedbackSender(net::URLRequestContextGetter* request_context, | 157 FeedbackSender::FeedbackSender(net::URLRequestContextGetter* request_context, |
158 const std::string& language, | 158 const std::string& language, |
159 const std::string& country) | 159 const std::string& country) |
160 : request_context_(request_context), | 160 : request_context_(request_context), |
161 api_version_(GetApiVersion()), | 161 api_version_(GetApiVersion()), |
162 language_(language), | 162 language_(language), |
163 country_(country), | 163 country_(country), |
164 misspelling_counter_(0), | 164 misspelling_counter_(0), |
165 session_start_(base::Time::Now()), | 165 session_start_(base::Time::Now()), |
166 feedback_service_url_(kFeedbackServiceURL) { | 166 feedback_service_url_(kFeedbackServiceURL) { |
167 // The command-line switch is for testing and temporary. | 167 // The command-line switch is for testing and temporary. |
168 // TODO(rouslan): Remove the command-line switch when testing is complete. | 168 // TODO(rouslan): Remove the command-line switch when testing is complete. |
169 // http://crbug.com/247726 | 169 // http://crbug.com/247726 |
170 if (CommandLine::ForCurrentProcess()->HasSwitch( | 170 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
171 switches::kSpellingServiceFeedbackUrl)) { | 171 switches::kSpellingServiceFeedbackUrl)) { |
172 feedback_service_url_ = | 172 feedback_service_url_ = |
173 GURL(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 173 GURL(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
174 switches::kSpellingServiceFeedbackUrl)); | 174 switches::kSpellingServiceFeedbackUrl)); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 FeedbackSender::~FeedbackSender() { | 178 FeedbackSender::~FeedbackSender() { |
179 } | 179 } |
180 | 180 |
181 void FeedbackSender::SelectedSuggestion(uint32 hash, int suggestion_index) { | 181 void FeedbackSender::SelectedSuggestion(uint32 hash, int suggestion_index) { |
182 Misspelling* misspelling = feedback_.GetMisspelling(hash); | 182 Misspelling* misspelling = feedback_.GetMisspelling(hash); |
183 // GetMisspelling() returns null for flushed feedback. Feedback is flushed | 183 // GetMisspelling() returns null for flushed feedback. Feedback is flushed |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 void FeedbackSender::StartFeedbackCollection() { | 309 void FeedbackSender::StartFeedbackCollection() { |
310 if (timer_.IsRunning()) | 310 if (timer_.IsRunning()) |
311 return; | 311 return; |
312 | 312 |
313 int interval_seconds = chrome::spellcheck_common::kFeedbackIntervalSeconds; | 313 int interval_seconds = chrome::spellcheck_common::kFeedbackIntervalSeconds; |
314 // This command-line switch is for testing and temporary. | 314 // This command-line switch is for testing and temporary. |
315 // TODO(rouslan): Remove the command-line switch when testing is complete. | 315 // TODO(rouslan): Remove the command-line switch when testing is complete. |
316 // http://crbug.com/247726 | 316 // http://crbug.com/247726 |
317 if (CommandLine::ForCurrentProcess()->HasSwitch( | 317 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
318 switches::kSpellingServiceFeedbackIntervalSeconds)) { | 318 switches::kSpellingServiceFeedbackIntervalSeconds)) { |
319 base::StringToInt(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 319 base::StringToInt( |
320 switches::kSpellingServiceFeedbackIntervalSeconds), | 320 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
321 &interval_seconds); | 321 switches::kSpellingServiceFeedbackIntervalSeconds), |
| 322 &interval_seconds); |
322 if (interval_seconds < kMinIntervalSeconds) | 323 if (interval_seconds < kMinIntervalSeconds) |
323 interval_seconds = kMinIntervalSeconds; | 324 interval_seconds = kMinIntervalSeconds; |
324 static const int kSessionSeconds = | 325 static const int kSessionSeconds = |
325 chrome::spellcheck_common::kSessionHours * 60 * 60; | 326 chrome::spellcheck_common::kSessionHours * 60 * 60; |
326 if (interval_seconds > kSessionSeconds) | 327 if (interval_seconds > kSessionSeconds) |
327 interval_seconds = kSessionSeconds; | 328 interval_seconds = kSessionSeconds; |
328 } | 329 } |
329 timer_.Start(FROM_HERE, | 330 timer_.Start(FROM_HERE, |
330 base::TimeDelta::FromSeconds(interval_seconds), | 331 base::TimeDelta::FromSeconds(interval_seconds), |
331 this, | 332 this, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 senders_.push_back(sender); | 415 senders_.push_back(sender); |
415 | 416 |
416 // Request context is NULL in testing. | 417 // Request context is NULL in testing. |
417 if (request_context_.get()) { | 418 if (request_context_.get()) { |
418 sender->SetRequestContext(request_context_.get()); | 419 sender->SetRequestContext(request_context_.get()); |
419 sender->Start(); | 420 sender->Start(); |
420 } | 421 } |
421 } | 422 } |
422 | 423 |
423 } // namespace spellcheck | 424 } // namespace spellcheck |
OLD | NEW |