Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/reading_list/ios/reading_list_model_impl.h" | 5 #include "components/reading_list/ios/reading_list_model_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 | 306 |
| 307 const ReadingListEntry& ReadingListModelImpl::AddEntry( | 307 const ReadingListEntry& ReadingListModelImpl::AddEntry( |
| 308 const GURL& url, | 308 const GURL& url, |
| 309 const std::string& title, | 309 const std::string& title, |
| 310 reading_list::EntrySource source) { | 310 reading_list::EntrySource source) { |
| 311 DCHECK(CalledOnValidThread()); | 311 DCHECK(CalledOnValidThread()); |
| 312 DCHECK(loaded()); | 312 DCHECK(loaded()); |
| 313 DCHECK(url.SchemeIsHTTPOrHTTPS()); | 313 DCHECK(url.SchemeIsHTTPOrHTTPS()); |
| 314 RemoveEntryByURL(url); | 314 RemoveEntryByURL(url); |
| 315 | 315 |
| 316 std::string trimmedTitle(title); | 316 std::string trimmed_title = base::CollapseWhitespaceASCII(title, false); |
| 317 base::TrimWhitespaceASCII(trimmedTitle, base::TRIM_ALL, &trimmedTitle); | |
| 318 | 317 |
| 319 ReadingListEntry entry(url, trimmedTitle); | 318 ReadingListEntry entry(url, trimmed_title); |
|
gambard
2017/02/14 08:37:26
What happens if the entry is added with empty titl
Olivier
2017/02/14 08:44:47
tab.title is never empty, so it does not happen wh
Olivier
2017/02/14 09:09:53
Done.
| |
| 320 for (auto& observer : observers_) | 319 for (auto& observer : observers_) |
| 321 observer.ReadingListWillAddEntry(this, entry); | 320 observer.ReadingListWillAddEntry(this, entry); |
| 322 UpdateEntryStateCountersOnEntryInsertion(entry); | 321 UpdateEntryStateCountersOnEntryInsertion(entry); |
| 323 SetUnseenFlag(); | 322 SetUnseenFlag(); |
| 324 entries_->insert(std::make_pair(url, std::move(entry))); | 323 entries_->insert(std::make_pair(url, std::move(entry))); |
| 325 | 324 |
| 326 if (storage_layer_) { | 325 if (storage_layer_) { |
| 327 storage_layer_->SaveEntry(*GetEntryByURL(url)); | 326 storage_layer_->SaveEntry(*GetEntryByURL(url)); |
| 328 } | 327 } |
| 329 | 328 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 364 |
| 366 void ReadingListModelImpl::SetEntryTitle(const GURL& url, | 365 void ReadingListModelImpl::SetEntryTitle(const GURL& url, |
| 367 const std::string& title) { | 366 const std::string& title) { |
| 368 DCHECK(CalledOnValidThread()); | 367 DCHECK(CalledOnValidThread()); |
| 369 DCHECK(loaded()); | 368 DCHECK(loaded()); |
| 370 auto iterator = entries_->find(url); | 369 auto iterator = entries_->find(url); |
| 371 if (iterator == entries_->end()) { | 370 if (iterator == entries_->end()) { |
| 372 return; | 371 return; |
| 373 } | 372 } |
| 374 ReadingListEntry& entry = iterator->second; | 373 ReadingListEntry& entry = iterator->second; |
| 375 if (entry.Title() == title) { | 374 std::string trimmed_title = base::CollapseWhitespaceASCII(title, false); |
| 375 if (entry.Title() == trimmed_title) { | |
| 376 return; | 376 return; |
| 377 } | 377 } |
| 378 | 378 |
| 379 for (ReadingListModelObserver& observer : observers_) { | 379 for (ReadingListModelObserver& observer : observers_) { |
| 380 observer.ReadingListWillUpdateEntry(this, url); | 380 observer.ReadingListWillUpdateEntry(this, url); |
| 381 } | 381 } |
| 382 entry.SetTitle(title); | 382 entry.SetTitle(trimmed_title); |
| 383 if (storage_layer_) { | 383 if (storage_layer_) { |
| 384 storage_layer_->SaveEntry(entry); | 384 storage_layer_->SaveEntry(entry); |
| 385 } | 385 } |
| 386 for (ReadingListModelObserver& observer : observers_) { | 386 for (ReadingListModelObserver& observer : observers_) { |
| 387 observer.ReadingListDidApplyChanges(this); | 387 observer.ReadingListDidApplyChanges(this); |
| 388 } | 388 } |
| 389 } | 389 } |
| 390 | 390 |
| 391 void ReadingListModelImpl::SetEntryDistilledInfo( | 391 void ReadingListModelImpl::SetEntryDistilledInfo( |
| 392 const GURL& url, | 392 const GURL& url, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 syncer::ModelTypeSyncBridge* ReadingListModelImpl::GetModelTypeSyncBridge() { | 496 syncer::ModelTypeSyncBridge* ReadingListModelImpl::GetModelTypeSyncBridge() { |
| 497 DCHECK(loaded()); | 497 DCHECK(loaded()); |
| 498 if (!storage_layer_) | 498 if (!storage_layer_) |
| 499 return nullptr; | 499 return nullptr; |
| 500 return storage_layer_.get(); | 500 return storage_layer_.get(); |
| 501 } | 501 } |
| 502 | 502 |
| 503 ReadingListModelStorage* ReadingListModelImpl::StorageLayer() { | 503 ReadingListModelStorage* ReadingListModelImpl::StorageLayer() { |
| 504 return storage_layer_.get(); | 504 return storage_layer_.get(); |
| 505 } | 505 } |
| OLD | NEW |