summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorian@chromium.org <ian@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 18:44:48 +0000
committerian@chromium.org <ian@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 18:44:48 +0000
commit0457c6bb559c2cebf47235388f0441be51817d60 (patch)
treec0cabb4c18a45d1f5d48df8bb19e6442ad95b357
parente06131db8c610bca50a025fc876755d0aa42e53c (diff)
downloadchromium_src-0457c6bb559c2cebf47235388f0441be51817d60.zip
chromium_src-0457c6bb559c2cebf47235388f0441be51817d60.tar.gz
chromium_src-0457c6bb559c2cebf47235388f0441be51817d60.tar.bz2
Fixes a bug where if there are only localstorage nodes, but nocookies nodes, the Remove and Remove All buttons are disabled.BUG=34886
TEST=clear all cookies, go to www.ianfette.com/localstorage.html and open cookies dialog, check that remove button is enabled. Review URL: http://codereview.chromium.org/596002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38640 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/tree_model.h7
-rw-r--r--app/tree_node_model.h36
-rw-r--r--chrome/browser/bookmarks/bookmark_folder_tree_model.cc10
-rw-r--r--chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc2
-rw-r--r--chrome/browser/cocoa/cookies_window_controller.mm2
-rw-r--r--chrome/browser/views/options/cookies_view.cc38
-rw-r--r--chrome/browser/views/options/cookies_view.h26
-rw-r--r--chrome/common/gtk_tree.cc2
-rw-r--r--views/controls/tree/tree_view.cc8
9 files changed, 93 insertions, 38 deletions
diff --git a/app/tree_model.h b/app/tree_model.h
index 9ce6cb1..fceb22d 100644
--- a/app/tree_model.h
+++ b/app/tree_model.h
@@ -74,8 +74,11 @@ class TreeModel {
// Returns the parent of a node, or NULL if node is the root.
virtual TreeModelNode* GetParent(TreeModelNode* node) = 0;
- // Sets the observer of the model.
- virtual void SetObserver(TreeModelObserver* observer) = 0;
+ // Adds an observer of the model.
+ virtual void AddObserver(TreeModelObserver* observer) = 0;
+
+ // Removes an observer of the model.
+ virtual void RemoveObserver(TreeModelObserver* observer) = 0;
// Sets the title of the specified node.
// This is only invoked if the node is editable and the user edits a node.
diff --git a/app/tree_node_model.h b/app/tree_node_model.h
index b47fe03..0d9f2b9 100644
--- a/app/tree_node_model.h
+++ b/app/tree_node_model.h
@@ -11,6 +11,7 @@
#include "app/tree_model.h"
#include "base/basictypes.h"
+#include "base/observer_list.h"
#include "base/scoped_ptr.h"
#include "base/scoped_vector.h"
#include "base/stl_util-inl.h"
@@ -231,18 +232,18 @@ class TreeNodeModel : public TreeModel {
// Creates a TreeNodeModel with the specified root node. The root is owned
// by the TreeNodeModel.
explicit TreeNodeModel(NodeType* root)
- : root_(root),
- observer_(NULL) {
+ : root_(root) {
}
virtual ~TreeNodeModel() {}
- virtual void SetObserver(TreeModelObserver* observer) {
- observer_ = observer;
+ // Observer methods, calls into ObserverList.
+ virtual void AddObserver(TreeModelObserver* observer) {
+ observer_list_.AddObserver(observer);
}
- TreeModelObserver* GetObserver() {
- return observer_;
+ virtual void RemoveObserver(TreeModelObserver* observer) {
+ observer_list_.RemoveObserver(observer);
}
// TreeModel methods, all forward to the nodes.
@@ -294,27 +295,32 @@ class TreeNodeModel : public TreeModel {
}
void NotifyObserverTreeNodesAdded(NodeType* parent, int start, int count) {
- if (observer_)
- observer_->TreeNodesAdded(this, parent, start, count);
+ FOR_EACH_OBSERVER(TreeModelObserver,
+ observer_list_,
+ TreeNodesAdded(this, parent, start, count));
}
void NotifyObserverTreeNodesRemoved(NodeType* parent, int start, int count) {
- if (observer_)
- observer_->TreeNodesRemoved(this, parent, start, count);
+ FOR_EACH_OBSERVER(TreeModelObserver,
+ observer_list_,
+ TreeNodesRemoved(this, parent, start, count));
}
virtual void NotifyObserverTreeNodeChanged(TreeModelNode* node) {
- if (observer_)
- observer_->TreeNodeChanged(this, node);
+ FOR_EACH_OBSERVER(TreeModelObserver,
+ observer_list_,
+ TreeNodeChanged(this, node));
}
+ protected:
+ ObserverList<TreeModelObserver>& observer_list() { return observer_list_; }
+
private:
+ // The observers.
+ ObserverList<TreeModelObserver> observer_list_;
// The root.
scoped_ptr<NodeType> root_;
- // The observer.
- TreeModelObserver* observer_;
-
DISALLOW_COPY_AND_ASSIGN(TreeNodeModel);
};
diff --git a/chrome/browser/bookmarks/bookmark_folder_tree_model.cc b/chrome/browser/bookmarks/bookmark_folder_tree_model.cc
index 2591fd0..e8b3827 100644
--- a/chrome/browser/bookmarks/bookmark_folder_tree_model.cc
+++ b/chrome/browser/bookmarks/bookmark_folder_tree_model.cc
@@ -128,8 +128,9 @@ void BookmarkFolderTreeModel::BookmarkNodeChanged(BookmarkModel* model,
return;
folder_node->SetTitle(node->GetTitle());
- if (GetObserver())
- GetObserver()->TreeNodeChanged(this, folder_node);
+ FOR_EACH_OBSERVER(TreeModelObserver,
+ observer_list(),
+ TreeNodeChanged(this, folder_node));
}
void BookmarkFolderTreeModel::BookmarkNodeChildrenReordered(
@@ -162,8 +163,9 @@ void BookmarkFolderTreeModel::BookmarkNodeChildrenReordered(
DCHECK(original_count == folder_node->GetChildCount());
// Finally, notify observers.
- if (GetObserver())
- GetObserver()->TreeNodeChildrenReordered(this, folder_node);
+ FOR_EACH_OBSERVER(TreeModelObserver,
+ observer_list(),
+ TreeNodeChildrenReordered(this, folder_node));
}
void BookmarkFolderTreeModel::GetIcons(std::vector<SkBitmap>* icons) {
diff --git a/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc b/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
index 2f9b3b5..c1c9a68 100644
--- a/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
+++ b/chrome/browser/bookmarks/bookmark_folder_tree_model_unittest.cc
@@ -54,7 +54,7 @@ class BookmarkFolderTreeModelTest : public testing::Test,
bookmark_model()->AddURL(other, 2, L"url3", url3_);
model_.reset(new BookmarkFolderTreeModel(bookmark_model()));
- model_->SetObserver(this);
+ model_->AddObserver(this);
}
virtual void TearDown() {
diff --git a/chrome/browser/cocoa/cookies_window_controller.mm b/chrome/browser/cocoa/cookies_window_controller.mm
index b61145a..cec7f71 100644
--- a/chrome/browser/cocoa/cookies_window_controller.mm
+++ b/chrome/browser/cocoa/cookies_window_controller.mm
@@ -381,7 +381,7 @@ bool CookiesTreeModelObserverBridge::HasCocoaModel() {
treeModel_.reset(new CookiesTreeModel(profile_, databaseHelper_,
storageHelper_));
modelObserver_.reset(new CookiesTreeModelObserverBridge(self));
- treeModel_->SetObserver(modelObserver_.get());
+ treeModel_->AddObserver(modelObserver_.get());
// Convert the model's icons from Skia to Cocoa.
std::vector<SkBitmap> skiaIcons;
diff --git a/chrome/browser/views/options/cookies_view.cc b/chrome/browser/views/options/cookies_view.cc
index bcfa0a20..e952d51 100644
--- a/chrome/browser/views/options/cookies_view.cc
+++ b/chrome/browser/views/options/cookies_view.cc
@@ -84,6 +84,16 @@ CookiesView::~CookiesView() {
}
///////////////////////////////////////////////////////////////////////////////
+// CookiesView, TreeModelObserver overrides:
+
+void CookiesView::TreeNodesAdded(TreeModel* model,
+ TreeModelNode* parent,
+ int start,
+ int count) {
+ UpdateRemoveButtonsState();
+}
+
+///////////////////////////////////////////////////////////////////////////////
// CookiesView, views::Buttonlistener implementation:
void CookiesView::ButtonPressed(
@@ -205,6 +215,17 @@ void CookiesView::OnTreeViewKeyDown(base::KeyboardCode keycode) {
}
///////////////////////////////////////////////////////////////////////////////
+// CookiesView, public:
+
+void CookiesView::UpdateSearchResults() {
+ cookies_tree_model_->UpdateSearchResults(search_field_->text());
+ remove_button_->SetEnabled(cookies_tree_model_->GetRoot()->
+ GetTotalNodeCount() > 1);
+ remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()->
+ GetTotalNodeCount() > 1);
+}
+
+///////////////////////////////////////////////////////////////////////////////
// CookiesView, private:
CookiesView::CookiesView(Profile* profile)
@@ -223,15 +244,6 @@ CookiesView::CookiesView(Profile* profile)
ALLOW_THIS_IN_INITIALIZER_LIST(search_update_factory_(this)) {
}
-
-void CookiesView::UpdateSearchResults() {
- cookies_tree_model_->UpdateSearchResults(search_field_->text());
- remove_button_->SetEnabled(cookies_tree_model_->GetRoot()->
- GetTotalNodeCount() > 1);
- remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()->
- GetTotalNodeCount() > 1);
-}
-
void CookiesView::Init() {
search_label_ = new views::Label(
l10n_util::GetString(IDS_COOKIES_SEARCH_LABEL));
@@ -246,6 +258,7 @@ void CookiesView::Init() {
cookies_tree_model_.reset(new CookiesTreeModel(profile_,
new BrowsingDataDatabaseHelper(profile_),
new BrowsingDataLocalStorageHelper(profile_)));
+ cookies_tree_model_->AddObserver(this);
cookie_info_view_ = new CookieInfoView(false);
database_info_view_ = new DatabaseInfoView;
local_storage_info_view_ = new LocalStorageInfoView;
@@ -327,6 +340,13 @@ void CookiesView::UpdateForEmptyState() {
UpdateVisibleDetailedInfo(cookie_info_view_);
}
+void CookiesView::UpdateRemoveButtonsState() {
+ remove_button_->SetEnabled(cookies_tree_model_->GetRoot()->
+ GetTotalNodeCount() > 1);
+ remove_all_button_->SetEnabled(cookies_tree_model_->GetRoot()->
+ GetTotalNodeCount() > 1);
+}
+
void CookiesView::UpdateVisibleDetailedInfo(views::View* view) {
view->SetVisible(true);
if (view != cookie_info_view_)
diff --git a/chrome/browser/views/options/cookies_view.h b/chrome/browser/views/options/cookies_view.h
index 0010fbc..f16d0cb 100644
--- a/chrome/browser/views/options/cookies_view.h
+++ b/chrome/browser/views/options/cookies_view.h
@@ -7,6 +7,7 @@
#include <string>
+#include "app/tree_model.h"
#include "base/task.h"
#include "net/base/cookie_monster.h"
#include "views/controls/button/button.h"
@@ -33,7 +34,8 @@ class Profile;
class Timer;
-class CookiesView : public views::View,
+class CookiesView : public TreeModelObserver,
+ public views::View,
public views::DialogDelegate,
public views::ButtonListener,
public views::TreeViewController,
@@ -47,6 +49,25 @@ class CookiesView : public views::View,
// Updates the display to show only the search results.
void UpdateSearchResults();
+ // TreeModelObserver implementation.
+ virtual void TreeNodesAdded(TreeModel* model,
+ TreeModelNode* parent,
+ int start,
+ int count);
+
+ // TreeModelObserver implementation.
+ virtual void TreeNodesRemoved(TreeModel* model,
+ TreeModelNode* parent,
+ int start,
+ int count) {}
+
+ // TreeModelObserver implementation.
+ virtual void TreeNodeChildrenReordered(TreeModel* model,
+ TreeModelNode* parent) {}
+
+ // TreeModelObserver implementation.
+ virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node) {}
+
// views::ButtonListener implementation.
virtual void ButtonPressed(views::Button* sender, const views::Event& event);
@@ -107,6 +128,9 @@ class CookiesView : public views::View,
// Update the UI when a local storage is selected.
void UpdateForLocalStorageState();
+ // Enable or disable the remove and remove all buttons.
+ void UpdateRemoveButtonsState();
+
// Updates view to be visible inside detailed_info_view_;
void UpdateVisibleDetailedInfo(views::View* view);
diff --git a/chrome/common/gtk_tree.cc b/chrome/common/gtk_tree.cc
index fbab4de..625c248 100644
--- a/chrome/common/gtk_tree.cc
+++ b/chrome/common/gtk_tree.cc
@@ -152,7 +152,7 @@ TreeAdapter::TreeAdapter(Delegate* delegate, TreeModel* tree_model)
GDK_TYPE_PIXBUF,
G_TYPE_STRING,
G_TYPE_POINTER);
- tree_model->SetObserver(this);
+ tree_model->AddObserver(this);
std::vector<SkBitmap> icons;
tree_model->GetIcons(&icons);
diff --git a/views/controls/tree/tree_view.cc b/views/controls/tree/tree_view.cc
index 4b87cde..68bd822 100644
--- a/views/controls/tree/tree_view.cc
+++ b/views/controls/tree/tree_view.cc
@@ -45,7 +45,7 @@ TreeView::TreeView()
TreeView::~TreeView() {
if (model_)
- model_->SetObserver(NULL);
+ model_->RemoveObserver(this);
// Both param_to_details_map_ and node_to_details_map_ have the same value,
// as such only need to delete from one.
STLDeleteContainerPairSecondPointers(id_to_details_map_.begin(),
@@ -60,11 +60,11 @@ void TreeView::SetModel(TreeModel* model) {
if (model_ && tree_view_)
DeleteRootItems();
if (model_)
- model_->SetObserver(NULL);
+ model_->RemoveObserver(this);
model_ = model;
if (tree_view_ && model_) {
CreateRootItems();
- model_->SetObserver(this);
+ model_->AddObserver(this);
HIMAGELIST last_image_list = image_list_;
image_list_ = CreateImageList();
TreeView_SetImageList(tree_view_, image_list_, TVSIL_NORMAL);
@@ -370,7 +370,7 @@ HWND TreeView::CreateNativeControl(HWND parent_container) {
if (model_) {
CreateRootItems();
- model_->SetObserver(this);
+ model_->AddObserver(this);
image_list_ = CreateImageList();
TreeView_SetImageList(tree_view_, image_list_, TVSIL_NORMAL);
}