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

Side by Side Diff: chrome/browser/notifications/notification_exceptions_table_model.cc

Issue 2868042: Backend changes for notifications content settings. (Closed)
Patch Set: '' Created 10 years, 5 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/notifications/notification_exceptions_table_model.h" 5 #include "chrome/browser/notifications/notification_exceptions_table_model.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/l10n_util_collator.h" 8 #include "app/l10n_util_collator.h"
9 #include "app/table_model_observer.h" 9 #include "app/table_model_observer.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
12 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
13 14
14 NotificationExceptionsTableModel::NotificationExceptionsTableModel( 15 NotificationExceptionsTableModel::NotificationExceptionsTableModel(
15 DesktopNotificationService* service) 16 DesktopNotificationService* service)
16 : service_(service), 17 : service_(service),
17 observer_(NULL) { 18 observer_(NULL) {
19 std::vector<GURL> allowed(service_->GetAllowedOrigins());
20 std::vector<GURL> blocked(service_->GetBlockedOrigins());
21 entries_.reserve(allowed.size() + blocked.size());
22 for (size_t i = 0; i < allowed.size(); ++i)
23 entries_.push_back(Entry(allowed[i], CONTENT_SETTING_ALLOW));
24 for (size_t i = 0; i < blocked.size(); ++i)
25 entries_.push_back(Entry(blocked[i], CONTENT_SETTING_BLOCK));
26 sort(entries_.begin(), entries_.end());
18 } 27 }
19 28
20 bool NotificationExceptionsTableModel::CanRemoveRows( 29 bool NotificationExceptionsTableModel::CanRemoveRows(
21 const Rows& rows) const { 30 const Rows& rows) const {
22 NOTIMPLEMENTED(); 31 return !rows.empty();
23 return false;
24 } 32 }
25 33
26 void NotificationExceptionsTableModel::RemoveRows(const Rows& rows) { 34 void NotificationExceptionsTableModel::RemoveRows(const Rows& rows) {
27 NOTIMPLEMENTED(); 35 // This is O(n^2) in rows.size(). Since n is small, that's ok.
36 for (Rows::const_reverse_iterator i(rows.rbegin()); i != rows.rend(); ++i) {
37 size_t row = *i;
38 Entry* entry = &entries_[row];
39 if (entry->setting == CONTENT_SETTING_ALLOW) {
40 service_->ResetAllowedOrigin(entry->origin);
41 } else {
42 DCHECK_EQ(entry->setting, CONTENT_SETTING_BLOCK);
43 service_->ResetBlockedOrigin(entry->origin);
44 }
45 entries_.erase(entries_.begin() + row); // Note: |entry| is now garbage.
46 if (observer_)
47 observer_->OnItemsRemoved(row, 1);
48 }
28 } 49 }
29 50
30 void NotificationExceptionsTableModel::RemoveAll() { 51 void NotificationExceptionsTableModel::RemoveAll() {
31 NOTIMPLEMENTED(); 52 int old_row_count = RowCount();
53 entries_.clear();
54 service_->ResetAllOrigins();
55 if (observer_)
56 observer_->OnItemsRemoved(0, old_row_count);
32 } 57 }
33 58
34 int NotificationExceptionsTableModel::RowCount() { 59 int NotificationExceptionsTableModel::RowCount() {
35 return static_cast<int>(entries_.size()); 60 return static_cast<int>(entries_.size());
36 } 61 }
37 62
38 std::wstring NotificationExceptionsTableModel::GetText(int row, 63 std::wstring NotificationExceptionsTableModel::GetText(int row,
39 int column_id) { 64 int column_id) {
40 NOTIMPLEMENTED(); 65 const Entry& entry = entries_[row];
66 if (column_id == IDS_EXCEPTIONS_HOSTNAME_HEADER) {
67 // TODO(bulach): factor out in a common function so that Notifications won't
68 // depend on Geolocation.
69 return UTF8ToWide(GeolocationContentSettingsMap::OriginToString(
70 entry.origin));
71 }
72
73 if (column_id == IDS_EXCEPTIONS_ACTION_HEADER) {
74 switch (entry.setting) {
75 case CONTENT_SETTING_ALLOW:
76 return l10n_util::GetString(IDS_EXCEPTIONS_ALLOW_BUTTON);
77 case CONTENT_SETTING_BLOCK:
78 return l10n_util::GetString(IDS_EXCEPTIONS_BLOCK_BUTTON);
79 default:
80 break;
81 }
82 }
83
84 NOTREACHED();
41 return std::wstring(); 85 return std::wstring();
42 } 86 }
43 87
44 void NotificationExceptionsTableModel::SetObserver( 88 void NotificationExceptionsTableModel::SetObserver(
45 TableModelObserver* observer) { 89 TableModelObserver* observer) {
46 observer_ = observer; 90 observer_ = observer;
47 } 91 }
48 92
49 NotificationExceptionsTableModel::Entry::Entry( 93 NotificationExceptionsTableModel::Entry::Entry(
50 const GURL& in_origin, 94 const GURL& in_origin,
51 ContentSetting in_setting) 95 ContentSetting in_setting)
52 : origin(in_origin), 96 : origin(in_origin),
53 setting(in_setting) { 97 setting(in_setting) {
54 } 98 }
55 99
100 bool NotificationExceptionsTableModel::Entry::operator<(
101 const NotificationExceptionsTableModel::Entry& b) const {
102 DCHECK_NE(origin, b.origin);
103 return origin < b.origin;
104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698