| 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/chrome_switches.h" | |
| 49 #include "chrome/common/spellcheck_common.h" | 48 #include "chrome/common/spellcheck_common.h" |
| 50 #include "chrome/common/spellcheck_marker.h" | 49 #include "chrome/common/spellcheck_marker.h" |
| 51 #include "chrome/common/spellcheck_messages.h" | 50 #include "chrome/common/spellcheck_messages.h" |
| 52 #include "components/data_use_measurement/core/data_use_user_data.h" | 51 #include "components/data_use_measurement/core/data_use_user_data.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 |
| 62 namespace spellcheck { | 62 namespace spellcheck { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 text_length; | 176 text_length; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // Returns the feedback API version. | 179 // Returns the feedback API version. |
| 180 std::string GetApiVersion() { | 180 std::string GetApiVersion() { |
| 181 // This guard is temporary. | 181 // This guard is temporary. |
| 182 // TODO(rouslan): Remove the guard. http://crbug.com/247726 | 182 // TODO(rouslan): Remove the guard. http://crbug.com/247726 |
| 183 if (base::FieldTrialList::FindFullName(kFeedbackFieldTrialName) == | 183 if (base::FieldTrialList::FindFullName(kFeedbackFieldTrialName) == |
| 184 kFeedbackFieldTrialEnabledGroupName && | 184 kFeedbackFieldTrialEnabledGroupName && |
| 185 base::CommandLine::ForCurrentProcess()->HasSwitch( | 185 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 186 switches::kEnableSpellingFeedbackFieldTrial)) { | 186 spellcheck::switches::kEnableSpellingFeedbackFieldTrial)) { |
| 187 return "v2-internal"; | 187 return "v2-internal"; |
| 188 } | 188 } |
| 189 return "v2"; | 189 return "v2"; |
| 190 } | 190 } |
| 191 | 191 |
| 192 } // namespace | 192 } // namespace |
| 193 | 193 |
| 194 FeedbackSender::FeedbackSender(net::URLRequestContextGetter* request_context, | 194 FeedbackSender::FeedbackSender(net::URLRequestContextGetter* request_context, |
| 195 const std::string& language, | 195 const std::string& language, |
| 196 const std::string& country) | 196 const std::string& country) |
| 197 : request_context_(request_context), | 197 : request_context_(request_context), |
| 198 api_version_(GetApiVersion()), | 198 api_version_(GetApiVersion()), |
| 199 language_(language), | 199 language_(language), |
| 200 country_(country), | 200 country_(country), |
| 201 misspelling_counter_(0), | 201 misspelling_counter_(0), |
| 202 feedback_(kMaxFeedbackSizeBytes), | 202 feedback_(kMaxFeedbackSizeBytes), |
| 203 session_start_(base::Time::Now()), | 203 session_start_(base::Time::Now()), |
| 204 feedback_service_url_(kFeedbackServiceURL) { | 204 feedback_service_url_(kFeedbackServiceURL) { |
| 205 // The command-line switch is for testing and temporary. | 205 // The command-line switch is for testing and temporary. |
| 206 // TODO(rouslan): Remove the command-line switch when testing is complete. | 206 // TODO(rouslan): Remove the command-line switch when testing is complete. |
| 207 // http://crbug.com/247726 | 207 // http://crbug.com/247726 |
| 208 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 208 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 209 switches::kSpellingServiceFeedbackUrl)) { | 209 spellcheck::switches::kSpellingServiceFeedbackUrl)) { |
| 210 feedback_service_url_ = | 210 feedback_service_url_ = |
| 211 GURL(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 211 GURL(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 212 switches::kSpellingServiceFeedbackUrl)); | 212 spellcheck::switches::kSpellingServiceFeedbackUrl)); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| 216 FeedbackSender::~FeedbackSender() { | 216 FeedbackSender::~FeedbackSender() { |
| 217 } | 217 } |
| 218 | 218 |
| 219 void FeedbackSender::SelectedSuggestion(uint32_t hash, int suggestion_index) { | 219 void FeedbackSender::SelectedSuggestion(uint32_t hash, int suggestion_index) { |
| 220 Misspelling* misspelling = feedback_.GetMisspelling(hash); | 220 Misspelling* misspelling = feedback_.GetMisspelling(hash); |
| 221 // GetMisspelling() returns null for flushed feedback. Feedback is flushed | 221 // GetMisspelling() returns null for flushed feedback. Feedback is flushed |
| 222 // when the session expires every |kSessionHours| hours. | 222 // when the session expires every |kSessionHours| hours. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 void FeedbackSender::StartFeedbackCollection() { | 342 void FeedbackSender::StartFeedbackCollection() { |
| 343 if (timer_.IsRunning()) | 343 if (timer_.IsRunning()) |
| 344 return; | 344 return; |
| 345 | 345 |
| 346 int interval_seconds = chrome::spellcheck_common::kFeedbackIntervalSeconds; | 346 int interval_seconds = chrome::spellcheck_common::kFeedbackIntervalSeconds; |
| 347 // This command-line switch is for testing and temporary. | 347 // This command-line switch is for testing and temporary. |
| 348 // TODO(rouslan): Remove the command-line switch when testing is complete. | 348 // TODO(rouslan): Remove the command-line switch when testing is complete. |
| 349 // http://crbug.com/247726 | 349 // http://crbug.com/247726 |
| 350 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 350 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 351 switches::kSpellingServiceFeedbackIntervalSeconds)) { | 351 spellcheck::switches::kSpellingServiceFeedbackIntervalSeconds)) { |
| 352 base::StringToInt( | 352 base::StringToInt( |
| 353 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 353 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 354 switches::kSpellingServiceFeedbackIntervalSeconds), | 354 spellcheck::switches::kSpellingServiceFeedbackIntervalSeconds), |
| 355 &interval_seconds); | 355 &interval_seconds); |
| 356 if (interval_seconds < kMinIntervalSeconds) | 356 if (interval_seconds < kMinIntervalSeconds) |
| 357 interval_seconds = kMinIntervalSeconds; | 357 interval_seconds = kMinIntervalSeconds; |
| 358 static const int kSessionSeconds = | 358 static const int kSessionSeconds = |
| 359 chrome::spellcheck_common::kSessionHours * 60 * 60; | 359 chrome::spellcheck_common::kSessionHours * 60 * 60; |
| 360 if (interval_seconds > kSessionSeconds) | 360 if (interval_seconds > kSessionSeconds) |
| 361 interval_seconds = kSessionSeconds; | 361 interval_seconds = kSessionSeconds; |
| 362 } | 362 } |
| 363 timer_.Start(FROM_HERE, | 363 timer_.Start(FROM_HERE, |
| 364 base::TimeDelta::FromSeconds(interval_seconds), | 364 base::TimeDelta::FromSeconds(interval_seconds), |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 senders_.push_back(sender); | 455 senders_.push_back(sender); |
| 456 | 456 |
| 457 // Request context is nullptr in testing. | 457 // Request context is nullptr in testing. |
| 458 if (request_context_.get()) { | 458 if (request_context_.get()) { |
| 459 sender->SetRequestContext(request_context_.get()); | 459 sender->SetRequestContext(request_context_.get()); |
| 460 sender->Start(); | 460 sender->Start(); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 | 463 |
| 464 } // namespace spellcheck | 464 } // namespace spellcheck |
| OLD | NEW |