| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/bookmarks/bookmark_model.h" | 5 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/gfx/png_decoder.h" | 8 #include "base/gfx/png_decoder.h" |
| 9 #include "base/scoped_vector.h" | 9 #include "base/scoped_vector.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 private: | 82 private: |
| 83 Collator* collator_; | 83 Collator* collator_; |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 } // namespace | 86 } // namespace |
| 87 | 87 |
| 88 BookmarkModel::BookmarkModel(Profile* profile) | 88 BookmarkModel::BookmarkModel(Profile* profile) |
| 89 : profile_(profile), | 89 : profile_(profile), |
| 90 loaded_(false), | 90 loaded_(false), |
| 91 persist_ids_(false), | 91 persist_ids_(false), |
| 92 file_changed_(false), |
| 92 root_(GURL()), | 93 root_(GURL()), |
| 93 bookmark_bar_node_(NULL), | 94 bookmark_bar_node_(NULL), |
| 94 other_node_(NULL), | 95 other_node_(NULL), |
| 95 next_node_id_(1), | 96 next_node_id_(1), |
| 96 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), | 97 observers_(ObserverList<BookmarkModelObserver>::NOTIFY_EXISTING_ONLY), |
| 97 loaded_signal_(TRUE, FALSE) { | 98 loaded_signal_(TRUE, FALSE) { |
| 98 if (!profile_) { | 99 if (!profile_) { |
| 99 // Profile is null during testing. | 100 // Profile is null during testing. |
| 100 DoneLoading(CreateLoadDetails()); | 101 DoneLoading(CreateLoadDetails()); |
| 101 } | 102 } |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 386 } |
| 386 | 387 |
| 387 void BookmarkModel::SetPersistIDs(bool value) { | 388 void BookmarkModel::SetPersistIDs(bool value) { |
| 388 if (value == persist_ids_) | 389 if (value == persist_ids_) |
| 389 return; | 390 return; |
| 390 persist_ids_ = value; | 391 persist_ids_ = value; |
| 391 if (profile_) { | 392 if (profile_) { |
| 392 PrefService* pref_service = profile_->GetPrefs(); | 393 PrefService* pref_service = profile_->GetPrefs(); |
| 393 pref_service->SetBoolean(kPrefPersistIDs, persist_ids_); | 394 pref_service->SetBoolean(kPrefPersistIDs, persist_ids_); |
| 394 } | 395 } |
| 396 // Need to save the bookmark data if the value of persist IDs changes. |
| 397 if (store_.get()) |
| 398 store_->ScheduleSave(); |
| 395 } | 399 } |
| 396 | 400 |
| 397 bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) { | 401 bool BookmarkModel::IsBookmarkedNoLock(const GURL& url) { |
| 398 BookmarkNode tmp_node(url); | 402 BookmarkNode tmp_node(url); |
| 399 return (nodes_ordered_by_url_set_.find(&tmp_node) != | 403 return (nodes_ordered_by_url_set_.find(&tmp_node) != |
| 400 nodes_ordered_by_url_set_.end()); | 404 nodes_ordered_by_url_set_.end()); |
| 401 } | 405 } |
| 402 | 406 |
| 403 void BookmarkModel::FavIconLoaded(BookmarkNode* node) { | 407 void BookmarkModel::FavIconLoaded(BookmarkNode* node) { |
| 404 // Send out notification to the observer. | 408 // Send out notification to the observer. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 scoped_ptr<BookmarkStorage::LoadDetails> details(details_delete_me); | 446 scoped_ptr<BookmarkStorage::LoadDetails> details(details_delete_me); |
| 443 if (loaded_) { | 447 if (loaded_) { |
| 444 // We should only ever be loaded once. | 448 // We should only ever be loaded once. |
| 445 NOTREACHED(); | 449 NOTREACHED(); |
| 446 return; | 450 return; |
| 447 } | 451 } |
| 448 | 452 |
| 449 bookmark_bar_node_ = details->bb_node(); | 453 bookmark_bar_node_ = details->bb_node(); |
| 450 other_node_ = details->other_folder_node(); | 454 other_node_ = details->other_folder_node(); |
| 451 next_node_id_ = details->max_id(); | 455 next_node_id_ = details->max_id(); |
| 456 if (details->computed_checksum() != details->stored_checksum()) |
| 457 SetFileChanged(); |
| 452 index_.reset(details->index()); | 458 index_.reset(details->index()); |
| 453 details->release(); | 459 details->release(); |
| 454 | 460 |
| 455 // WARNING: order is important here, various places assume bookmark bar then | 461 // WARNING: order is important here, various places assume bookmark bar then |
| 456 // other node. | 462 // other node. |
| 457 root_.Add(0, bookmark_bar_node_); | 463 root_.Add(0, bookmark_bar_node_); |
| 458 root_.Add(1, other_node_); | 464 root_.Add(1, other_node_); |
| 459 | 465 |
| 460 { | 466 { |
| 461 AutoLock url_lock(url_lock_); | 467 AutoLock url_lock(url_lock_); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 if (node->is_url()) | 699 if (node->is_url()) |
| 694 nodes_ordered_by_url_set_.insert(node); | 700 nodes_ordered_by_url_set_.insert(node); |
| 695 for (int i = 0; i < node->GetChildCount(); ++i) | 701 for (int i = 0; i < node->GetChildCount(); ++i) |
| 696 PopulateNodesByURL(node->GetChild(i)); | 702 PopulateNodesByURL(node->GetChild(i)); |
| 697 } | 703 } |
| 698 | 704 |
| 699 int BookmarkModel::generate_next_node_id() { | 705 int BookmarkModel::generate_next_node_id() { |
| 700 return next_node_id_++; | 706 return next_node_id_++; |
| 701 } | 707 } |
| 702 | 708 |
| 709 void BookmarkModel::SetFileChanged() { |
| 710 file_changed_ = true; |
| 711 // If bookmarks file changed externally, the IDs may have changed externally. |
| 712 // in that case, the decoder may have reassigned IDs to make them unique. |
| 713 // So when the file has changed externally and IDs are persisted, we should |
| 714 // save the bookmarks file to persist new IDs. |
| 715 if (persist_ids_ && store_.get()) |
| 716 store_->ScheduleSave(); |
| 717 } |
| 718 |
| 703 BookmarkStorage::LoadDetails* BookmarkModel::CreateLoadDetails() { | 719 BookmarkStorage::LoadDetails* BookmarkModel::CreateLoadDetails() { |
| 704 BookmarkNode* bb_node = CreateBookmarkNode(); | 720 BookmarkNode* bb_node = CreateBookmarkNode(); |
| 705 BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); | 721 BookmarkNode* other_folder_node = CreateOtherBookmarksNode(); |
| 706 return new BookmarkStorage::LoadDetails( | 722 return new BookmarkStorage::LoadDetails( |
| 707 bb_node, other_folder_node, new BookmarkIndex(), next_node_id_); | 723 bb_node, other_folder_node, new BookmarkIndex(), next_node_id_); |
| 708 } | 724 } |
| 709 | 725 |
| 710 void BookmarkModel::RegisterPreferences() { | 726 void BookmarkModel::RegisterPreferences() { |
| 711 if (!profile_) | 727 if (!profile_) |
| 712 return; | 728 return; |
| 713 PrefService* pref_service = profile_->GetPrefs(); | 729 PrefService* pref_service = profile_->GetPrefs(); |
| 714 if (!pref_service->IsPrefRegistered(kPrefPersistIDs)) | 730 if (!pref_service->IsPrefRegistered(kPrefPersistIDs)) |
| 715 pref_service->RegisterBooleanPref(kPrefPersistIDs, false); | 731 pref_service->RegisterBooleanPref(kPrefPersistIDs, false); |
| 716 } | 732 } |
| 717 | 733 |
| 718 void BookmarkModel::LoadPreferences() { | 734 void BookmarkModel::LoadPreferences() { |
| 719 if (!profile_) | 735 if (!profile_) |
| 720 return; | 736 return; |
| 721 PrefService* pref_service = profile_->GetPrefs(); | 737 PrefService* pref_service = profile_->GetPrefs(); |
| 722 persist_ids_ = pref_service->GetBoolean(kPrefPersistIDs); | 738 persist_ids_ = pref_service->GetBoolean(kPrefPersistIDs); |
| 723 } | 739 } |
| OLD | NEW |