diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 20:13:01 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-09 20:13:01 +0000 |
commit | 5fb74d2acbc5f53203e828f5a74d2600233ca04c (patch) | |
tree | 518c17ad77de691c6337c8d09246dc7d5c9f1213 | |
parent | 76138b78caa7365ed9af0e2a76b1ceb75a8e40db (diff) | |
download | chromium_src-5fb74d2acbc5f53203e828f5a74d2600233ca04c.zip chromium_src-5fb74d2acbc5f53203e828f5a74d2600233ca04c.tar.gz chromium_src-5fb74d2acbc5f53203e828f5a74d2600233ca04c.tar.bz2 |
BUG=8345
Added a PasswordManagerTableModelObserver to listen for row count change events.
PasswordManagerView and PasswordManagerExceptionsView are listening to the
event.
Move the |instance_| variable from static global to the respective class to
avoid future misuse of the variable.
Review URL: http://codereview.chromium.org/39313
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11279 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/views/password_manager_exceptions_view.cc | 11 | ||||
-rw-r--r-- | chrome/browser/views/password_manager_exceptions_view.h | 8 | ||||
-rw-r--r-- | chrome/browser/views/password_manager_view.cc | 24 | ||||
-rw-r--r-- | chrome/browser/views/password_manager_view.h | 34 |
4 files changed, 63 insertions, 14 deletions
diff --git a/chrome/browser/views/password_manager_exceptions_view.cc b/chrome/browser/views/password_manager_exceptions_view.cc index 9d41a85..a501a60 100644 --- a/chrome/browser/views/password_manager_exceptions_view.cc +++ b/chrome/browser/views/password_manager_exceptions_view.cc @@ -18,7 +18,7 @@ using views::ColumnSet; using views::GridLayout; // We can only have one PasswordManagerExceptionsView at a time. -static PasswordManagerExceptionsView* instance_ = NULL; +PasswordManagerExceptionsView* PasswordManagerExceptionsView::instance_ = NULL; static const int kDefaultWindowWidth = 530; static const int kDefaultWindowHeight = 240; @@ -74,6 +74,8 @@ void PasswordManagerExceptionsTableModel::OnWebDataServiceRequestDone( } if (observer_) observer_->OnModelChanged(); + if (row_count_observer_) + row_count_observer_->OnRowCountChanged(RowCount()); } ////////////////////////////////////////////////////////////////////// @@ -105,6 +107,9 @@ PasswordManagerExceptionsView::PasswordManagerExceptionsView(Profile* profile) } void PasswordManagerExceptionsView::SetupTable() { + // Tell the table model we are concern about how many rows it has. + table_model_.set_row_count_observer(this); + // Creates the different columns for the table. // The float resize values are the result of much tinkering. std::vector<views::TableColumn> columns; @@ -240,3 +245,7 @@ void PasswordManagerExceptionsView::WindowClosing() { views::View* PasswordManagerExceptionsView::GetContentsView() { return this; } + +void PasswordManagerExceptionsView::OnRowCountChanged(size_t rows) { + remove_all_button_.SetEnabled(rows > 0); +} diff --git a/chrome/browser/views/password_manager_exceptions_view.h b/chrome/browser/views/password_manager_exceptions_view.h index 1ae684c..0151a5b 100644 --- a/chrome/browser/views/password_manager_exceptions_view.h +++ b/chrome/browser/views/password_manager_exceptions_view.h @@ -38,7 +38,8 @@ class PasswordManagerExceptionsTableModel : public PasswordManagerTableModel { class PasswordManagerExceptionsView : public views::View, public views::DialogDelegate, public views::TableViewObserver, - public views::NativeButton::Listener { + public views::NativeButton::Listener, + public PasswordManagerTableModelObserver { public: explicit PasswordManagerExceptionsView(Profile* profile); virtual ~PasswordManagerExceptionsView(); @@ -68,6 +69,9 @@ class PasswordManagerExceptionsView : public views::View, virtual void WindowClosing(); virtual views::View* GetContentsView(); + // PasswordManagerTableModelObserver implementation. + virtual void OnRowCountChanged(size_t rows); + private: // Wire up buttons, the model, and the table view, and query the DB for // exception data tied to the given profile. @@ -87,6 +91,8 @@ class PasswordManagerExceptionsView : public views::View, views::NativeButton remove_button_; views::NativeButton remove_all_button_; + static PasswordManagerExceptionsView* instance_; + DISALLOW_EVIL_CONSTRUCTORS(PasswordManagerExceptionsView); }; #endif // CHROME_BROWSER_PASSWORD_MANAGER_EXCEPTIONS_VIEW_H__ diff --git a/chrome/browser/views/password_manager_view.cc b/chrome/browser/views/password_manager_view.cc index bdc877d..63d8c73 100644 --- a/chrome/browser/views/password_manager_view.cc +++ b/chrome/browser/views/password_manager_view.cc @@ -17,8 +17,7 @@ using views::ColumnSet; using views::GridLayout; -// We can only have one PasswordManagerView at a time. -static PasswordManagerView* instance_ = NULL; +PasswordManagerView* PasswordManagerView::instance_ = NULL; static const int kDefaultWindowWidth = 530; static const int kDefaultWindowHeight = 240; @@ -55,6 +54,7 @@ gfx::Size MultiLabelButtons::GetPreferredSize() { // PasswordManagerTableModel PasswordManagerTableModel::PasswordManagerTableModel(Profile* profile) : observer_(NULL), + row_count_observer_(NULL), pending_login_query_(NULL), saved_signons_cleanup_(&saved_signons_), profile_(profile) { @@ -135,9 +135,10 @@ void PasswordManagerTableModel::OnWebDataServiceRequestDone( saved_signons_[i] = new PasswordRow( gfx::SortedDisplayURL(rows[i]->origin, languages), rows[i]); } - instance_->SetRemoveAllEnabled(RowCount() != 0); if (observer_) observer_->OnModelChanged(); + if (row_count_observer_) + row_count_observer_->OnRowCountChanged(RowCount()); } void PasswordManagerTableModel::CancelLoginsQuery() { @@ -160,9 +161,10 @@ void PasswordManagerTableModel::ForgetAndRemoveSignon(int row) { web_data_service()->RemoveLogin(*(password_row->form.get())); delete password_row; saved_signons_.erase(target_iter); - instance_->SetRemoveAllEnabled(RowCount() != 0); if (observer_) observer_->OnItemsRemoved(row, 1); + if (row_count_observer_) + row_count_observer_->OnRowCountChanged(RowCount()); } void PasswordManagerTableModel::ForgetAndRemoveAllSignons() { @@ -174,9 +176,10 @@ void PasswordManagerTableModel::ForgetAndRemoveAllSignons() { delete row; iter = saved_signons_.erase(iter); } - instance_->SetRemoveAllEnabled(false); if (observer_) observer_->OnModelChanged(); + if (row_count_observer_) + row_count_observer_->OnRowCountChanged(RowCount()); } ////////////////////////////////////////////////////////////////////// @@ -211,6 +214,9 @@ PasswordManagerView::PasswordManagerView(Profile* profile) } void PasswordManagerView::SetupTable() { + // Tell the table model we are concern about how many rows it has. + table_model_.set_row_count_observer(this); + // Creates the different columns for the table. // The float resize values are the result of much tinkering. std::vector<views::TableColumn> columns; @@ -358,10 +364,6 @@ std::wstring PasswordManagerView::GetWindowTitle() const { return l10n_util::GetString(IDS_PASSWORD_MANAGER_VIEW_TITLE); } -void PasswordManagerView::SetRemoveAllEnabled(bool enabled) { - instance_->remove_all_button_.SetEnabled(enabled); -} - void PasswordManagerView::ButtonPressed(views::NativeButton* sender) { DCHECK(window()); // Close will result in our destruction. @@ -406,3 +408,7 @@ void PasswordManagerView::WindowClosing() { views::View* PasswordManagerView::GetContentsView() { return this; } + +void PasswordManagerView::OnRowCountChanged(size_t rows) { + remove_all_button_.SetEnabled(rows > 0); +} diff --git a/chrome/browser/views/password_manager_view.h b/chrome/browser/views/password_manager_view.h index a5e5950..6454db0 100644 --- a/chrome/browser/views/password_manager_view.h +++ b/chrome/browser/views/password_manager_view.h @@ -20,6 +20,21 @@ class Profile; +// An observer interface to notify change of row count in a table model. This +// allow the container view of TableView(i.e. PasswordManagerView and +// PasswordManagerExceptionsView), to be notified of row count changes directly +// from the TableModel. We have two different observers in +// PasswordManagerTableModel, namely views::TableModelObserver and +// PasswordManagerTableModelObserver, rather than adding this event to +// views::TableModelObserver because only container view of +// PasswordManagerTableModel cares about this event. Because of the same reason +// the relationship between a PasswordManagerTableModel and +// PasswordManagerTableModelObserver is 1-to-1. +class PasswordManagerTableModelObserver { + public: + virtual void OnRowCountChanged(size_t rows) = 0; +}; + class PasswordManagerTableModel : public views::TableModel, public WebDataServiceConsumer { public: @@ -49,6 +64,11 @@ class PasswordManagerTableModel : public views::TableModel, // Return the PasswordForm at the specified index. PasswordForm* GetPasswordFormAt(int row); + // Set the observer who concerns about how many rows are in the table. + void set_row_count_observer(PasswordManagerTableModelObserver* observer) { + row_count_observer_ = observer; + } + protected: // Wraps the PasswordForm from the database and caches the display URL for // quick sorting. @@ -72,6 +92,10 @@ class PasswordManagerTableModel : public views::TableModel, // The TableView observing this model. views::TableModelObserver* observer_; + // Dispatching row count events specific to this password manager table model + // to this observer. + PasswordManagerTableModelObserver* row_count_observer_; + // Handle to any pending WebDataService::GetLogins query. WebDataService::Handle pending_login_query_; @@ -108,7 +132,8 @@ class MultiLabelButtons : public views::NativeButton { class PasswordManagerView : public views::View, public views::DialogDelegate, public views::TableViewObserver, - public views::NativeButton::Listener { + public views::NativeButton::Listener, + public PasswordManagerTableModelObserver { public: explicit PasswordManagerView(Profile* profile); virtual ~PasswordManagerView(); @@ -121,8 +146,6 @@ class PasswordManagerView : public views::View, virtual gfx::Size GetPreferredSize(); virtual void ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child); - virtual void SetRemoveAllEnabled(bool enabled); - // views::TableViewObserver implementation. virtual void OnSelectionChanged(); @@ -139,6 +162,9 @@ class PasswordManagerView : public views::View, virtual void WindowClosing(); virtual views::View* GetContentsView(); + // PasswordManagerTableModelObserver implementation. + virtual void OnRowCountChanged(size_t rows); + private: // Wire up buttons, the model, and the table view, and query the DB for // saved login data tied to the given profile. @@ -160,6 +186,8 @@ class PasswordManagerView : public views::View, views::NativeButton remove_all_button_; views::Label password_label_; + static PasswordManagerView* instance_; + DISALLOW_EVIL_CONSTRUCTORS(PasswordManagerView); }; #endif // CHROME_BROWSER_PASSWORD_MANAGER_VIEW_H__ |