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

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

Issue 8345034: SpellCheck: the custom dictionary should be per profile. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Fixed. Created 9 years, 2 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/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"
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // We download from the ui thread because we need to know that 231 // We download from the ui thread because we need to know that
232 // |request_context_getter_| is still valid before initiating the download. 232 // |request_context_getter_| is still valid before initiating the download.
233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 233 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
234 NewRunnableMethod(this, &SpellCheckHostImpl::DownloadDictionary)); 234 NewRunnableMethod(this, &SpellCheckHostImpl::DownloadDictionary));
235 return; 235 return;
236 } 236 }
237 237
238 request_context_getter_ = NULL; 238 request_context_getter_ = NULL;
239 239
240 scoped_ptr<CustomWordList> custom_words(new CustomWordList()); 240 scoped_ptr<CustomWordList> custom_words(new CustomWordList());
241 if (file_ != base::kInvalidPlatformFileValue) { 241 if (file_ != base::kInvalidPlatformFileValue)
242 // Load custom dictionary. 242 LoadCustomDictionary(custom_words.get());
243 std::string contents;
244 file_util::ReadFileToString(custom_dictionary_file_, &contents);
245 CustomWordList list_of_words;
246 base::SplitString(contents, '\n', &list_of_words);
247 for (size_t i = 0; i < list_of_words.size(); ++i)
248 custom_words->push_back(list_of_words[i]);
249 }
250 243
251 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 244 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
252 NewRunnableMethod( 245 NewRunnableMethod(
253 this, 246 this,
254 &SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords, 247 &SpellCheckHostImpl::InformProfileOfInitializationWithCustomWords,
255 custom_words.release())); 248 custom_words.release()));
256 } 249 }
257 250
258 void SpellCheckHostImpl::InitializeOnFileThread() { 251 void SpellCheckHostImpl::InitializeOnFileThread() {
259 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE)); 252 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 295 }
303 GURL url = GURL(std::string(kDownloadServerUrl) + 296 GURL url = GURL(std::string(kDownloadServerUrl) +
304 StringToLowerASCII(bdict_file)); 297 StringToLowerASCII(bdict_file));
305 fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); 298 fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this));
306 fetcher_->set_request_context(request_context_getter_); 299 fetcher_->set_request_context(request_context_getter_);
307 tried_to_download_ = true; 300 tried_to_download_ = true;
308 fetcher_->Start(); 301 fetcher_->Start();
309 request_context_getter_ = NULL; 302 request_context_getter_ = NULL;
310 } 303 }
311 304
305 void SpellCheckHostImpl::LoadCustomDictionary(CustomWordList* custom_words) {
306 if (!custom_words)
307 return;
308
309 std::string contents;
Hironori Bono 2011/10/20 04:48:50 nit: move this declaration above Line 317 "file_ut
shinyak (Google) 2011/10/20 12:04:52 Done.
310 CustomWordList list_of_words;
Hironori Bono 2011/10/20 04:48:50 nit: ditto.
shinyak (Google) 2011/10/20 12:04:52 Done.
311
312 // Load custom dictionary for profile.
313 if (profile_)
314 profile_->LoadCustomDictionary(custom_words);
315
316 // Load custom dictionary.
317 file_util::ReadFileToString(custom_dictionary_file_, &contents);
318 base::SplitString(contents, '\n', &list_of_words);
Hironori Bono 2011/10/20 04:48:50 nit: need 'if (!contents.empty()) {' to avoid call
shinyak (Google) 2011/10/20 12:04:52 Done.
319 for (size_t i = 0; i < list_of_words.size(); ++i) {
320 if (list_of_words[i] != "")
321 custom_words->push_back(list_of_words[i]);
322 }
323 }
324
312 void SpellCheckHostImpl::WriteWordToCustomDictionary(const std::string& word) { 325 void SpellCheckHostImpl::WriteWordToCustomDictionary(const std::string& word) {
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
314 327
315 // Stored in UTF-8. 328 if (profile_)
316 std::string word_to_add(word + "\n"); 329 profile_->WriteWordToCustomDictionary(word);
317 FILE* f = file_util::OpenFile(custom_dictionary_file_, "a+");
318 if (f)
319 fputs(word_to_add.c_str(), f);
320 file_util::CloseFile(f);
321 } 330 }
322 331
323 void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source, 332 void SpellCheckHostImpl::OnURLFetchComplete(const URLFetcher* source,
324 const GURL& url, 333 const GURL& url,
325 const net::URLRequestStatus& status, 334 const net::URLRequestStatus& status,
326 int response_code, 335 int response_code,
327 const net::ResponseCookies& cookies, 336 const net::ResponseCookies& cookies,
328 const std::string& data) { 337 const std::string& data) {
329 DCHECK(source); 338 DCHECK(source);
330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 return file_; 442 return file_;
434 } 443 }
435 444
436 const std::string& SpellCheckHostImpl::GetLanguage() const { 445 const std::string& SpellCheckHostImpl::GetLanguage() const {
437 return language_; 446 return language_;
438 } 447 }
439 448
440 bool SpellCheckHostImpl::IsUsingPlatformChecker() const { 449 bool SpellCheckHostImpl::IsUsingPlatformChecker() const {
441 return use_platform_spellchecker_; 450 return use_platform_spellchecker_;
442 } 451 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698