diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-22 19:18:26 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-22 19:18:26 +0000 |
commit | 6dfff6333eb5442582369195386fedce84395a72 (patch) | |
tree | 8896983a78d3817f61988e861df00f0bfb799af2 /chrome/browser/notifications | |
parent | 13165805e647e8132beaeb87de5fe1e953b53a34 (diff) | |
download | chromium_src-6dfff6333eb5442582369195386fedce84395a72.zip chromium_src-6dfff6333eb5442582369195386fedce84395a72.tar.gz chromium_src-6dfff6333eb5442582369195386fedce84395a72.tar.bz2 |
notifications: Remove NotificationExceptionsTableModel as it's no longer used.
R=thakis@chromium.org
Review URL: http://codereview.chromium.org/7994009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/notifications')
3 files changed, 0 insertions, 332 deletions
diff --git a/chrome/browser/notifications/notification_exceptions_table_model.cc b/chrome/browser/notifications/notification_exceptions_table_model.cc deleted file mode 100644 index f147af5..0000000 --- a/chrome/browser/notifications/notification_exceptions_table_model.cc +++ /dev/null @@ -1,144 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/notification_exceptions_table_model.h" - -#include <algorithm> -#include <string> - -#include "base/auto_reset.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/content_settings/host_content_settings_map.h" -#include "chrome/common/chrome_notification_types.h" -#include "chrome/common/content_settings.h" -#include "chrome/common/content_settings_pattern.h" -#include "chrome/common/content_settings_types.h" -#include "chrome/common/url_constants.h" -#include "content/common/notification_service.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/models/table_model_observer.h" - -struct NotificationExceptionsTableModel::Entry { - Entry(const ContentSettingsPattern& origin, ContentSetting setting); - bool operator<(const Entry& b) const; - - ContentSettingsPattern origin; - ContentSetting setting; -}; - -NotificationExceptionsTableModel::NotificationExceptionsTableModel( - DesktopNotificationService* service) - : service_(service), - updates_disabled_(false), - observer_(NULL) { - registrar_.Add(this, - chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, - Source<DesktopNotificationService>(service)); - LoadEntries(); -} - -NotificationExceptionsTableModel::~NotificationExceptionsTableModel() {} - -bool NotificationExceptionsTableModel::CanRemoveRows( - const Rows& rows) const { - return !rows.empty(); -} - -void NotificationExceptionsTableModel::RemoveRows(const Rows& rows) { - AutoReset<bool> tmp(&updates_disabled_, true); - // This is O(n^2) in rows.size(). Since n is small, that's ok. - for (Rows::const_reverse_iterator i(rows.rbegin()); i != rows.rend(); ++i) { - size_t row = *i; - Entry* entry = &entries_[row]; - DCHECK(entry->setting == CONTENT_SETTING_ALLOW || - entry->setting == CONTENT_SETTING_BLOCK); - service_->ClearSetting(entry->origin); - entries_.erase(entries_.begin() + row); // Note: |entry| is now garbage. - if (observer_) - observer_->OnItemsRemoved(row, 1); - } -} - -void NotificationExceptionsTableModel::RemoveAll() { - AutoReset<bool> tmp(&updates_disabled_, true); - entries_.clear(); - service_->ResetAllOrigins(); - if (observer_) - observer_->OnModelChanged(); -} - -int NotificationExceptionsTableModel::RowCount() { - return static_cast<int>(entries_.size()); -} - -string16 NotificationExceptionsTableModel::GetText(int row, - int column_id) { - const Entry& entry = entries_[row]; - if (column_id == IDS_EXCEPTIONS_HOSTNAME_HEADER) { - return UTF8ToUTF16(entry.origin.ToString()); - } - - if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) { - switch (entry.setting) { - case CONTENT_SETTING_ALLOW: - return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON); - case CONTENT_SETTING_BLOCK: - return l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON); - default: - break; - } - } - - NOTREACHED(); - return string16(); -} - -void NotificationExceptionsTableModel::SetObserver( - ui::TableModelObserver* observer) { - observer_ = observer; -} - -void NotificationExceptionsTableModel::Observe( - int type, - const NotificationSource& source, - const NotificationDetails& details) { - if (!updates_disabled_) { - DCHECK_EQ(type, chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED); - DCHECK_EQ(Source<DesktopNotificationService>(source).ptr(), service_); - entries_.clear(); - LoadEntries(); - - if (observer_) - observer_->OnModelChanged(); - } -} - -void NotificationExceptionsTableModel::LoadEntries() { - HostContentSettingsMap::SettingsForOneType settings; - service_->GetNotificationsSettings(&settings); - - entries_.reserve(settings.size()); - for (HostContentSettingsMap::SettingsForOneType::const_iterator i = - settings.begin(); - i != settings.end(); - ++i) { - const HostContentSettingsMap::PatternSettingSourceTuple& tuple(*i); - entries_.push_back(Entry(tuple.a, tuple.c)); - } - std::sort(entries_.begin(), entries_.end()); -} - -NotificationExceptionsTableModel::Entry::Entry( - const ContentSettingsPattern& in_origin, - ContentSetting in_setting) - : origin(in_origin), - setting(in_setting) { -} - -bool NotificationExceptionsTableModel::Entry::operator<( - const NotificationExceptionsTableModel::Entry& b) const { - DCHECK_NE(origin, b.origin); - return origin.ToString() < b.origin.ToString(); -} diff --git a/chrome/browser/notifications/notification_exceptions_table_model.h b/chrome/browser/notifications/notification_exceptions_table_model.h deleted file mode 100644 index bd6ad8e..0000000 --- a/chrome/browser/notifications/notification_exceptions_table_model.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_EXCEPTIONS_TABLE_MODEL_H_ -#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_EXCEPTIONS_TABLE_MODEL_H_ -#pragma once - -#include <vector> - -#include "base/compiler_specific.h" -#include "chrome/browser/notifications/desktop_notification_service.h" -#include "chrome/browser/remove_rows_table_model.h" -#include "content/common/notification_observer.h" - -class NotificationExceptionsTableModel : public RemoveRowsTableModel, - public NotificationObserver { - public: - explicit NotificationExceptionsTableModel( - DesktopNotificationService* service); - virtual ~NotificationExceptionsTableModel(); - - // Overridden from RemoveRowsTableModel: - virtual bool CanRemoveRows(const Rows& rows) const; - virtual void RemoveRows(const Rows& rows); - virtual void RemoveAll(); - - // Overridden from TableModel: - virtual int RowCount() OVERRIDE; - virtual string16 GetText(int row, int column_id) OVERRIDE; - virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE; - - // Overridden from NotificationObserver: - virtual void Observe(int type, - const NotificationSource& source, - const NotificationDetails& details); - private: - struct Entry; - - void LoadEntries(); - - DesktopNotificationService* service_; - - typedef std::vector<Entry> EntriesVector; - EntriesVector entries_; - - // We use this variable to prevent ourselves from handling further changes - // that we ourselves caused. - bool updates_disabled_; - NotificationRegistrar registrar_; - ui::TableModelObserver* observer_; - - DISALLOW_COPY_AND_ASSIGN(NotificationExceptionsTableModel); -}; - -#endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_EXCEPTIONS_TABLE_MODEL_H_ diff --git a/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc b/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc deleted file mode 100644 index 86dda43..0000000 --- a/chrome/browser/notifications/notification_exceptions_table_model_unittest.cc +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/notifications/notification_exceptions_table_model.h" - -#include "base/utf_string_conversions.h" -#include "chrome/browser/notifications/desktop_notification_service_factory.h" -#include "chrome/test/base/chrome_render_view_host_test_harness.h" -#include "chrome/test/base/testing_profile.h" -#include "content/browser/browser_thread.h" -#include "grit/generated_resources.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/l10n/l10n_util.h" - -class NotificationExceptionsTableModelTest - : public ChromeRenderViewHostTestHarness { - public: - NotificationExceptionsTableModelTest() - : ui_thread_(BrowserThread::UI, MessageLoop::current()) { - } - - virtual ~NotificationExceptionsTableModelTest() { - } - - virtual void SetUp() { - ChromeRenderViewHostTestHarness::SetUp(); - service_ = DesktopNotificationServiceFactory::GetForProfile(profile()); - ResetModel(); - } - - virtual void TearDown() { - model_.reset(NULL); - ChromeRenderViewHostTestHarness::TearDown(); - } - - virtual void ResetModel() { - model_.reset(new NotificationExceptionsTableModel(service_)); - } - - virtual void FillData() { - service_->GrantPermission(GURL("http://e-allowed2.com")); - service_->GrantPermission(GURL("http://allowed.com")); - - service_->DenyPermission(GURL("http://denied2.com")); - service_->DenyPermission(GURL("http://denied.com")); - service_->DenyPermission(GURL("http://f-denied3.com")); - - ResetModel(); - } - - protected: - BrowserThread ui_thread_; - scoped_ptr<NotificationExceptionsTableModel> model_; - DesktopNotificationService* service_; -}; - -TEST_F(NotificationExceptionsTableModelTest, CanCreate) { - EXPECT_EQ(0, model_->RowCount()); -} - -TEST_F(NotificationExceptionsTableModelTest, RemoveAll) { - FillData(); - HostContentSettingsMap::SettingsForOneType settings; - service_->GetNotificationsSettings(&settings); - EXPECT_EQ(5u, settings.size()); - EXPECT_EQ(5, model_->RowCount()); - - model_->RemoveAll(); - EXPECT_EQ(0, model_->RowCount()); - - service_->GetNotificationsSettings(&settings); - EXPECT_EQ(0u, settings.size()); -} - -TEST_F(NotificationExceptionsTableModelTest, AlphabeticalOrder) { - FillData(); - EXPECT_EQ(5, model_->RowCount()); - - EXPECT_EQ(ASCIIToUTF16("http://allowed.com:80"), - model_->GetText(0, IDS_EXCEPTIONS_HOSTNAME_HEADER)); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), - model_->GetText(0, IDS_EXCEPTIONS_ACTION_HEADER)); - - EXPECT_EQ(ASCIIToUTF16("http://denied.com:80"), - model_->GetText(1, IDS_EXCEPTIONS_HOSTNAME_HEADER)); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), - model_->GetText(1, IDS_EXCEPTIONS_ACTION_HEADER)); - - EXPECT_EQ(ASCIIToUTF16("http://denied2.com:80"), - model_->GetText(2, IDS_EXCEPTIONS_HOSTNAME_HEADER)); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), - model_->GetText(2, IDS_EXCEPTIONS_ACTION_HEADER)); - - EXPECT_EQ(ASCIIToUTF16("http://e-allowed2.com:80"), - model_->GetText(3, IDS_EXCEPTIONS_HOSTNAME_HEADER)); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_ALLOW_BUTTON), - model_->GetText(3, IDS_EXCEPTIONS_ACTION_HEADER)); - - EXPECT_EQ(ASCIIToUTF16("http://f-denied3.com:80"), - model_->GetText(4, IDS_EXCEPTIONS_HOSTNAME_HEADER)); - EXPECT_EQ(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_BLOCK_BUTTON), - model_->GetText(4, IDS_EXCEPTIONS_ACTION_HEADER)); -} - -TEST_F(NotificationExceptionsTableModelTest, RemoveRows) { - FillData(); - EXPECT_EQ(5, model_->RowCount()); - - { - RemoveRowsTableModel::Rows rows; - rows.insert(0); // allowed.com - rows.insert(3); // e-allowed2.com - model_->RemoveRows(rows); - } - EXPECT_EQ(3, model_->RowCount()); - - HostContentSettingsMap::SettingsForOneType settings; - service_->GetNotificationsSettings(&settings); - EXPECT_EQ(3u, settings.size()); - - { - RemoveRowsTableModel::Rows rows; - rows.insert(0); - rows.insert(1); - rows.insert(2); - model_->RemoveRows(rows); - } - EXPECT_EQ(0, model_->RowCount()); - service_->GetNotificationsSettings(&settings); - EXPECT_EQ(0u, settings.size()); -} |