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

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

Issue 1551503002: Convert Pass()→std::move() in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8
9 #include <functional> 8 #include <functional>
9 #include <utility>
10 10
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/important_file_writer.h" 12 #include "base/files/important_file_writer.h"
13 #include "base/md5.h" 13 #include "base/md5.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_split.h" 15 #include "base/strings/string_split.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" 17 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h"
18 #include "chrome/common/chrome_constants.h" 18 #include "chrome/common/chrome_constants.h"
19 #include "chrome/common/spellcheck_common.h" 19 #include "chrome/common/spellcheck_common.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 223 }
224 224
225 bool SpellcheckCustomDictionary::AddWord(const std::string& word) { 225 bool SpellcheckCustomDictionary::AddWord(const std::string& word) {
226 DCHECK_CURRENTLY_ON(BrowserThread::UI); 226 DCHECK_CURRENTLY_ON(BrowserThread::UI);
227 scoped_ptr<Change> dictionary_change(new Change); 227 scoped_ptr<Change> dictionary_change(new Change);
228 dictionary_change->AddWord(word); 228 dictionary_change->AddWord(word);
229 int result = dictionary_change->Sanitize(GetWords()); 229 int result = dictionary_change->Sanitize(GetWords());
230 Apply(*dictionary_change); 230 Apply(*dictionary_change);
231 Notify(*dictionary_change); 231 Notify(*dictionary_change);
232 Sync(*dictionary_change); 232 Sync(*dictionary_change);
233 Save(dictionary_change.Pass()); 233 Save(std::move(dictionary_change));
234 return result == VALID_CHANGE; 234 return result == VALID_CHANGE;
235 } 235 }
236 236
237 bool SpellcheckCustomDictionary::RemoveWord(const std::string& word) { 237 bool SpellcheckCustomDictionary::RemoveWord(const std::string& word) {
238 DCHECK_CURRENTLY_ON(BrowserThread::UI); 238 DCHECK_CURRENTLY_ON(BrowserThread::UI);
239 scoped_ptr<Change> dictionary_change(new Change); 239 scoped_ptr<Change> dictionary_change(new Change);
240 dictionary_change->RemoveWord(word); 240 dictionary_change->RemoveWord(word);
241 int result = dictionary_change->Sanitize(GetWords()); 241 int result = dictionary_change->Sanitize(GetWords());
242 Apply(*dictionary_change); 242 Apply(*dictionary_change);
243 Notify(*dictionary_change); 243 Notify(*dictionary_change);
244 Sync(*dictionary_change); 244 Sync(*dictionary_change);
245 Save(dictionary_change.Pass()); 245 Save(std::move(dictionary_change));
246 return result == VALID_CHANGE; 246 return result == VALID_CHANGE;
247 } 247 }
248 248
249 bool SpellcheckCustomDictionary::HasWord(const std::string& word) const { 249 bool SpellcheckCustomDictionary::HasWord(const std::string& word) const {
250 return !!words_.count(word); 250 return !!words_.count(word);
251 } 251 }
252 252
253 void SpellcheckCustomDictionary::AddObserver(Observer* observer) { 253 void SpellcheckCustomDictionary::AddObserver(Observer* observer) {
254 DCHECK_CURRENTLY_ON(BrowserThread::UI); 254 DCHECK_CURRENTLY_ON(BrowserThread::UI);
255 DCHECK(observer); 255 DCHECK(observer);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 syncer::ModelType type, 287 syncer::ModelType type,
288 const syncer::SyncDataList& initial_sync_data, 288 const syncer::SyncDataList& initial_sync_data,
289 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 289 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
290 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler) { 290 scoped_ptr<syncer::SyncErrorFactory> sync_error_handler) {
291 DCHECK_CURRENTLY_ON(BrowserThread::UI); 291 DCHECK_CURRENTLY_ON(BrowserThread::UI);
292 DCHECK(!sync_processor_.get()); 292 DCHECK(!sync_processor_.get());
293 DCHECK(!sync_error_handler_.get()); 293 DCHECK(!sync_error_handler_.get());
294 DCHECK(sync_processor.get()); 294 DCHECK(sync_processor.get());
295 DCHECK(sync_error_handler.get()); 295 DCHECK(sync_error_handler.get());
296 DCHECK_EQ(syncer::DICTIONARY, type); 296 DCHECK_EQ(syncer::DICTIONARY, type);
297 sync_processor_ = sync_processor.Pass(); 297 sync_processor_ = std::move(sync_processor);
298 sync_error_handler_ = sync_error_handler.Pass(); 298 sync_error_handler_ = std::move(sync_error_handler);
299 299
300 // Build a list of words to add locally. 300 // Build a list of words to add locally.
301 scoped_ptr<Change> to_change_locally(new Change); 301 scoped_ptr<Change> to_change_locally(new Change);
302 for (const syncer::SyncData& data : initial_sync_data) { 302 for (const syncer::SyncData& data : initial_sync_data) {
303 DCHECK_EQ(syncer::DICTIONARY, data.GetDataType()); 303 DCHECK_EQ(syncer::DICTIONARY, data.GetDataType());
304 to_change_locally->AddWord(data.GetSpecifics().dictionary().word()); 304 to_change_locally->AddWord(data.GetSpecifics().dictionary().word());
305 } 305 }
306 306
307 // Add as many as possible local words remotely. 307 // Add as many as possible local words remotely.
308 to_change_locally->Sanitize(GetWords()); 308 to_change_locally->Sanitize(GetWords());
309 Change to_change_remotely; 309 Change to_change_remotely;
310 to_change_remotely.AddWords(base::STLSetDifference<std::set<std::string>>( 310 to_change_remotely.AddWords(base::STLSetDifference<std::set<std::string>>(
311 words_, to_change_locally->to_add())); 311 words_, to_change_locally->to_add()));
312 312
313 // Add remote words locally. 313 // Add remote words locally.
314 Apply(*to_change_locally); 314 Apply(*to_change_locally);
315 Notify(*to_change_locally); 315 Notify(*to_change_locally);
316 Save(to_change_locally.Pass()); 316 Save(std::move(to_change_locally));
317 317
318 // Send local changes to the sync server. 318 // Send local changes to the sync server.
319 syncer::SyncMergeResult result(type); 319 syncer::SyncMergeResult result(type);
320 result.set_error(Sync(to_change_remotely)); 320 result.set_error(Sync(to_change_remotely));
321 return result; 321 return result;
322 } 322 }
323 323
324 void SpellcheckCustomDictionary::StopSyncing(syncer::ModelType type) { 324 void SpellcheckCustomDictionary::StopSyncing(syncer::ModelType type) {
325 DCHECK_CURRENTLY_ON(BrowserThread::UI); 325 DCHECK_CURRENTLY_ON(BrowserThread::UI);
326 DCHECK_EQ(syncer::DICTIONARY, type); 326 DCHECK_EQ(syncer::DICTIONARY, type);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 return sync_error_handler_->CreateAndUploadError( 369 return sync_error_handler_->CreateAndUploadError(
370 FROM_HERE, 370 FROM_HERE,
371 "Processing sync changes failed on change type " + 371 "Processing sync changes failed on change type " +
372 syncer::SyncChange::ChangeTypeToString(change.change_type())); 372 syncer::SyncChange::ChangeTypeToString(change.change_type()));
373 } 373 }
374 } 374 }
375 375
376 dictionary_change->Sanitize(GetWords()); 376 dictionary_change->Sanitize(GetWords());
377 Apply(*dictionary_change); 377 Apply(*dictionary_change);
378 Notify(*dictionary_change); 378 Notify(*dictionary_change);
379 Save(dictionary_change.Pass()); 379 Save(std::move(dictionary_change));
380 380
381 return syncer::SyncError(); 381 return syncer::SyncError();
382 } 382 }
383 383
384 SpellcheckCustomDictionary::LoadFileResult::LoadFileResult() 384 SpellcheckCustomDictionary::LoadFileResult::LoadFileResult()
385 : is_valid_file(false) {} 385 : is_valid_file(false) {}
386 386
387 SpellcheckCustomDictionary::LoadFileResult::~LoadFileResult() {} 387 SpellcheckCustomDictionary::LoadFileResult::~LoadFileResult() {}
388 388
389 // static 389 // static
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 } 526 }
527 527
528 void SpellcheckCustomDictionary::Notify(const Change& dictionary_change) { 528 void SpellcheckCustomDictionary::Notify(const Change& dictionary_change) {
529 DCHECK_CURRENTLY_ON(BrowserThread::UI); 529 DCHECK_CURRENTLY_ON(BrowserThread::UI);
530 if (!IsLoaded() || dictionary_change.empty()) 530 if (!IsLoaded() || dictionary_change.empty())
531 return; 531 return;
532 FOR_EACH_OBSERVER(Observer, 532 FOR_EACH_OBSERVER(Observer,
533 observers_, 533 observers_,
534 OnCustomDictionaryChanged(dictionary_change)); 534 OnCustomDictionaryChanged(dictionary_change));
535 } 535 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698