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

Side by Side Diff: chrome/browser/views/bookmark_bar_view.cc

Issue 2822010: Fixes bug in bookmark bar view if profile changed. If the profile (Closed)
Patch Set: Created 10 years, 6 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/views/bookmark_bar_view.h" 5 #include "chrome/browser/views/bookmark_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 model_->RemoveObserver(this); 437 model_->RemoveObserver(this);
438 438
439 // Disable the other bookmarked button, we'll re-enable when the model is 439 // Disable the other bookmarked button, we'll re-enable when the model is
440 // loaded. 440 // loaded.
441 other_bookmarked_button_->SetEnabled(false); 441 other_bookmarked_button_->SetEnabled(false);
442 442
443 Source<Profile> ns_source(profile_->GetOriginalProfile()); 443 Source<Profile> ns_source(profile_->GetOriginalProfile());
444 registrar_.Add(this, NotificationType::BOOKMARK_BUBBLE_SHOWN, ns_source); 444 registrar_.Add(this, NotificationType::BOOKMARK_BUBBLE_SHOWN, ns_source);
445 registrar_.Add(this, NotificationType::BOOKMARK_BUBBLE_HIDDEN, ns_source); 445 registrar_.Add(this, NotificationType::BOOKMARK_BUBBLE_HIDDEN, ns_source);
446 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 446 registrar_.Add(this, NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
447 NotificationService::AllSources()); 447 NotificationService::AllSources());
448
449 // Remove any existing bookmark buttons.
450 while (GetBookmarkButtonCount())
451 delete GetChildViewAt(0);
448 452
449 model_ = profile_->GetBookmarkModel(); 453 model_ = profile_->GetBookmarkModel();
450 model_->AddObserver(this); 454 model_->AddObserver(this);
451 if (model_->IsLoaded()) 455 if (model_->IsLoaded())
452 Loaded(model_); 456 Loaded(model_);
453
454 // else case: we'll receive notification back from the BookmarkModel when done 457 // else case: we'll receive notification back from the BookmarkModel when done
455 // loading, then we'll populate the bar. 458 // loading, then we'll populate the bar.
456 } 459 }
457 460
458 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { 461 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) {
459 page_navigator_ = navigator; 462 page_navigator_ = navigator;
460 } 463 }
461 464
462 gfx::Size BookmarkBarView::GetPreferredSize() { 465 gfx::Size BookmarkBarView::GetPreferredSize() {
463 // Extension apps don't show the bookmark bar. 466 // Extension apps don't show the bookmark bar.
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 button->EnableCanvasFlippingForRTLUI(true); 944 button->EnableCanvasFlippingForRTLUI(true);
942 945
943 // Make visible as necessary. 946 // Make visible as necessary.
944 button->SetVisible(false); 947 button->SetVisible(false);
945 // Set accessibility name. 948 // Set accessibility name.
946 button->SetAccessibleName( 949 button->SetAccessibleName(
947 l10n_util::GetString(IDS_ACCNAME_BOOKMARKS_CHEVRON)); 950 l10n_util::GetString(IDS_ACCNAME_BOOKMARKS_CHEVRON));
948 return button; 951 return button;
949 } 952 }
950 953
951 int BookmarkBarView::GetBookmarkButtonCount() {
952 // We contain at least four non-bookmark button views: other bookmarks,
953 // bookmarks separator, chevrons (for overflow), the instruction label and
954 // the sync error button.
955 return GetChildViewCount() - 5;
956 }
957
958 void BookmarkBarView::Loaded(BookmarkModel* model) { 954 void BookmarkBarView::Loaded(BookmarkModel* model) {
955 volatile int button_count = GetBookmarkButtonCount();
956 CHECK(button_count == 0); // If non-zero it means Load was invoked more than
957 // once, or we didn't properly clear things. Either
958 // of which shouldn't happen
959 const BookmarkNode* node = model_->GetBookmarkBarNode(); 959 const BookmarkNode* node = model_->GetBookmarkBarNode();
960 DCHECK(node && model_->other_node()); 960 DCHECK(node && model_->other_node());
961 // Create a button for each of the children on the bookmark bar. 961 // Create a button for each of the children on the bookmark bar.
962 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) 962 for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i)
963 AddChildView(i, CreateBookmarkButton(node->GetChild(i))); 963 AddChildView(i, CreateBookmarkButton(node->GetChild(i)));
964 UpdateColors(); 964 UpdateColors();
965 other_bookmarked_button_->SetEnabled(true); 965 other_bookmarked_button_->SetEnabled(true);
966 966
967 Layout(); 967 Layout();
968 SchedulePaint(); 968 SchedulePaint();
969
970 CheckIntegrity();
969 } 971 }
970 972
971 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { 973 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
972 // The bookmark model should never be deleted before us. This code exists 974 // The bookmark model should never be deleted before us. This code exists
973 // to check for regressions in shutdown code and not crash. 975 // to check for regressions in shutdown code and not crash.
974 NOTREACHED(); 976 NOTREACHED();
975 977
976 // Do minimal cleanup, presumably we'll be deleted shortly. 978 // Do minimal cleanup, presumably we'll be deleted shortly.
977 NotifyModelChanged(); 979 NotifyModelChanged();
978 model_->RemoveObserver(this); 980 model_->RemoveObserver(this);
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 } 1552 }
1551 } else if (!overflow_only) { 1553 } else if (!overflow_only) {
1552 throbbing_view_ = other_bookmarked_button_; 1554 throbbing_view_ = other_bookmarked_button_;
1553 } 1555 }
1554 1556
1555 // Use a large number so that the button continues to throb. 1557 // Use a large number so that the button continues to throb.
1556 if (throbbing_view_) 1558 if (throbbing_view_)
1557 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); 1559 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max());
1558 } 1560 }
1559 1561
1562 int BookmarkBarView::GetBookmarkButtonCount() {
1563 // We contain at least four non-bookmark button views: other bookmarks,
1564 // bookmarks separator, chevrons (for overflow), the instruction label and
1565 // the sync error button.
1566 return GetChildViewCount() - 5;
1567 }
1568
1560 void BookmarkBarView::StopThrobbing(bool immediate) { 1569 void BookmarkBarView::StopThrobbing(bool immediate) {
1561 if (!throbbing_view_) 1570 if (!throbbing_view_)
1562 return; 1571 return;
1563 1572
1564 // If not immediate, cycle through 2 more complete cycles. 1573 // If not immediate, cycle through 2 more complete cycles.
1565 throbbing_view_->StartThrobbing(immediate ? 0 : 4); 1574 throbbing_view_->StartThrobbing(immediate ? 0 : 4);
1566 throbbing_view_ = NULL; 1575 throbbing_view_ = NULL;
1567 } 1576 }
1568 1577
1569 void BookmarkBarView::UpdateColors() { 1578 void BookmarkBarView::UpdateColors() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 1743
1735 void BookmarkBarView::CheckIntegrity() { 1744 void BookmarkBarView::CheckIntegrity() {
1736 // We better be on the ui thread. 1745 // We better be on the ui thread.
1737 CHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); 1746 CHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
1738 1747
1739 // And the number of views on the bookmark bar better match that of the model. 1748 // And the number of views on the bookmark bar better match that of the model.
1740 volatile int model_count = model_->GetBookmarkBarNode()->GetChildCount(); 1749 volatile int model_count = model_->GetBookmarkBarNode()->GetChildCount();
1741 volatile int view_count = GetBookmarkButtonCount(); 1750 volatile int view_count = GetBookmarkButtonCount();
1742 CHECK_EQ(model_count, view_count); 1751 CHECK_EQ(model_count, view_count);
1743 } 1752 }
OLDNEW
« no previous file with comments | « chrome/browser/views/bookmark_bar_view.h ('k') | chrome/browser/views/bookmark_bar_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698