Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Side by Side Diff: chrome/browser/spellcheck_host_impl.cc

Issue 7121006: Introduced additional spellcheck related histogram. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Uploading the patch for our commit queue Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/spellcheck_host_impl.h" 5 #include "chrome/browser/spellcheck_host_impl.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 const std::string& language, 84 const std::string& language,
85 net::URLRequestContextGetter* request_context_getter) 85 net::URLRequestContextGetter* request_context_getter)
86 : observer_(observer), 86 : observer_(observer),
87 language_(language), 87 language_(language),
88 file_(base::kInvalidPlatformFileValue), 88 file_(base::kInvalidPlatformFileValue),
89 tried_to_download_(false), 89 tried_to_download_(false),
90 use_platform_spellchecker_(false), 90 use_platform_spellchecker_(false),
91 request_context_getter_(request_context_getter), 91 request_context_getter_(request_context_getter),
92 misspelled_word_count_(0), 92 misspelled_word_count_(0),
93 spellchecked_word_count_(0), 93 spellchecked_word_count_(0),
94 suggestion_show_count_(0),
94 replaced_word_count_(0) { 95 replaced_word_count_(0) {
95 DCHECK(observer_); 96 DCHECK(observer_);
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 97 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
97 98
98 FilePath personal_file_directory; 99 FilePath personal_file_directory;
99 PathService::Get(chrome::DIR_USER_DATA, &personal_file_directory); 100 PathService::Get(chrome::DIR_USER_DATA, &personal_file_directory);
100 custom_dictionary_file_ = 101 custom_dictionary_file_ =
101 personal_file_directory.Append(chrome::kCustomDictionaryFileName); 102 personal_file_directory.Append(chrome::kCustomDictionaryFileName);
102 103
103 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED, 104 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED,
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 // the population. So we ensure to instantiate the histogram 309 // the population. So we ensure to instantiate the histogram
309 // entries here at the first time. 310 // entries here at the first time.
310 if (misspelled_word_count_ == 1) 311 if (misspelled_word_count_ == 1)
311 RecordReplacedWordStats(0); 312 RecordReplacedWordStats(0);
312 } 313 }
313 314
314 int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_; 315 int percentage = (100 * misspelled_word_count_) / spellchecked_word_count_;
315 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage); 316 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.MisspellRatio", percentage);
316 } 317 }
317 318
319 void SpellCheckHostImpl::RecordDictionaryCorruptionStats(bool corrupted) {
320 UMA_HISTOGRAM_BOOLEAN("SpellCheck.DictionaryCorrupted", corrupted);
321 }
322
323 void SpellCheckHostImpl::RecordSuggestionStats(int delta) {
324 suggestion_show_count_ += delta;
325 RecordReplacedWordStats(0);
326 }
327
318 void SpellCheckHostImpl::RecordReplacedWordStats(int delta) { 328 void SpellCheckHostImpl::RecordReplacedWordStats(int delta) {
319 replaced_word_count_ += delta; 329 replaced_word_count_ += delta;
320 if (!misspelled_word_count_) { 330
321 // This is possible when an extension gives the misspelling, 331 if (misspelled_word_count_) {
322 // which is not recorded as a part of this metrics. 332 // zero |misspelled_word_count_| is possible when an extension
323 return; 333 // gives the misspelling, which is not recorded as a part of this
334 // metrics.
335 int percentage = (100 * replaced_word_count_) / misspelled_word_count_;
336 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.ReplaceRatio", percentage);
324 } 337 }
325 338
326 int percentage = (100 * replaced_word_count_) / misspelled_word_count_; 339 if (suggestion_show_count_) {
327 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.ReplaceRatio", percentage); 340 int percentage = (100 * replaced_word_count_) / suggestion_show_count_;
341 UMA_HISTOGRAM_PERCENTAGE("SpellCheck.SuggestionHitRatio", percentage);
342 }
328 } 343 }
329 344
330 void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source, 345 void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source,
331 const GURL& url, 346 const GURL& url,
332 const net::URLRequestStatus& status, 347 const net::URLRequestStatus& status,
333 int response_code, 348 int response_code,
334 const net::ResponseCookies& cookies, 349 const net::ResponseCookies& cookies,
335 const std::string& data) { 350 const std::string& data) {
336 DCHECK(source); 351 DCHECK(source);
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 27 matching lines...) Expand all
365 DCHECK(type == NotificationType::RENDERER_PROCESS_CREATED); 380 DCHECK(type == NotificationType::RENDERER_PROCESS_CREATED);
366 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); 381 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr();
367 InitForRenderer(process); 382 InitForRenderer(process);
368 } 383 }
369 384
370 void SpellCheckHostImpl::SaveDictionaryData() { 385 void SpellCheckHostImpl::SaveDictionaryData() {
371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
372 387
373 // To prevent corrupted dictionary data from causing a renderer crash, scan 388 // To prevent corrupted dictionary data from causing a renderer crash, scan
374 // the dictionary data and verify it is sane before save it to a file. 389 // the dictionary data and verify it is sane before save it to a file.
375 if (!hunspell::BDict::Verify(data_.data(), data_.size())) { 390 bool verified = hunspell::BDict::Verify(data_.data(), data_.size());
391 RecordDictionaryCorruptionStats(!verified);
392 if (!verified) {
376 LOG(ERROR) << "Failure to verify the downloaded dictionary."; 393 LOG(ERROR) << "Failure to verify the downloaded dictionary.";
377 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 394 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
378 NewRunnableMethod(this, 395 NewRunnableMethod(this,
379 &SpellCheckHostImpl::InformObserverOfInitialization)); 396 &SpellCheckHostImpl::InformObserverOfInitialization));
380 return; 397 return;
381 } 398 }
382 399
383 size_t bytes_written = 400 size_t bytes_written =
384 file_util::WriteFile(bdict_file_path_, data_.data(), data_.length()); 401 file_util::WriteFile(bdict_file_path_, data_.data(), data_.length());
385 if (bytes_written != data_.length()) { 402 if (bytes_written != data_.length()) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 return custom_words_.back(); 439 return custom_words_.back();
423 } 440 }
424 441
425 const std::string& SpellCheckHostImpl::GetLanguage() const { 442 const std::string& SpellCheckHostImpl::GetLanguage() const {
426 return language_; 443 return language_;
427 } 444 }
428 445
429 bool SpellCheckHostImpl::IsUsingPlatformChecker() const { 446 bool SpellCheckHostImpl::IsUsingPlatformChecker() const {
430 return use_platform_spellchecker_; 447 return use_platform_spellchecker_;
431 } 448 }
OLDNEW
« no previous file with comments | « chrome/browser/spellcheck_host_impl.h ('k') | chrome/browser/tab_contents/render_view_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698