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 19 matching lines...) Expand all Loading... | |
30 #include "components/spellcheck/browser/feedback_sender.h" | 30 #include "components/spellcheck/browser/feedback_sender.h" |
31 | 31 |
32 #include <algorithm> | 32 #include <algorithm> |
33 #include <iterator> | 33 #include <iterator> |
34 #include <utility> | 34 #include <utility> |
35 | 35 |
36 #include "base/command_line.h" | 36 #include "base/command_line.h" |
37 #include "base/hash.h" | 37 #include "base/hash.h" |
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/memory/ptr_util.h" | |
40 #include "base/metrics/field_trial.h" | 41 #include "base/metrics/field_trial.h" |
41 #include "base/single_thread_task_runner.h" | 42 #include "base/single_thread_task_runner.h" |
42 #include "base/stl_util.h" | 43 #include "base/stl_util.h" |
43 #include "base/strings/string_number_conversions.h" | 44 #include "base/strings/string_number_conversions.h" |
44 #include "base/strings/stringprintf.h" | 45 #include "base/strings/stringprintf.h" |
45 #include "base/threading/thread_task_runner_handle.h" | 46 #include "base/threading/thread_task_runner_handle.h" |
46 #include "base/values.h" | 47 #include "base/values.h" |
47 #include "components/data_use_measurement/core/data_use_user_data.h" | 48 #include "components/data_use_measurement/core/data_use_user_data.h" |
48 #include "components/spellcheck/browser/word_trimmer.h" | 49 #include "components/spellcheck/browser/word_trimmer.h" |
49 #include "components/spellcheck/common/spellcheck_common.h" | 50 #include "components/spellcheck/common/spellcheck_common.h" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 | 370 |
370 FlushFeedback(); | 371 FlushFeedback(); |
371 timer_.Stop(); | 372 timer_.Stop(); |
372 } | 373 } |
373 | 374 |
374 void FeedbackSender::RandBytes(void* p, size_t len) { | 375 void FeedbackSender::RandBytes(void* p, size_t len) { |
375 crypto::RandBytes(p, len); | 376 crypto::RandBytes(p, len); |
376 } | 377 } |
377 | 378 |
378 void FeedbackSender::OnURLFetchComplete(const net::URLFetcher* source) { | 379 void FeedbackSender::OnURLFetchComplete(const net::URLFetcher* source) { |
379 for (ScopedVector<net::URLFetcher>::iterator sender_it = senders_.begin(); | 380 for (auto sender_it = senders_.begin(); sender_it != senders_.end(); |
380 sender_it != senders_.end(); | |
381 ++sender_it) { | 381 ++sender_it) { |
382 if (*sender_it == source) { | 382 if ((*sender_it).get() == source) { |
383 senders_.erase(sender_it); | 383 senders_.erase(sender_it); |
384 return; | 384 return; |
385 } | 385 } |
386 } | 386 } |
387 delete source; | 387 delete source; |
388 } | 388 } |
389 | 389 |
390 void FeedbackSender::RequestDocumentMarkers() { | 390 void FeedbackSender::RequestDocumentMarkers() { |
391 // Request document markers from all the renderers that are still alive. | 391 // Request document markers from all the renderers that are still alive. |
392 std::set<int> alive_renderers; | 392 std::set<int> alive_renderers; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 // The tests use this identifier to mock the URL fetcher. | 442 // The tests use this identifier to mock the URL fetcher. |
443 static const int kUrlFetcherId = 0; | 443 static const int kUrlFetcherId = 0; |
444 net::URLFetcher* sender = | 444 net::URLFetcher* sender = |
445 net::URLFetcher::Create(kUrlFetcherId, feedback_service_url_, | 445 net::URLFetcher::Create(kUrlFetcherId, feedback_service_url_, |
446 net::URLFetcher::POST, this).release(); | 446 net::URLFetcher::POST, this).release(); |
447 data_use_measurement::DataUseUserData::AttachToFetcher( | 447 data_use_measurement::DataUseUserData::AttachToFetcher( |
448 sender, data_use_measurement::DataUseUserData::SPELL_CHECKER); | 448 sender, data_use_measurement::DataUseUserData::SPELL_CHECKER); |
449 sender->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 449 sender->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
450 net::LOAD_DO_NOT_SAVE_COOKIES); | 450 net::LOAD_DO_NOT_SAVE_COOKIES); |
451 sender->SetUploadData("application/json", feedback); | 451 sender->SetUploadData("application/json", feedback); |
452 senders_.push_back(sender); | 452 senders_.push_back(base::WrapUnique<net::URLFetcher>(sender)); |
groby-ooo-7-16
2017/01/26 17:40:47
This should probably be a unique_ptr from creation
ke.he
2017/01/27 03:15:40
Done.
| |
453 | 453 |
454 // Request context is nullptr in testing. | 454 // Request context is nullptr in testing. |
455 if (request_context_.get()) { | 455 if (request_context_.get()) { |
456 sender->SetRequestContext(request_context_.get()); | 456 sender->SetRequestContext(request_context_.get()); |
457 sender->Start(); | 457 sender->Start(); |
458 } | 458 } |
459 } | 459 } |
460 | 460 |
461 } // namespace spellcheck | 461 } // namespace spellcheck |
OLD | NEW |