| OLD | NEW |
| 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/spellchecker/spellcheck_host_impl.h" | 5 #include "chrome/browser/spellchecker/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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 17 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| 18 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" | 18 #include "chrome/browser/spellchecker/spellcheck_profile_provider.h" |
| 19 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" | 19 #include "chrome/browser/spellchecker/spellchecker_platform_engine.h" |
| 20 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/common/spellcheck_common.h" | 23 #include "chrome/common/spellcheck_common.h" |
| 24 #include "chrome/common/spellcheck_messages.h" | 24 #include "chrome/common/spellcheck_messages.h" |
| 25 #include "content/browser/renderer_host/render_process_host.h" | 25 #include "content/browser/renderer_host/render_process_host.h" |
| 26 #include "content/common/net/url_fetcher.h" |
| 26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 29 #include "net/url_request/url_request_context_getter.h" | 30 #include "net/url_request/url_request_context_getter.h" |
| 30 #include "third_party/hunspell/google/bdict.h" | 31 #include "third_party/hunspell/google/bdict.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 #if defined(OS_MACOSX) | 33 #if defined(OS_MACOSX) |
| 33 #include "base/metrics/histogram.h" | 34 #include "base/metrics/histogram.h" |
| 34 #endif | 35 #endif |
| 35 | 36 |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 314 | 315 |
| 315 // Stored in UTF-8. | 316 // Stored in UTF-8. |
| 316 std::string word_to_add(word + "\n"); | 317 std::string word_to_add(word + "\n"); |
| 317 FILE* f = file_util::OpenFile(custom_dictionary_file_, "a+"); | 318 FILE* f = file_util::OpenFile(custom_dictionary_file_, "a+"); |
| 318 if (f) | 319 if (f) |
| 319 fputs(word_to_add.c_str(), f); | 320 fputs(word_to_add.c_str(), f); |
| 320 file_util::CloseFile(f); | 321 file_util::CloseFile(f); |
| 321 } | 322 } |
| 322 | 323 |
| 323 void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source, | 324 void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source) { |
| 324 const GURL& url, | |
| 325 const net::URLRequestStatus& status, | |
| 326 int response_code, | |
| 327 const net::ResponseCookies& cookies, | |
| 328 const std::string& data) { | |
| 329 DCHECK(source); | 325 DCHECK(source); |
| 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 331 fetcher_.reset(); | 327 scoped_ptr<URLFetcher> fetcher_destructor(fetcher_.release()); |
| 332 | 328 |
| 333 if ((response_code / 100) != 2) { | 329 if ((source->response_code() / 100) != 2) { |
| 334 // Initialize will not try to download the file a second time. | 330 // Initialize will not try to download the file a second time. |
| 335 LOG(ERROR) << "Failure to download dictionary."; | 331 LOG(ERROR) << "Failure to download dictionary."; |
| 336 InitializeOnFileThread(); | 332 InitializeOnFileThread(); |
| 337 return; | 333 return; |
| 338 } | 334 } |
| 339 | 335 |
| 340 // Basic sanity check on the dictionary. | 336 // Basic sanity check on the dictionary. |
| 341 // There's the small chance that we might see a 200 status code for a body | 337 // There's the small chance that we might see a 200 status code for a body |
| 342 // that represents some form of failure. | 338 // that represents some form of failure. |
| 339 std::string data; |
| 340 source->GetResponseAsString(&data); |
| 343 if (data.size() < 4 || data[0] != 'B' || data[1] != 'D' || data[2] != 'i' || | 341 if (data.size() < 4 || data[0] != 'B' || data[1] != 'D' || data[2] != 'i' || |
| 344 data[3] != 'c') { | 342 data[3] != 'c') { |
| 345 LOG(ERROR) << "Failure to download dictionary."; | 343 LOG(ERROR) << "Failure to download dictionary."; |
| 346 InitializeOnFileThread(); | 344 InitializeOnFileThread(); |
| 347 return; | 345 return; |
| 348 } | 346 } |
| 349 | 347 |
| 350 data_ = data; | 348 data_ = data; |
| 351 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 349 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 352 NewRunnableMethod(this, &SpellCheckHostImpl::SaveDictionaryData)); | 350 NewRunnableMethod(this, &SpellCheckHostImpl::SaveDictionaryData)); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 return file_; | 431 return file_; |
| 434 } | 432 } |
| 435 | 433 |
| 436 const std::string& SpellCheckHostImpl::GetLanguage() const { | 434 const std::string& SpellCheckHostImpl::GetLanguage() const { |
| 437 return language_; | 435 return language_; |
| 438 } | 436 } |
| 439 | 437 |
| 440 bool SpellCheckHostImpl::IsUsingPlatformChecker() const { | 438 bool SpellCheckHostImpl::IsUsingPlatformChecker() const { |
| 441 return use_platform_spellchecker_; | 439 return use_platform_spellchecker_; |
| 442 } | 440 } |
| OLD | NEW |