| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 5 |
| 6 #include "chrome/browser/content_settings/content_settings_notification_provider
.h" | 6 #include "chrome/browser/content_settings/content_settings_notification_provider
.h" |
| 7 | 7 |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 9 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 ListPrefUpdate update_denied_sites( | 274 ListPrefUpdate update_denied_sites( |
| 275 prefs, prefs::kDesktopNotificationDeniedOrigins); | 275 prefs, prefs::kDesktopNotificationDeniedOrigins); |
| 276 ListValue* allowed_sites = update_allowed_sites.Get(); | 276 ListValue* allowed_sites = update_allowed_sites.Get(); |
| 277 ListValue* denied_sites = update_denied_sites.Get(); | 277 ListValue* denied_sites = update_denied_sites.Get(); |
| 278 // |value| is passed to the preferences list, or deleted. | 278 // |value| is passed to the preferences list, or deleted. |
| 279 StringValue* value = new StringValue(origin.spec()); | 279 StringValue* value = new StringValue(origin.spec()); |
| 280 | 280 |
| 281 // Remove from one list and add to the other. | 281 // Remove from one list and add to the other. |
| 282 if (is_allowed) { | 282 if (is_allowed) { |
| 283 // Remove from the denied list. | 283 // Remove from the denied list. |
| 284 if (denied_sites->Remove(*value) != -1) | 284 if (denied_sites->Remove(*value, NULL)) |
| 285 denied_changed = true; | 285 denied_changed = true; |
| 286 | 286 |
| 287 // Add to the allowed list. | 287 // Add to the allowed list. |
| 288 if (allowed_sites->AppendIfNotPresent(value)) | 288 if (allowed_sites->AppendIfNotPresent(value)) |
| 289 allowed_changed = true; | 289 allowed_changed = true; |
| 290 } else { | 290 } else { |
| 291 // Remove from the allowed list. | 291 // Remove from the allowed list. |
| 292 if (allowed_sites->Remove(*value) != -1) | 292 if (allowed_sites->Remove(*value, NULL)) |
| 293 allowed_changed = true; | 293 allowed_changed = true; |
| 294 | 294 |
| 295 // Add to the denied list. | 295 // Add to the denied list. |
| 296 if (denied_sites->AppendIfNotPresent(value)) | 296 if (denied_sites->AppendIfNotPresent(value)) |
| 297 denied_changed = true; | 297 denied_changed = true; |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 // Persist the pref if anthing changed, but only send updates for the | 301 // Persist the pref if anthing changed, but only send updates for the |
| 302 // list that changed. | 302 // list that changed. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 329 if (profile_->IsOffTheRecord()) | 329 if (profile_->IsOffTheRecord()) |
| 330 return; | 330 return; |
| 331 | 331 |
| 332 // Since this isn't called often, let the normal observer behavior update the | 332 // Since this isn't called often, let the normal observer behavior update the |
| 333 // cache in this case. | 333 // cache in this case. |
| 334 PrefService* prefs = profile_->GetPrefs(); | 334 PrefService* prefs = profile_->GetPrefs(); |
| 335 { | 335 { |
| 336 ListPrefUpdate update(prefs, prefs::kDesktopNotificationAllowedOrigins); | 336 ListPrefUpdate update(prefs, prefs::kDesktopNotificationAllowedOrigins); |
| 337 ListValue* allowed_sites = update.Get(); | 337 ListValue* allowed_sites = update.Get(); |
| 338 StringValue value(origin.spec()); | 338 StringValue value(origin.spec()); |
| 339 int removed_index = allowed_sites->Remove(value); | 339 bool removed = allowed_sites->Remove(value, NULL); |
| 340 DCHECK_NE(-1, removed_index) << origin << " was not allowed"; | 340 DCHECK_NE(false, removed) << origin << " was not allowed"; |
| 341 } | 341 } |
| 342 prefs->ScheduleSavePersistentPrefs(); | 342 prefs->ScheduleSavePersistentPrefs(); |
| 343 } | 343 } |
| 344 | 344 |
| 345 void NotificationProvider::ResetBlockedOrigin(const GURL& origin) { | 345 void NotificationProvider::ResetBlockedOrigin(const GURL& origin) { |
| 346 if (profile_->IsOffTheRecord()) | 346 if (profile_->IsOffTheRecord()) |
| 347 return; | 347 return; |
| 348 | 348 |
| 349 // Since this isn't called often, let the normal observer behavior update the | 349 // Since this isn't called often, let the normal observer behavior update the |
| 350 // cache in this case. | 350 // cache in this case. |
| 351 PrefService* prefs = profile_->GetPrefs(); | 351 PrefService* prefs = profile_->GetPrefs(); |
| 352 { | 352 { |
| 353 ListPrefUpdate update(prefs, prefs::kDesktopNotificationDeniedOrigins); | 353 ListPrefUpdate update(prefs, prefs::kDesktopNotificationDeniedOrigins); |
| 354 ListValue* denied_sites = update.Get(); | 354 ListValue* denied_sites = update.Get(); |
| 355 StringValue value(origin.spec()); | 355 StringValue value(origin.spec()); |
| 356 int removed_index = denied_sites->Remove(value); | 356 bool removed = denied_sites->Remove(value, NULL); |
| 357 DCHECK_NE(-1, removed_index) << origin << " was not blocked"; | 357 DCHECK_NE(false, removed) << origin << " was not blocked"; |
| 358 } | 358 } |
| 359 prefs->ScheduleSavePersistentPrefs(); | 359 prefs->ScheduleSavePersistentPrefs(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 void NotificationProvider::ResetAllOrigins() { | 362 void NotificationProvider::ResetAllOrigins() { |
| 363 PrefService* prefs = profile_->GetPrefs(); | 363 PrefService* prefs = profile_->GetPrefs(); |
| 364 prefs->ClearPref(prefs::kDesktopNotificationAllowedOrigins); | 364 prefs->ClearPref(prefs::kDesktopNotificationAllowedOrigins); |
| 365 prefs->ClearPref(prefs::kDesktopNotificationDeniedOrigins); | 365 prefs->ClearPref(prefs::kDesktopNotificationDeniedOrigins); |
| 366 } | 366 } |
| 367 | 367 |
| 368 } // namespace content_settings | 368 } // namespace content_settings |
| OLD | NEW |