Commit d1948c32 authored by dbeam@chromium.org's avatar dbeam@chromium.org

Revert 201932 "Add API function chrome.notifications.getAll"

Broke Mac ASAN Tests (1):
http://build.chromium.org/p/chromium.memory/builders/Mac%20ASAN%20Tests%20%281%29/builds/10683

NotificationsApiTest.TestGetAll: 
dyld: warning, unknown environment variable: DYLD_NO_PIE
dyld: warning, unknown environment variable: DYLD_NO_PIE
dyld: warning, unknown environment variable: DYLD_NO_PIE
dyld: warning, unknown environment variable: DYLD_NO_PIE
[6552:3847:0523/180035:INFO:gpu_command_buffer_stub.cc(468)] Created virtual GL
context.
../../chrome/browser/extensions/api/notifications/notifications_apitest.cc:331:
Failure
Value of: kNotificationsToCreate
Actual: 4
Expected: return_value->size()
Which is: 0

> Add API function chrome.notifications.getAll
> 
> This function returns an object whose keys are the notification
> IDs of all notifications created by that extension.
> 
> BUG=240924
> 
> Review URL: https://chromiumcodereview.appspot.com/14767029

TBR=dewittj@chromium.org

Review URL: https://codereview.chromium.org/15925003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201969 0039d316-1c4b-4281-b951-d872f2087c98
parent aff98124
......@@ -29,23 +29,6 @@ namespace {
const char kResultKey[] = "result";
// Given an extension id and another id, returns an id that is unique
// relative to other extensions.
std::string CreateScopedIdentifier(const std::string& extension_id,
const std::string& id) {
return extension_id + "-" + id;
}
// Removes the unique internal identifier to send the ID as the
// extension expects it.
std::string StripScopeFromIdentifier(const std::string& extension_id,
const std::string& id) {
size_t index_of_separator = extension_id.length() + 1;
DCHECK_LT(index_of_separator, id.length());
return id.substr(index_of_separator);
}
class NotificationsApiDelegate : public NotificationDelegate {
public:
NotificationsApiDelegate(ApiFunction* api_function,
......@@ -63,6 +46,13 @@ class NotificationsApiDelegate : public NotificationDelegate {
process_id_ = api_function->render_view_host()->GetProcess()->GetID();
}
// Given an extension id and another id, returns an id that is unique
// relative to other extensions.
static std::string CreateScopedIdentifier(const std::string& extension_id,
const std::string& id) {
return extension_id + "-" + id;
}
virtual void Display() OVERRIDE { }
virtual void Error() OVERRIDE {
......@@ -145,7 +135,10 @@ bool NotificationsApiFunction::IsNotificationsApiAvailable() {
// We need to check this explicitly rather than letting
// _permission_features.json enforce it, because we're sharing the
// chrome.notifications permissions namespace with WebKit notifications.
return GetExtension()->is_platform_app() || GetExtension()->is_extension();
if (!(GetExtension()->is_platform_app() || GetExtension()->is_extension()))
return false;
return true;
}
NotificationsApiFunction::NotificationsApiFunction() {
......@@ -340,8 +333,9 @@ bool NotificationsUpdateFunction::RunNotificationsApi() {
params_ = api::notifications::Update::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
if (g_browser_process->notification_ui_manager()->DoesIdExist(
CreateScopedIdentifier(extension_->id(), params_->notification_id))) {
if (g_browser_process->notification_ui_manager()->
DoesIdExist(NotificationsApiDelegate::CreateScopedIdentifier(
extension_->id(), params_->notification_id))) {
CreateNotification(params_->notification_id, &params_->options);
SetResult(Value::CreateBooleanValue(true));
} else {
......@@ -363,8 +357,9 @@ bool NotificationsClearFunction::RunNotificationsApi() {
params_ = api::notifications::Clear::Params::Create(*args_);
EXTENSION_FUNCTION_VALIDATE(params_.get());
bool cancel_result = g_browser_process->notification_ui_manager()->CancelById(
CreateScopedIdentifier(extension_->id(), params_->notification_id));
bool cancel_result = g_browser_process->notification_ui_manager()->
CancelById(NotificationsApiDelegate::CreateScopedIdentifier(
extension_->id(), params_->notification_id));
SetResult(Value::CreateBooleanValue(cancel_result));
SendResponse(true);
......@@ -372,29 +367,4 @@ bool NotificationsClearFunction::RunNotificationsApi() {
return true;
}
NotificationsGetAllFunction::NotificationsGetAllFunction() {}
NotificationsGetAllFunction::~NotificationsGetAllFunction() {}
bool NotificationsGetAllFunction::RunNotificationsApi() {
NotificationUIManager* notification_ui_manager =
g_browser_process->notification_ui_manager();
std::set<std::string> notification_ids =
notification_ui_manager->GetAllIdsByProfileAndSourceOrigin(
profile_, extension_->url());
scoped_ptr<DictionaryValue> result(new DictionaryValue());
for (std::set<std::string>::iterator iter = notification_ids.begin();
iter != notification_ids.end(); iter++) {
result->SetBooleanWithoutPathExpansion(
StripScopeFromIdentifier(extension_->id(), *iter), true);
}
SetResult(result.release());
SendResponse(true);
return true;
}
} // namespace extensions
......@@ -89,20 +89,6 @@ class NotificationsClearFunction : public NotificationsApiFunction {
DECLARE_EXTENSION_FUNCTION("notifications.clear", NOTIFICATIONS_CLEAR)
};
class NotificationsGetAllFunction : public NotificationsApiFunction {
public:
NotificationsGetAllFunction();
// UIThreadExtensionFunction:
virtual bool RunNotificationsApi() OVERRIDE;
protected:
virtual ~NotificationsGetAllFunction();
private:
DECLARE_EXTENSION_FUNCTION("notifications.getAll", NOTIFICATIONS_GET_ALL)
};
} // namespace extensions
#endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/stringprintf.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/notifications/notifications_api.h"
#include "chrome/browser/extensions/extension_apitest.h"
......@@ -13,7 +12,6 @@
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_switches.h"
#include "ui/message_center/message_center_util.h"
// TODO(kbr): remove: http://crbug.com/222296
......@@ -262,82 +260,6 @@ IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) {
ASSERT_TRUE(notification_id.length() > 0);
}
#if defined(OS_LINUX) && defined(USE_AURA)
#define MAYBE_TestGetAll DISABLED_TestGetAll
#else
#define MAYBE_TestGetAll TestGetAll
#endif
IN_PROC_BROWSER_TEST_F(NotificationsApiTest, MAYBE_TestGetAll) {
scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
{
scoped_refptr<extensions::NotificationsGetAllFunction>
notification_get_all_function(
new extensions::NotificationsGetAllFunction());
notification_get_all_function->set_extension(empty_extension.get());
notification_get_all_function->set_has_callback(true);
scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
notification_get_all_function, "[]", browser(), utils::NONE));
base::DictionaryValue* return_value;
ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
ASSERT_TRUE(result->GetAsDictionary(&return_value));
ASSERT_TRUE(return_value->size() == 0);
}
const unsigned int kNotificationsToCreate = 4;
for (unsigned int i = 0; i < kNotificationsToCreate; i++) {
scoped_refptr<extensions::NotificationsCreateFunction>
notification_create_function(
new extensions::NotificationsCreateFunction());
notification_create_function->set_extension(empty_extension.get());
notification_create_function->set_has_callback(true);
scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
notification_create_function,
base::StringPrintf("[\"identifier-%u\", "
"{"
"\"type\": \"list\","
"\"iconUrl\": \"an/image/that/does/not/exist.png\","
"\"title\": \"Title\","
"\"message\": \"Message.\","
"\"items\": ["
" {\"title\": \"Grace Goe\","
" \"message\": \"I saw Frank steal a sandwich :-)\"}"
"],"
"\"priority\": 1,"
"\"eventTime\": 1361488019.9999999"
"}]",
i),
browser(),
utils::NONE));
}
{
scoped_refptr<extensions::NotificationsGetAllFunction>
notification_get_all_function(
new extensions::NotificationsGetAllFunction());
notification_get_all_function->set_extension(empty_extension.get());
notification_get_all_function->set_has_callback(true);
scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
notification_get_all_function, "[]", browser(), utils::NONE));
base::DictionaryValue* return_value;
ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
ASSERT_TRUE(result->GetAsDictionary(&return_value));
ASSERT_EQ(return_value->size(), kNotificationsToCreate);
bool dictionary_bool = false;
for (unsigned int i = 0; i < kNotificationsToCreate; i++) {
std::string id = base::StringPrintf("identifier-%u", i);
ASSERT_TRUE(return_value->GetBoolean(id, &dictionary_bool));
ASSERT_TRUE(dictionary_bool);
}
}
}
IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) {
#if defined(OS_MACOSX)
// TODO(kbr): re-enable: http://crbug.com/222296
......
......@@ -530,7 +530,6 @@ enum HistogramValue {
WEBVIEW_INSERTCSS,
METRICSPRIVATE_GETISCRASHRECORDINGENABLED,
IDENTITYPRIVATE_GETRESOURCES,
NOTIFICATIONS_GET_ALL,
ENUM_BOUNDARY // Last entry: Add new entries above.
};
......
......@@ -13,7 +13,6 @@
#include "chrome/browser/idle.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "content/public/browser/notification_service.h"
......@@ -60,26 +59,6 @@ bool BalloonNotificationUIManager::CancelById(const std::string& id) {
return balloon_collection_->RemoveById(id);
}
std::set<std::string>
BalloonNotificationUIManager::GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) {
std::set<std::string> notification_ids =
NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin(profile,
source);
const BalloonCollection::Balloons& balloons =
balloon_collection_->GetActiveBalloons();
for (BalloonCollection::Balloons::const_iterator iter = balloons.begin();
iter != balloons.end(); ++iter) {
if (profile->IsSameProfile((*iter)->profile()) &&
source == (*iter)->notification().origin_url()) {
notification_ids.insert((*iter)->notification().notification_id());
}
}
return notification_ids;
}
bool BalloonNotificationUIManager::CancelAllBySourceOrigin(const GURL& source) {
// Same pattern as CancelById, but more complicated than the above
// because there may be multiple notifications from the same source.
......
......@@ -36,9 +36,6 @@ class BalloonNotificationUIManager
// NotificationUIManager:
virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE;
virtual bool CancelById(const std::string& notification_id) OVERRIDE;
virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) OVERRIDE;
virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE;
virtual bool CancelAllByProfile(Profile* profile) OVERRIDE;
virtual void CancelAll() OVERRIDE;
......
......@@ -70,25 +70,6 @@ bool MessageCenterNotificationManager::CancelById(const std::string& id) {
return true;
}
std::set<std::string>
MessageCenterNotificationManager::GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) {
std::set<std::string> notification_ids =
NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin(profile,
source);
for (NotificationMap::iterator iter = profile_notifications_.begin();
iter != profile_notifications_.end(); iter++) {
if ((*iter).second->notification().origin_url() == source &&
profile->IsSameProfile((*iter).second->profile())) {
notification_ids.insert(iter->first);
}
}
return notification_ids;
}
bool MessageCenterNotificationManager::CancelAllBySourceOrigin(
const GURL& source) {
// Same pattern as CancelById, but more complicated than the above
......@@ -113,7 +94,7 @@ bool MessageCenterNotificationManager::CancelAllByProfile(Profile* profile) {
for (NotificationMap::iterator loopiter = profile_notifications_.begin();
loopiter != profile_notifications_.end(); ) {
NotificationMap::iterator curiter = loopiter++;
if (profile->IsSameProfile((*curiter).second->profile())) {
if ((*curiter).second->profile() == profile) {
message_center_->RemoveNotification(curiter->first, /* by_user */ false);
removed = true;
}
......
......@@ -34,9 +34,6 @@ class MessageCenterNotificationManager
// NotificationUIManager
virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE;
virtual bool CancelById(const std::string& notification_id) OVERRIDE;
virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) OVERRIDE;
virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE;
virtual bool CancelAllByProfile(Profile* profile) OVERRIDE;
virtual void CancelAll() OVERRIDE;
......
......@@ -7,7 +7,6 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/notifications/balloon_notification_ui_manager.h"
#include "chrome/browser/notifications/message_center_notification_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "ui/message_center/message_center_util.h"
// static
......
......@@ -5,7 +5,6 @@
#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_H_
#include <set>
#include <string>
#include <vector>
......@@ -37,12 +36,6 @@ class NotificationUIManager {
// displayed or in the queue. Returns true if anything was removed.
virtual bool CancelById(const std::string& notification_id) = 0;
// Adds the notification_id for each outstanding notification to the set
// |notification_ids| (must not be NULL).
virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) = 0;
// Removes notifications matching the |source_origin| (which could be an
// extension ID). Returns true if anything was removed.
virtual bool CancelAllBySourceOrigin(const GURL& source_origin) = 0;
......
......@@ -95,21 +95,6 @@ bool NotificationUIManagerImpl::CancelById(const std::string& id) {
return false;
}
std::set<std::string>
NotificationUIManagerImpl::GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) {
std::set<std::string> notification_ids;
for (NotificationDeque::iterator iter = show_queue_.begin();
iter != show_queue_.end(); iter++) {
if ((*iter)->notification().origin_url() == source &&
profile->IsSameProfile((*iter)->profile())) {
notification_ids.insert((*iter)->notification().notification_id());
}
}
return notification_ids;
}
bool NotificationUIManagerImpl::CancelAllBySourceOrigin(const GURL& source) {
// Same pattern as CancelById, but more complicated than the above
// because there may be multiple notifications from the same source.
......
......@@ -36,9 +36,6 @@ class NotificationUIManagerImpl
Profile* profile) OVERRIDE;
virtual bool DoesIdExist(const std::string& notification_id) OVERRIDE;
virtual bool CancelById(const std::string& notification_id) OVERRIDE;
virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) OVERRIDE;
virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE;
virtual bool CancelAllByProfile(Profile* profile) OVERRIDE;
virtual void CancelAll() OVERRIDE;
......
......@@ -11,7 +11,6 @@
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification.h"
#include "chrome/browser/profiles/profile.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_change_processor.h"
#include "sync/api/sync_error_factory.h"
......@@ -123,7 +122,6 @@ class StubNotificationUIManager : public NotificationUIManager {
OVERRIDE {
// Make a deep copy of the notification that we can inspect.
notification_ = notification;
profile_ = profile;
}
// Returns true if any notifications match the supplied ID, either currently
......@@ -138,18 +136,6 @@ class StubNotificationUIManager : public NotificationUIManager {
return false;
}
// Adds the notification_id for each outstanding notification to the set
// |notification_ids| (must not be NULL).
virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) OVERRIDE {
std::set<std::string> notification_ids;
if (source == notification_.origin_url() &&
profile->IsSameProfile(profile_))
notification_ids.insert(notification_.notification_id());
return notification_ids;
}
// Removes notifications matching the |source_origin| (which could be an
// extension ID). Returns true if anything was removed.
virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE {
......@@ -171,7 +157,6 @@ class StubNotificationUIManager : public NotificationUIManager {
private:
DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager);
Notification notification_;
Profile* profile_;
};
// Dummy SyncChangeProcessor used to help review what SyncChanges are pushed
......
......@@ -9,7 +9,6 @@
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/notifications/sync_notifier/synced_notification.h"
#include "chrome/browser/profiles/profile.h"
#include "sync/api/sync_data.h"
#include "sync/protocol/sync.pb.h"
#include "sync/protocol/synced_notification_specifics.pb.h"
......@@ -88,7 +87,6 @@ class StubNotificationUIManager : public NotificationUIManager {
OVERRIDE {
// Make a deep copy of the notification that we can inspect.
notification_ = notification;
profile_ = profile;
}
// Returns true if any notifications match the supplied ID, either currently
......@@ -103,16 +101,6 @@ class StubNotificationUIManager : public NotificationUIManager {
return false;
}
virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin(
Profile* profile,
const GURL& source) OVERRIDE {
std::set<std::string> notification_ids;
if (source == notification_.origin_url() &&
profile->IsSameProfile(profile_))
notification_ids.insert(notification_.notification_id());
return notification_ids;
}
// Removes notifications matching the |source_origin| (which could be an
// extension ID). Returns true if anything was removed.
virtual bool CancelAllBySourceOrigin(const GURL& source_origin) OVERRIDE {
......@@ -134,7 +122,6 @@ class StubNotificationUIManager : public NotificationUIManager {
private:
DISALLOW_COPY_AND_ASSIGN(StubNotificationUIManager);
Notification notification_;
Profile* profile_;
};
class SyncedNotificationTest : public testing::Test {
......
......@@ -67,8 +67,6 @@ namespace notifications {
callback ClearCallback = void (boolean wasCleared);
callback GetAllCallback = void (object notifications);
interface Functions {
// Creates and displays a notification having the contents in |options|,
// identified by the id |notificationId|. If |notificationId| is empty,
......@@ -91,10 +89,6 @@ namespace notifications {
// corresponding notification. |callback| indicates whether a matching
// notification existed.
static void clear(DOMString notificationId, ClearCallback callback);
// |callback| is executed with the set of notification_ids currently in
// the system.
static void getAll(GetAllCallback callback);
};
interface Events {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment