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 27 matching lines...) Expand all Loading... |
38 #include "base/json/json_writer.h" | 38 #include "base/json/json_writer.h" |
39 #include "base/location.h" | 39 #include "base/location.h" |
40 #include "base/metrics/field_trial.h" | 40 #include "base/metrics/field_trial.h" |
41 #include "base/single_thread_task_runner.h" | 41 #include "base/single_thread_task_runner.h" |
42 #include "base/stl_util.h" | 42 #include "base/stl_util.h" |
43 #include "base/strings/string_number_conversions.h" | 43 #include "base/strings/string_number_conversions.h" |
44 #include "base/strings/stringprintf.h" | 44 #include "base/strings/stringprintf.h" |
45 #include "base/threading/thread_task_runner_handle.h" | 45 #include "base/threading/thread_task_runner_handle.h" |
46 #include "base/values.h" | 46 #include "base/values.h" |
47 #include "chrome/browser/spellchecker/word_trimmer.h" | 47 #include "chrome/browser/spellchecker/word_trimmer.h" |
48 #include "chrome/common/spellcheck_common.h" | |
49 #include "chrome/common/spellcheck_marker.h" | |
50 #include "chrome/common/spellcheck_messages.h" | |
51 #include "components/data_use_measurement/core/data_use_user_data.h" | 48 #include "components/data_use_measurement/core/data_use_user_data.h" |
| 49 #include "components/spellcheck/common/spellcheck_common.h" |
| 50 #include "components/spellcheck/common/spellcheck_marker.h" |
| 51 #include "components/spellcheck/common/spellcheck_messages.h" |
52 #include "components/spellcheck/common/spellcheck_switches.h" | 52 #include "components/spellcheck/common/spellcheck_switches.h" |
53 #include "content/public/browser/render_process_host.h" | 53 #include "content/public/browser/render_process_host.h" |
54 #include "crypto/random.h" | 54 #include "crypto/random.h" |
55 #include "crypto/secure_hash.h" | 55 #include "crypto/secure_hash.h" |
56 #include "crypto/sha2.h" | 56 #include "crypto/sha2.h" |
57 #include "google_apis/google_api_keys.h" | 57 #include "google_apis/google_api_keys.h" |
58 #include "net/base/load_flags.h" | 58 #include "net/base/load_flags.h" |
59 #include "net/url_request/url_fetcher.h" | 59 #include "net/url_request/url_fetcher.h" |
60 #include "net/url_request/url_request_context_getter.h" | 60 #include "net/url_request/url_request_context_getter.h" |
61 | 61 |
(...skipping 30 matching lines...) Expand all Loading... |
92 uint64_t result; | 92 uint64_t result; |
93 hash->Finish(&result, sizeof(result)); | 93 hash->Finish(&result, sizeof(result)); |
94 return result; | 94 return result; |
95 } | 95 } |
96 | 96 |
97 // Returns a pending feedback data structure for the spellcheck |result| and | 97 // Returns a pending feedback data structure for the spellcheck |result| and |
98 // |text|. | 98 // |text|. |
99 Misspelling BuildFeedback(const SpellCheckResult& result, | 99 Misspelling BuildFeedback(const SpellCheckResult& result, |
100 const base::string16& text) { | 100 const base::string16& text) { |
101 size_t start = result.location; | 101 size_t start = result.location; |
102 base::string16 context = TrimWords(&start, | 102 base::string16 context = TrimWords(&start, start + result.length, text, |
103 start + result.length, | 103 spellcheck::kContextWordCount); |
104 text, | |
105 chrome::spellcheck_common::kContextWordCount); | |
106 return Misspelling(context, | 104 return Misspelling(context, |
107 start, | 105 start, |
108 result.length, | 106 result.length, |
109 std::vector<base::string16>(1, result.replacement), | 107 std::vector<base::string16>(1, result.replacement), |
110 result.hash); | 108 result.hash); |
111 } | 109 } |
112 | 110 |
113 // Builds suggestion info from |suggestions|. | 111 // Builds suggestion info from |suggestions|. |
114 std::unique_ptr<base::ListValue> BuildSuggestionInfo( | 112 std::unique_ptr<base::ListValue> BuildSuggestionInfo( |
115 const std::vector<Misspelling>& misspellings, | 113 const std::vector<Misspelling>& misspellings, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 return; | 272 return; |
275 misspelling->action.set_type(SpellcheckAction::TYPE_MANUALLY_CORRECTED); | 273 misspelling->action.set_type(SpellcheckAction::TYPE_MANUALLY_CORRECTED); |
276 misspelling->action.set_value(correction); | 274 misspelling->action.set_value(correction); |
277 misspelling->timestamp = base::Time::Now(); | 275 misspelling->timestamp = base::Time::Now(); |
278 } | 276 } |
279 | 277 |
280 void FeedbackSender::OnReceiveDocumentMarkers( | 278 void FeedbackSender::OnReceiveDocumentMarkers( |
281 int renderer_process_id, | 279 int renderer_process_id, |
282 const std::vector<uint32_t>& markers) { | 280 const std::vector<uint32_t>& markers) { |
283 if ((base::Time::Now() - session_start_).InHours() >= | 281 if ((base::Time::Now() - session_start_).InHours() >= |
284 chrome::spellcheck_common::kSessionHours) { | 282 spellcheck::kSessionHours) { |
285 FlushFeedback(); | 283 FlushFeedback(); |
286 return; | 284 return; |
287 } | 285 } |
288 | 286 |
289 if (!feedback_.RendererHasMisspellings(renderer_process_id)) | 287 if (!feedback_.RendererHasMisspellings(renderer_process_id)) |
290 return; | 288 return; |
291 | 289 |
292 feedback_.FinalizeRemovedMisspellings(renderer_process_id, markers); | 290 feedback_.FinalizeRemovedMisspellings(renderer_process_id, markers); |
293 SendFeedback(feedback_.GetMisspellingsInRenderer(renderer_process_id), | 291 SendFeedback(feedback_.GetMisspellingsInRenderer(renderer_process_id), |
294 !renderers_sent_feedback_.count(renderer_process_id)); | 292 !renderers_sent_feedback_.count(renderer_process_id)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 const std::string& country) { | 334 const std::string& country) { |
337 FlushFeedback(); | 335 FlushFeedback(); |
338 language_ = language; | 336 language_ = language; |
339 country_ = country; | 337 country_ = country; |
340 } | 338 } |
341 | 339 |
342 void FeedbackSender::StartFeedbackCollection() { | 340 void FeedbackSender::StartFeedbackCollection() { |
343 if (timer_.IsRunning()) | 341 if (timer_.IsRunning()) |
344 return; | 342 return; |
345 | 343 |
346 int interval_seconds = chrome::spellcheck_common::kFeedbackIntervalSeconds; | 344 int interval_seconds = spellcheck::kFeedbackIntervalSeconds; |
347 // This command-line switch is for testing and temporary. | 345 // This command-line switch is for testing and temporary. |
348 // TODO(rouslan): Remove the command-line switch when testing is complete. | 346 // TODO(rouslan): Remove the command-line switch when testing is complete. |
349 // http://crbug.com/247726 | 347 // http://crbug.com/247726 |
350 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 348 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
351 spellcheck::switches::kSpellingServiceFeedbackIntervalSeconds)) { | 349 spellcheck::switches::kSpellingServiceFeedbackIntervalSeconds)) { |
352 base::StringToInt( | 350 base::StringToInt( |
353 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 351 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
354 spellcheck::switches::kSpellingServiceFeedbackIntervalSeconds), | 352 spellcheck::switches::kSpellingServiceFeedbackIntervalSeconds), |
355 &interval_seconds); | 353 &interval_seconds); |
356 if (interval_seconds < kMinIntervalSeconds) | 354 if (interval_seconds < kMinIntervalSeconds) |
357 interval_seconds = kMinIntervalSeconds; | 355 interval_seconds = kMinIntervalSeconds; |
358 static const int kSessionSeconds = | 356 static const int kSessionSeconds = spellcheck::kSessionHours * 60 * 60; |
359 chrome::spellcheck_common::kSessionHours * 60 * 60; | |
360 if (interval_seconds > kSessionSeconds) | 357 if (interval_seconds > kSessionSeconds) |
361 interval_seconds = kSessionSeconds; | 358 interval_seconds = kSessionSeconds; |
362 } | 359 } |
363 timer_.Start(FROM_HERE, | 360 timer_.Start(FROM_HERE, |
364 base::TimeDelta::FromSeconds(interval_seconds), | 361 base::TimeDelta::FromSeconds(interval_seconds), |
365 this, | 362 this, |
366 &FeedbackSender::RequestDocumentMarkers); | 363 &FeedbackSender::RequestDocumentMarkers); |
367 } | 364 } |
368 | 365 |
369 void FeedbackSender::StopFeedbackCollection() { | 366 void FeedbackSender::StopFeedbackCollection() { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 senders_.push_back(sender); | 452 senders_.push_back(sender); |
456 | 453 |
457 // Request context is nullptr in testing. | 454 // Request context is nullptr in testing. |
458 if (request_context_.get()) { | 455 if (request_context_.get()) { |
459 sender->SetRequestContext(request_context_.get()); | 456 sender->SetRequestContext(request_context_.get()); |
460 sender->Start(); | 457 sender->Start(); |
461 } | 458 } |
462 } | 459 } |
463 | 460 |
464 } // namespace spellcheck | 461 } // namespace spellcheck |
OLD | NEW |