| 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 |Misspelling| object stores the misspelling, a spellcheck suggestion for | 5 // The |Misspelling| object stores the misspelling, a spellcheck suggestion for |
| 6 // it, and user's action on it. The misspelling is stored as |context|, | 6 // it, and user's action on it. The misspelling is stored as |context|, |
| 7 // |location|, and |length| instead of only misspelled text, because the | 7 // |location|, and |length| instead of only misspelled text, because the |
| 8 // spellcheck algorithm uses the context. | 8 // spellcheck algorithm uses the context. |
| 9 | 9 |
| 10 #include "chrome/browser/spellchecker/misspelling.h" | 10 #include "chrome/browser/spellchecker/misspelling.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 uint32_t hash) | 41 uint32_t hash) |
| 42 : context(context), | 42 : context(context), |
| 43 location(location), | 43 location(location), |
| 44 length(length), | 44 length(length), |
| 45 suggestions(suggestions), | 45 suggestions(suggestions), |
| 46 hash(hash), | 46 hash(hash), |
| 47 timestamp(base::Time::Now()) {} | 47 timestamp(base::Time::Now()) {} |
| 48 | 48 |
| 49 Misspelling::~Misspelling() {} | 49 Misspelling::~Misspelling() {} |
| 50 | 50 |
| 51 base::DictionaryValue* SerializeMisspelling(const Misspelling& misspelling) { | 51 scoped_ptr<base::DictionaryValue> SerializeMisspelling( |
| 52 base::DictionaryValue* result = new base::DictionaryValue; | 52 const Misspelling& misspelling) { |
| 53 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
| 53 result->SetString( | 54 result->SetString( |
| 54 "timestamp", | 55 "timestamp", |
| 55 base::Int64ToString(static_cast<long>(misspelling.timestamp.ToJsTime()))); | 56 base::Int64ToString(static_cast<long>(misspelling.timestamp.ToJsTime()))); |
| 56 result->SetInteger("misspelledLength", misspelling.length); | 57 result->SetInteger("misspelledLength", misspelling.length); |
| 57 result->SetInteger("misspelledStart", misspelling.location); | 58 result->SetInteger("misspelledStart", misspelling.location); |
| 58 result->SetString("originalText", misspelling.context); | 59 result->SetString("originalText", misspelling.context); |
| 59 result->SetString("suggestionId", base::UintToString(misspelling.hash)); | 60 result->SetString("suggestionId", base::UintToString(misspelling.hash)); |
| 60 result->Set("suggestions", BuildSuggestionsValue(misspelling.suggestions)); | 61 result->Set("suggestions", BuildSuggestionsValue(misspelling.suggestions)); |
| 61 result->Set("userActions", BuildUserActionValue(misspelling.action)); | 62 result->Set("userActions", BuildUserActionValue(misspelling.action)); |
| 62 return result; | 63 return result; |
| 63 } | 64 } |
| 64 | 65 |
| 65 base::string16 GetMisspelledString(const Misspelling& misspelling) { | 66 base::string16 GetMisspelledString(const Misspelling& misspelling) { |
| 66 // Feedback sender does not create Misspelling objects for spellcheck results | 67 // Feedback sender does not create Misspelling objects for spellcheck results |
| 67 // that are out-of-bounds of checked text length. | 68 // that are out-of-bounds of checked text length. |
| 68 if (misspelling.location > misspelling.context.length()) | 69 if (misspelling.location > misspelling.context.length()) |
| 69 return base::string16(); | 70 return base::string16(); |
| 70 return misspelling.context.substr(misspelling.location, misspelling.length); | 71 return misspelling.context.substr(misspelling.location, misspelling.length); |
| 71 } | 72 } |
| 72 | 73 |
| 73 size_t ApproximateSerializedSize(const Misspelling& misspelling) { | 74 size_t ApproximateSerializedSize(const Misspelling& misspelling) { |
| 74 // Estimated by eyeballing JSON overhead. | 75 // Estimated by eyeballing JSON overhead. |
| 75 const size_t kNumberOfOverheadBytes = 180; | 76 const size_t kNumberOfOverheadBytes = 180; |
| 76 size_t result = misspelling.context.length() + kNumberOfOverheadBytes; | 77 size_t result = misspelling.context.length() + kNumberOfOverheadBytes; |
| 77 for (const base::string16& suggestion : misspelling.suggestions) | 78 for (const base::string16& suggestion : misspelling.suggestions) |
| 78 result += suggestion.size(); | 79 result += suggestion.size(); |
| 79 return result; | 80 return result; |
| 80 } | 81 } |
| OLD | NEW |