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 28 matching lines...) Expand all Loading... |
39 size_t length, | 39 size_t length, |
40 const std::vector<base::string16>& suggestions, | 40 const std::vector<base::string16>& suggestions, |
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(const Misspelling& other) = default; |
| 50 |
49 Misspelling::~Misspelling() {} | 51 Misspelling::~Misspelling() {} |
50 | 52 |
51 scoped_ptr<base::DictionaryValue> SerializeMisspelling( | 53 scoped_ptr<base::DictionaryValue> SerializeMisspelling( |
52 const Misspelling& misspelling) { | 54 const Misspelling& misspelling) { |
53 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); | 55 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue); |
54 result->SetString( | 56 result->SetString( |
55 "timestamp", | 57 "timestamp", |
56 base::Int64ToString(static_cast<long>(misspelling.timestamp.ToJsTime()))); | 58 base::Int64ToString(static_cast<long>(misspelling.timestamp.ToJsTime()))); |
57 result->SetInteger("misspelledLength", misspelling.length); | 59 result->SetInteger("misspelledLength", misspelling.length); |
58 result->SetInteger("misspelledStart", misspelling.location); | 60 result->SetInteger("misspelledStart", misspelling.location); |
(...skipping 15 matching lines...) Expand all Loading... |
74 } | 76 } |
75 | 77 |
76 size_t ApproximateSerializedSize(const Misspelling& misspelling) { | 78 size_t ApproximateSerializedSize(const Misspelling& misspelling) { |
77 // Estimated by eyeballing JSON overhead. | 79 // Estimated by eyeballing JSON overhead. |
78 const size_t kNumberOfOverheadBytes = 180; | 80 const size_t kNumberOfOverheadBytes = 180; |
79 size_t result = misspelling.context.length() + kNumberOfOverheadBytes; | 81 size_t result = misspelling.context.length() + kNumberOfOverheadBytes; |
80 for (const base::string16& suggestion : misspelling.suggestions) | 82 for (const base::string16& suggestion : misspelling.suggestions) |
81 result += suggestion.size(); | 83 result += suggestion.size(); |
82 return result; | 84 return result; |
83 } | 85 } |
OLD | NEW |