OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" | 5 #include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h" |
6 | 6 |
7 #include <functional> | 7 #include <functional> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/important_file_writer.h" | 10 #include "base/files/important_file_writer.h" |
11 #include "base/md5.h" | 11 #include "base/md5.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
15 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
16 #include "chrome/common/spellcheck_messages.h" | 17 #include "chrome/common/spellcheck_messages.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "sync/api/sync_change.h" | 19 #include "sync/api/sync_change.h" |
19 #include "sync/api/sync_data.h" | 20 #include "sync/api/sync_data.h" |
20 #include "sync/api/sync_error_factory.h" | 21 #include "sync/api/sync_error_factory.h" |
21 #include "sync/protocol/sync.pb.h" | 22 #include "sync/protocol/sync.pb.h" |
22 | 23 |
23 using content::BrowserThread; | 24 using content::BrowserThread; |
24 using chrome::spellcheck_common::WordList; | 25 using chrome::spellcheck_common::WordList; |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 403 } |
403 | 404 |
404 // static | 405 // static |
405 WordList SpellcheckCustomDictionary::LoadDictionaryFile( | 406 WordList SpellcheckCustomDictionary::LoadDictionaryFile( |
406 const base::FilePath& path) { | 407 const base::FilePath& path) { |
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
408 WordList words; | 409 WordList words; |
409 LoadDictionaryFileReliably(words, path); | 410 LoadDictionaryFileReliably(words, path); |
410 if (!words.empty() && VALID_CHANGE != SanitizeWordsToAdd(WordList(), words)) | 411 if (!words.empty() && VALID_CHANGE != SanitizeWordsToAdd(WordList(), words)) |
411 SaveDictionaryFileReliably(words, path); | 412 SaveDictionaryFileReliably(words, path); |
| 413 SpellCheckHostMetrics::RecordCustomWordCountStats(words.size()); |
412 return words; | 414 return words; |
413 } | 415 } |
414 | 416 |
415 // static | 417 // static |
416 void SpellcheckCustomDictionary::UpdateDictionaryFile( | 418 void SpellcheckCustomDictionary::UpdateDictionaryFile( |
417 const SpellcheckCustomDictionary::Change& dictionary_change, | 419 const SpellcheckCustomDictionary::Change& dictionary_change, |
418 const base::FilePath& path) { | 420 const base::FilePath& path) { |
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
420 if (dictionary_change.empty()) | 422 if (dictionary_change.empty()) |
421 return; | 423 return; |
(...skipping 23 matching lines...) Expand all Loading... |
445 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
446 std::sort(words_.begin(), words_.end()); | 448 std::sort(words_.begin(), words_.end()); |
447 Change dictionary_change(custom_words); | 449 Change dictionary_change(custom_words); |
448 dictionary_change.Sanitize(GetWords()); | 450 dictionary_change.Sanitize(GetWords()); |
449 Apply(dictionary_change); | 451 Apply(dictionary_change); |
450 Sync(dictionary_change); | 452 Sync(dictionary_change); |
451 is_loaded_ = true; | 453 is_loaded_ = true; |
452 FOR_EACH_OBSERVER(Observer, observers_, OnCustomDictionaryLoaded()); | 454 FOR_EACH_OBSERVER(Observer, observers_, OnCustomDictionaryLoaded()); |
453 } | 455 } |
454 | 456 |
455 // TODO(rlp): record metrics on custom word size | |
456 void SpellcheckCustomDictionary::Apply( | 457 void SpellcheckCustomDictionary::Apply( |
457 const SpellcheckCustomDictionary::Change& dictionary_change) { | 458 const SpellcheckCustomDictionary::Change& dictionary_change) { |
458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 459 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
459 if (!dictionary_change.to_add().empty()) { | 460 if (!dictionary_change.to_add().empty()) { |
460 words_.insert(words_.end(), | 461 words_.insert(words_.end(), |
461 dictionary_change.to_add().begin(), | 462 dictionary_change.to_add().begin(), |
462 dictionary_change.to_add().end()); | 463 dictionary_change.to_add().end()); |
463 } | 464 } |
464 if (!dictionary_change.to_remove().empty()) { | 465 if (!dictionary_change.to_remove().empty()) { |
465 std::sort(words_.begin(), words_.end()); | 466 std::sort(words_.begin(), words_.end()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 | 546 |
546 void SpellcheckCustomDictionary::Notify( | 547 void SpellcheckCustomDictionary::Notify( |
547 const SpellcheckCustomDictionary::Change& dictionary_change) { | 548 const SpellcheckCustomDictionary::Change& dictionary_change) { |
548 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 549 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
549 if (!IsLoaded() || dictionary_change.empty()) | 550 if (!IsLoaded() || dictionary_change.empty()) |
550 return; | 551 return; |
551 FOR_EACH_OBSERVER(Observer, | 552 FOR_EACH_OBSERVER(Observer, |
552 observers_, | 553 observers_, |
553 OnCustomDictionaryChanged(dictionary_change)); | 554 OnCustomDictionaryChanged(dictionary_change)); |
554 } | 555 } |
OLD | NEW |