diff options
author | deepak.m1 <deepak.m1@samsung.com> | 2015-06-01 20:38:26 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-02 03:38:50 +0000 |
commit | 909d4debbc0f9b443109ab4eb2f68edd084ac015 (patch) | |
tree | c8f8f7d6929d5520735455a111d9268c783b1720 | |
parent | 176353a4bceff74ca34d6ebd0708b8894cda6d73 (diff) | |
download | chromium_src-909d4debbc0f9b443109ab4eb2f68edd084ac015.zip chromium_src-909d4debbc0f9b443109ab4eb2f68edd084ac015.tar.gz chromium_src-909d4debbc0f9b443109ab4eb2f68edd084ac015.tar.bz2 |
Passing ProfileID instead of Profile* to clarify that profile should not be used for making any calls.
ProfileID is just a void* cast of Profile* to stop making any call.
BUG=490581
Review URL: https://codereview.chromium.org/1155453002
Cr-Commit-Position: refs/heads/master@{#332340}
12 files changed, 44 insertions, 54 deletions
diff --git a/chrome/browser/download/notification/download_notification_item_unittest.cc b/chrome/browser/download/notification/download_notification_item_unittest.cc index 9939f14..4248ca8 100644 --- a/chrome/browser/download/notification/download_notification_item_unittest.cc +++ b/chrome/browser/download/notification/download_notification_item_unittest.cc @@ -126,7 +126,7 @@ class DownloadNotificationItemTest : public testing::Test { size_t NotificationCount() const { return ui_manager_ ->GetAllIdsByProfileAndSourceOrigin( - profile_, + NotificationUIManager::GetProfileID(profile_), GURL(DownloadNotificationItem::kDownloadNotificationOrigin)) .size(); } diff --git a/chrome/browser/extensions/api/notifications/notifications_api.cc b/chrome/browser/extensions/api/notifications/notifications_api.cc index 493ae93..2c80b1f 100644 --- a/chrome/browser/extensions/api/notifications/notifications_api.cc +++ b/chrome/browser/extensions/api/notifications/notifications_api.cc @@ -644,7 +644,7 @@ bool NotificationsGetAllFunction::RunNotificationsApi() { g_browser_process->notification_ui_manager(); std::set<std::string> notification_ids = notification_ui_manager->GetAllIdsByProfileAndSourceOrigin( - GetProfile(), extension_->url()); + NotificationUIManager::GetProfileID(GetProfile()), extension_->url()); scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); diff --git a/chrome/browser/notifications/message_center_notification_manager.cc b/chrome/browser/notifications/message_center_notification_manager.cc index e4c54e7..273dcf2 100644 --- a/chrome/browser/notifications/message_center_notification_manager.cc +++ b/chrome/browser/notifications/message_center_notification_manager.cc @@ -139,7 +139,8 @@ void MessageCenterNotificationManager::Add(const Notification& notification, // route notifications to one of the apps/extensions. std::string extension_id = GetExtensionTakingOverNotifications(profile); if (!extension_id.empty()) - AddNotificationToAlternateProvider(profile_notification, extension_id); + AddNotificationToAlternateProvider(profile_notification->notification(), + profile, extension_id); message_center_->AddNotification(make_scoped_ptr( new message_center::Notification(profile_notification->notification()))); @@ -162,7 +163,8 @@ bool MessageCenterNotificationManager::Update(const Notification& notification, ProfileNotification* old_notification = (*iter).second; if (old_notification->notification().tag() == tag && old_notification->notification().origin_url() == origin_url && - old_notification->profile() == profile) { + old_notification->profile_id() == + NotificationUIManager::GetProfileID(profile)) { // Changing the type from non-progress to progress does not count towards // the immediate update allowed in the message center. std::string old_id = old_notification->notification().id(); @@ -231,15 +233,12 @@ bool MessageCenterNotificationManager::CancelById( std::set<std::string> MessageCenterNotificationManager::GetAllIdsByProfileAndSourceOrigin( - Profile* profile, + ProfileID profile_id, const GURL& source) { - // The profile pointer can be weak, the instance may have been destroyed, so - // no profile method should be called inside this function. - std::set<std::string> delegate_ids; for (const auto& pair : profile_notifications_) { const Notification& notification = pair.second->notification(); - if (pair.second->profile() == profile && + if (pair.second->profile_id() == profile_id && notification.origin_url() == source) { delegate_ids.insert(notification.delegate_id()); } @@ -249,13 +248,10 @@ MessageCenterNotificationManager::GetAllIdsByProfileAndSourceOrigin( } std::set<std::string> MessageCenterNotificationManager::GetAllIdsByProfile( - Profile* profile) { - // The profile pointer can be weak, the instance may have been destroyed, so - // no profile method should be called inside this function. - + ProfileID profile_id) { std::set<std::string> delegate_ids; for (const auto& pair : profile_notifications_) { - if (pair.second->profile() == profile) + if (pair.second->profile_id() == profile_id) delegate_ids.insert(pair.second->notification().delegate_id()); } @@ -289,8 +285,7 @@ bool MessageCenterNotificationManager::CancelAllByProfile( for (NotificationMap::iterator loopiter = profile_notifications_.begin(); loopiter != profile_notifications_.end(); ) { NotificationMap::iterator curiter = loopiter++; - if (profile_id == NotificationUIManager::GetProfileID( - (*curiter).second->profile())) { + if (profile_id == (*curiter).second->profile_id()) { const std::string id = curiter->first; RemoveProfileNotification(curiter->second); message_center_->RemoveNotification(id, /* by_user */ false); @@ -364,18 +359,16 @@ MessageCenterNotificationManager::GetMessageCenterNotificationIdForTest( // private void MessageCenterNotificationManager::AddNotificationToAlternateProvider( - ProfileNotification* profile_notification, + const Notification& notification, + Profile* profile, const std::string& extension_id) const { - const Notification& notification = profile_notification->notification(); - // Convert data from Notification type to NotificationOptions type. extensions::api::notifications::NotificationOptions options; NotificationConversionHelper::NotificationToNotificationOptions(notification, &options); // Send the notification to the alternate provider extension/app. - extensions::NotificationProviderEventRouter event_router( - profile_notification->profile()); + extensions::NotificationProviderEventRouter event_router(profile); event_router.CreateNotification(extension_id, notification.notifier_id().id, notification.delegate_id(), diff --git a/chrome/browser/notifications/message_center_notification_manager.h b/chrome/browser/notifications/message_center_notification_manager.h index a5a2149..64fc7c8 100644 --- a/chrome/browser/notifications/message_center_notification_manager.h +++ b/chrome/browser/notifications/message_center_notification_manager.h @@ -59,9 +59,9 @@ class MessageCenterNotificationManager bool CancelById(const std::string& delegate_id, ProfileID profile_id) override; std::set<std::string> GetAllIdsByProfileAndSourceOrigin( - Profile* profile, + ProfileID profile_id, const GURL& source) override; - std::set<std::string> GetAllIdsByProfile(Profile* profile) override; + std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) override; bool CancelAllBySourceOrigin(const GURL& source_origin) override; bool CancelAllByProfile(ProfileID profile_id) override; void CancelAll() override; @@ -96,7 +96,8 @@ class MessageCenterNotificationManager private: // Adds |profile_notification| to an alternative provider extension or app. void AddNotificationToAlternateProvider( - ProfileNotification* profile_notification, + const Notification& notification, + Profile* profile, const std::string& extension_id) const; FRIEND_TEST_ALL_PREFIXES(message_center::WebNotificationTrayTest, diff --git a/chrome/browser/notifications/notification_test_util.cc b/chrome/browser/notifications/notification_test_util.cc index 1cfdf9d..e5a5670 100644 --- a/chrome/browser/notifications/notification_test_util.cc +++ b/chrome/browser/notifications/notification_test_util.cc @@ -34,7 +34,8 @@ void StubNotificationUIManager::SetNotificationAddedCallback( void StubNotificationUIManager::Add(const Notification& notification, Profile* profile) { - notifications_.push_back(std::make_pair(notification, profile)); + notifications_.push_back(std::make_pair( + notification, NotificationUIManager::GetProfileID(profile))); if (!notification_added_callback_.is_null()) { notification_added_callback_.Run(); @@ -82,21 +83,21 @@ bool StubNotificationUIManager::CancelById(const std::string& delegate_id, std::set<std::string> StubNotificationUIManager::GetAllIdsByProfileAndSourceOrigin( - Profile* profile, + ProfileID profile_id, const GURL& source) { std::set<std::string> delegate_ids; for (const auto& pair : notifications_) { - if (pair.second == profile && pair.first.origin_url() == source) + if (pair.second == profile_id && pair.first.origin_url() == source) delegate_ids.insert(pair.first.delegate_id()); } return delegate_ids; } std::set<std::string> StubNotificationUIManager::GetAllIdsByProfile( - Profile* profile) { + ProfileID profile_id) { std::set<std::string> delegate_ids; for (const auto& pair : notifications_) { - if (pair.second == profile) + if (pair.second == profile_id) delegate_ids.insert(pair.first.delegate_id()); } return delegate_ids; diff --git a/chrome/browser/notifications/notification_test_util.h b/chrome/browser/notifications/notification_test_util.h index 1ea0fc0..e2d34eb 100644 --- a/chrome/browser/notifications/notification_test_util.h +++ b/chrome/browser/notifications/notification_test_util.h @@ -56,9 +56,9 @@ class StubNotificationUIManager : public NotificationUIManager { bool CancelById(const std::string& delegate_id, ProfileID profile_id) override; std::set<std::string> GetAllIdsByProfileAndSourceOrigin( - Profile* profile, + ProfileID profile_id, const GURL& source) override; - std::set<std::string> GetAllIdsByProfile(Profile* profile) override; + std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) override; bool CancelAllBySourceOrigin(const GURL& source_origin) override; bool CancelAllByProfile(ProfileID profile_id) override; void CancelAll() override; diff --git a/chrome/browser/notifications/notification_ui_manager.h b/chrome/browser/notifications/notification_ui_manager.h index 49d0ed9..64c06a3 100644 --- a/chrome/browser/notifications/notification_ui_manager.h +++ b/chrome/browser/notifications/notification_ui_manager.h @@ -67,17 +67,13 @@ class NotificationUIManager { ProfileID profile_id) = 0; // Returns the set of all delegate IDs for notifications from the passed - // |profile| and |source|. - // TODO(peter): Change Profile* to ProfileID to clarify that the profile - // should not be used for making any calls, as it might be dead. + // |profile_id| and |source|. virtual std::set<std::string> GetAllIdsByProfileAndSourceOrigin( - Profile* profile, + ProfileID profile_id, const GURL& source) = 0; - // Returns the set of all delegate IDs for notifications from |profile|. - // TODO(peter): Change Profile* to ProfileID to clarify that the profile - // should not be used for making any calls, as it might be dead. - virtual std::set<std::string> GetAllIdsByProfile(Profile* profile) = 0; + // Returns the set of all delegate IDs for notifications from |profile_id|. + virtual std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) = 0; // Removes notifications matching the |source_origin| (which could be an // extension ID). Returns true if anything was removed. diff --git a/chrome/browser/notifications/notification_ui_manager_android.cc b/chrome/browser/notifications/notification_ui_manager_android.cc index cee5ffa..85455f1 100644 --- a/chrome/browser/notifications/notification_ui_manager_android.cc +++ b/chrome/browser/notifications/notification_ui_manager_android.cc @@ -199,14 +199,14 @@ bool NotificationUIManagerAndroid::CancelById(const std::string& delegate_id, std::set<std::string> NotificationUIManagerAndroid::GetAllIdsByProfileAndSourceOrigin( - Profile* profile, + ProfileID profile_id, const GURL& source) { NOTREACHED(); return std::set<std::string>(); } std::set<std::string> NotificationUIManagerAndroid::GetAllIdsByProfile( - Profile* profile) { + ProfileID profile_id) { NOTREACHED(); return std::set<std::string>(); } diff --git a/chrome/browser/notifications/notification_ui_manager_android.h b/chrome/browser/notifications/notification_ui_manager_android.h index 68fd226..9c43dce 100644 --- a/chrome/browser/notifications/notification_ui_manager_android.h +++ b/chrome/browser/notifications/notification_ui_manager_android.h @@ -51,10 +51,10 @@ class NotificationUIManagerAndroid : public NotificationUIManager { ProfileID profile_id) const override; bool CancelById(const std::string& delegate_id, ProfileID profile_id) override; - std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, - const GURL& source) - override; - std::set<std::string> GetAllIdsByProfile(Profile* profile) override; + std::set<std::string> GetAllIdsByProfileAndSourceOrigin( + ProfileID profile_id, + const GURL& source) override; + std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) override; bool CancelAllBySourceOrigin(const GURL& source_origin) override; bool CancelAllByProfile(ProfileID profile_id) override; void CancelAll() override; diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc index be6db4c..cafd270 100644 --- a/chrome/browser/notifications/platform_notification_service_impl.cc +++ b/chrome/browser/notifications/platform_notification_service_impl.cc @@ -320,8 +320,8 @@ bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( return false; // Tests will not have a message center. // TODO(peter): Filter for persistent notifications only. - *displayed_notifications = - GetNotificationUIManager()->GetAllIdsByProfile(profile); + *displayed_notifications = GetNotificationUIManager()->GetAllIdsByProfile( + NotificationUIManager::GetProfileID(profile)); return true; #else diff --git a/chrome/browser/notifications/profile_notification.cc b/chrome/browser/notifications/profile_notification.cc index 745820a..8c1b7ac 100644 --- a/chrome/browser/notifications/profile_notification.cc +++ b/chrome/browser/notifications/profile_notification.cc @@ -18,10 +18,9 @@ std::string ProfileNotification::GetProfileNotificationId( delegate_id.c_str()); } -ProfileNotification::ProfileNotification( - Profile* profile, - const Notification& notification) - : profile_(profile), +ProfileNotification::ProfileNotification(Profile* profile, + const Notification& notification) + : profile_id_(NotificationUIManager::GetProfileID(profile)), notification_( // Uses Notification's copy constructor to assign the message center // id, which should be unique for every profile + Notification pair. diff --git a/chrome/browser/notifications/profile_notification.h b/chrome/browser/notifications/profile_notification.h index 1395233..8350121 100644 --- a/chrome/browser/notifications/profile_notification.h +++ b/chrome/browser/notifications/profile_notification.h @@ -24,12 +24,12 @@ class ProfileNotification { ProfileNotification(Profile* profile, const Notification& notification); ~ProfileNotification(); - Profile* profile() const { return profile_; } + ProfileID profile_id() const { return profile_id_; } const Notification& notification() const { return notification_; } private: - // Weak, guaranteed not to be used after profile removal by parent class. - Profile* profile_; + // Used for equality comparision in notification maps. + ProfileID profile_id_; Notification notification_; }; |