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 17 matching lines...) Expand all Loading... |
28 // spelling service. | 28 // spelling service. |
29 | 29 |
30 #include "chrome/browser/spellchecker/feedback_sender.h" | 30 #include "chrome/browser/spellchecker/feedback_sender.h" |
31 | 31 |
32 #include <algorithm> | 32 #include <algorithm> |
33 #include <iterator> | 33 #include <iterator> |
34 | 34 |
35 #include "base/command_line.h" | 35 #include "base/command_line.h" |
36 #include "base/hash.h" | 36 #include "base/hash.h" |
37 #include "base/json/json_writer.h" | 37 #include "base/json/json_writer.h" |
| 38 #include "base/location.h" |
38 #include "base/metrics/field_trial.h" | 39 #include "base/metrics/field_trial.h" |
| 40 #include "base/single_thread_task_runner.h" |
39 #include "base/stl_util.h" | 41 #include "base/stl_util.h" |
40 #include "base/strings/string_number_conversions.h" | 42 #include "base/strings/string_number_conversions.h" |
41 #include "base/strings/stringprintf.h" | 43 #include "base/strings/stringprintf.h" |
| 44 #include "base/thread_task_runner_handle.h" |
42 #include "base/values.h" | 45 #include "base/values.h" |
43 #include "chrome/browser/spellchecker/word_trimmer.h" | 46 #include "chrome/browser/spellchecker/word_trimmer.h" |
44 #include "chrome/common/chrome_switches.h" | 47 #include "chrome/common/chrome_switches.h" |
45 #include "chrome/common/spellcheck_common.h" | 48 #include "chrome/common/spellcheck_common.h" |
46 #include "chrome/common/spellcheck_marker.h" | 49 #include "chrome/common/spellcheck_marker.h" |
47 #include "chrome/common/spellcheck_messages.h" | 50 #include "chrome/common/spellcheck_messages.h" |
48 #include "content/public/browser/render_process_host.h" | 51 #include "content/public/browser/render_process_host.h" |
49 #include "google_apis/google_api_keys.h" | 52 #include "google_apis/google_api_keys.h" |
50 #include "net/base/load_flags.h" | 53 #include "net/base/load_flags.h" |
51 #include "net/url_request/url_fetcher.h" | 54 #include "net/url_request/url_fetcher.h" |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Asynchronously send out the feedback for all the renderers that are no | 370 // Asynchronously send out the feedback for all the renderers that are no |
368 // longer alive. | 371 // longer alive. |
369 std::vector<int> known_renderers = feedback_.GetRendersWithMisspellings(); | 372 std::vector<int> known_renderers = feedback_.GetRendersWithMisspellings(); |
370 std::sort(known_renderers.begin(), known_renderers.end()); | 373 std::sort(known_renderers.begin(), known_renderers.end()); |
371 std::vector<int> dead_renderers = | 374 std::vector<int> dead_renderers = |
372 base::STLSetDifference<std::vector<int> >(known_renderers, | 375 base::STLSetDifference<std::vector<int> >(known_renderers, |
373 alive_renderers); | 376 alive_renderers); |
374 for (std::vector<int>::const_iterator it = dead_renderers.begin(); | 377 for (std::vector<int>::const_iterator it = dead_renderers.begin(); |
375 it != dead_renderers.end(); | 378 it != dead_renderers.end(); |
376 ++it) { | 379 ++it) { |
377 base::MessageLoop::current()->PostTask( | 380 base::ThreadTaskRunnerHandle::Get()->PostTask( |
378 FROM_HERE, | 381 FROM_HERE, base::Bind(&FeedbackSender::OnReceiveDocumentMarkers, |
379 base::Bind(&FeedbackSender::OnReceiveDocumentMarkers, | 382 AsWeakPtr(), *it, std::vector<uint32>())); |
380 AsWeakPtr(), | |
381 *it, | |
382 std::vector<uint32>())); | |
383 } | 383 } |
384 } | 384 } |
385 | 385 |
386 void FeedbackSender::FlushFeedback() { | 386 void FeedbackSender::FlushFeedback() { |
387 if (feedback_.Empty()) | 387 if (feedback_.Empty()) |
388 return; | 388 return; |
389 feedback_.FinalizeAllMisspellings(); | 389 feedback_.FinalizeAllMisspellings(); |
390 SendFeedback(feedback_.GetAllMisspellings(), | 390 SendFeedback(feedback_.GetAllMisspellings(), |
391 renderers_sent_feedback_.empty()); | 391 renderers_sent_feedback_.empty()); |
392 feedback_.Clear(); | 392 feedback_.Clear(); |
(...skipping 23 matching lines...) Expand all Loading... |
416 senders_.push_back(sender); | 416 senders_.push_back(sender); |
417 | 417 |
418 // Request context is NULL in testing. | 418 // Request context is NULL in testing. |
419 if (request_context_.get()) { | 419 if (request_context_.get()) { |
420 sender->SetRequestContext(request_context_.get()); | 420 sender->SetRequestContext(request_context_.get()); |
421 sender->Start(); | 421 sender->Start(); |
422 } | 422 } |
423 } | 423 } |
424 | 424 |
425 } // namespace spellcheck | 425 } // namespace spellcheck |
OLD | NEW |