diff options
| author | lwchkg <lwchkg@gmail.com> | 2016-02-10 08:14:55 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-02-10 16:16:04 +0000 |
| commit | 99addc8596703ef749ff20c9bf98dc29a80e37ea (patch) | |
| tree | 7ae480b6d818569150bd61a6af967067ea2c39bd | |
| parent | fe95d93a38c040091a6d8bcc55e2c66f29d4ce27 (diff) | |
| download | chromium_src-99addc8596703ef749ff20c9bf98dc29a80e37ea.zip chromium_src-99addc8596703ef749ff20c9bf98dc29a80e37ea.tar.gz chromium_src-99addc8596703ef749ff20c9bf98dc29a80e37ea.tar.bz2 | |
Refactor of ProfileInfoCache in c/b/notifications
ProfileInfoCache is being refactored into ProfileAttributesStorage and ProfileAttributesEntry, which use profile paths instead of numerical
indices in the interface. See https://codereview.chromium.org/1599013002
for details.
Member variable index is removed from message_center::NotifierGroup
and its subclasses because it is apparently unused except in tests.
BUG=305720
Review URL: https://codereview.chromium.org/1657913003
Cr-Commit-Position: refs/heads/master@{#374668}
11 files changed, 55 insertions, 61 deletions
diff --git a/chrome/browser/notifications/message_center_settings_controller.cc b/chrome/browser/notifications/message_center_settings_controller.cc index f67ee39..883ca01 100644 --- a/chrome/browser/notifications/message_center_settings_controller.cc +++ b/chrome/browser/notifications/message_center_settings_controller.cc @@ -5,6 +5,7 @@ #include "chrome/browser/notifications/message_center_settings_controller.h" #include <algorithm> +#include <string> #include <utility> #include "base/command_line.h" @@ -22,6 +23,8 @@ #include "chrome/browser/notifications/notifier_state_tracker.h" #include "chrome/browser/notifications/notifier_state_tracker_factory.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_attributes_entry.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/extensions/api/notifications.h" @@ -59,12 +62,10 @@ class ProfileNotifierGroup : public message_center::NotifierGroup { ProfileNotifierGroup(const gfx::Image& icon, const base::string16& display_name, const base::string16& login_info, - size_t index, const base::FilePath& profile_path); ProfileNotifierGroup(const gfx::Image& icon, const base::string16& display_name, const base::string16& login_info, - size_t index, Profile* profile); virtual ~ProfileNotifierGroup() {} @@ -77,9 +78,8 @@ class ProfileNotifierGroup : public message_center::NotifierGroup { ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, const base::string16& display_name, const base::string16& login_info, - size_t index, const base::FilePath& profile_path) - : message_center::NotifierGroup(icon, display_name, login_info, index), + : message_center::NotifierGroup(icon, display_name, login_info), profile_(NULL) { // Try to get the profile profile_ = @@ -89,9 +89,8 @@ ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, const base::string16& display_name, const base::string16& login_info, - size_t index, Profile* profile) - : message_center::NotifierGroup(icon, display_name, login_info, index), + : message_center::NotifierGroup(icon, display_name, login_info), profile_(profile) { } @@ -120,11 +119,10 @@ class NotifierComparator { } // namespace MessageCenterSettingsController::MessageCenterSettingsController( - ProfileInfoCache* profile_info_cache) + ProfileAttributesStorage& storage) : current_notifier_group_(0), - profile_info_cache_(profile_info_cache), + storage_(storage), weak_factory_(this) { - DCHECK(profile_info_cache_); // The following events all represent changes that may need to be reflected in // the profile selector context menu, so listen for them all. We'll just // rebuild the list when we get any of them. @@ -137,7 +135,7 @@ MessageCenterSettingsController::MessageCenterSettingsController( registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, content::NotificationService::AllBrowserContextsAndSources()); - g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); + storage_.AddObserver(this); RebuildNotifierGroups(false); #if defined(OS_CHROMEOS) @@ -148,8 +146,7 @@ MessageCenterSettingsController::MessageCenterSettingsController( } MessageCenterSettingsController::~MessageCenterSettingsController() { - g_browser_process->profile_manager()-> - GetProfileInfoCache().RemoveObserver(this); + storage_.RemoveObserver(this); #if defined(OS_CHROMEOS) // UserManager may not exist in some tests. if (user_manager::UserManager::IsInitialized()) @@ -492,7 +489,6 @@ void MessageCenterSettingsController::CreateNotifierGroupForGuestLogin() { new message_center::ProfileNotifierGroup(gfx::Image(user->GetImage()), user->GetDisplayName(), user->GetDisplayName(), - 0, profile)); notifier_groups_.push_back(std::move(group)); @@ -507,15 +503,15 @@ void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) { notifier_groups_.clear(); current_notifier_group_ = 0; - const size_t count = profile_info_cache_->GetNumberOfProfiles(); - for (size_t i = 0; i < count; ++i) { + std::vector<ProfileAttributesEntry*> entries = + storage_.GetAllProfilesAttributes(); + for (const auto entry : entries) { scoped_ptr<message_center::ProfileNotifierGroup> group( new message_center::ProfileNotifierGroup( - profile_info_cache_->GetAvatarIconOfProfileAtIndex(i), - profile_info_cache_->GetNameOfProfileAtIndex(i), - profile_info_cache_->GetUserNameOfProfileAtIndex(i), - i, - profile_info_cache_->GetPathOfProfileAtIndex(i))); + entry->GetAvatarIcon(), + entry->GetName(), + entry->GetUserName(), + entry->GetPath())); if (group->profile() == NULL) continue; diff --git a/chrome/browser/notifications/message_center_settings_controller.h b/chrome/browser/notifications/message_center_settings_controller.h index 0b5fc97..1c1403a 100644 --- a/chrome/browser/notifications/message_center_settings_controller.h +++ b/chrome/browser/notifications/message_center_settings_controller.h @@ -16,7 +16,7 @@ #include "base/observer_list.h" #include "build/build_config.h" #include "chrome/browser/extensions/app_icon_loader.h" -#include "chrome/browser/profiles/profile_info_cache_observer.h" +#include "chrome/browser/profiles/profile_attributes_storage.h" #include "components/content_settings/core/common/content_settings.h" #include "components/favicon_base/favicon_types.h" #include "content/public/browser/notification_details.h" @@ -30,7 +30,6 @@ #endif class Profile; -class ProfileInfoCache; namespace base { class CancelableTaskTracker; @@ -49,14 +48,13 @@ class ProfileNotifierGroup; class MessageCenterSettingsController : public message_center::NotifierSettingsProvider, public content::NotificationObserver, - public ProfileInfoCacheObserver, + public ProfileAttributesStorage::Observer, #if defined(OS_CHROMEOS) public user_manager::UserManager::UserSessionStateObserver, #endif public extensions::AppIconLoader::Delegate { public: - explicit MessageCenterSettingsController( - ProfileInfoCache* profile_info_cache); + explicit MessageCenterSettingsController(ProfileAttributesStorage& storage); ~MessageCenterSettingsController() override; // Overridden from message_center::NotifierSettingsProvider. @@ -94,7 +92,7 @@ class MessageCenterSettingsController const content::NotificationSource& source, const content::NotificationDetails& details) override; - // ProfileInfoCacheObserver: + // ProfileAttributesStorage::Observer: void OnProfileAdded(const base::FilePath& profile_path) override; void OnProfileWasRemoved(const base::FilePath& profile_path, const base::string16& profile_name) override; @@ -128,7 +126,8 @@ class MessageCenterSettingsController std::map<base::string16, ContentSettingsPattern> patterns_; // The list of all configurable notifier groups. This is each profile that is - // loaded (and in the ProfileInfoCache - so no incognito profiles go here). + // loaded (and in the ProfileAttributesStorage - so no incognito profiles go + // here). std::vector<scoped_ptr<message_center::ProfileNotifierGroup>> notifier_groups_; @@ -136,7 +135,7 @@ class MessageCenterSettingsController content::NotificationRegistrar registrar_; - ProfileInfoCache* profile_info_cache_; + ProfileAttributesStorage& storage_; base::WeakPtrFactory<MessageCenterSettingsController> weak_factory_; diff --git a/chrome/browser/notifications/message_center_settings_controller_unittest.cc b/chrome/browser/notifications/message_center_settings_controller_unittest.cc index f4b05b6..538c845 100644 --- a/chrome/browser/notifications/message_center_settings_controller_unittest.cc +++ b/chrome/browser/notifications/message_center_settings_controller_unittest.cc @@ -51,7 +51,7 @@ class MessageCenterSettingsControllerBaseTest : public testing::Test { void CreateController() { controller_.reset(new MessageCenterSettingsController( - testing_profile_manager_.profile_info_cache())); + *testing_profile_manager_.profile_attributes_storage())); } void ResetController() { @@ -131,20 +131,15 @@ TEST_F(MessageCenterSettingsControllerTest, NotifierGroups) { EXPECT_EQ(controller()->GetNotifierGroupAt(0).name, base::UTF8ToUTF16("Profile-1")); - EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 0u); - EXPECT_EQ(controller()->GetNotifierGroupAt(1).name, base::UTF8ToUTF16("Profile-2")); - EXPECT_EQ(controller()->GetNotifierGroupAt(1).index, 1u); EXPECT_EQ(controller()->GetActiveNotifierGroup().name, base::UTF8ToUTF16("Profile-1")); - EXPECT_EQ(controller()->GetActiveNotifierGroup().index, 0u); controller()->SwitchToNotifierGroup(1); EXPECT_EQ(controller()->GetActiveNotifierGroup().name, base::UTF8ToUTF16("Profile-2")); - EXPECT_EQ(controller()->GetActiveNotifierGroup().index, 1u); controller()->SwitchToNotifierGroup(0); EXPECT_EQ(controller()->GetActiveNotifierGroup().name, @@ -160,19 +155,16 @@ TEST_F(MessageCenterSettingsControllerChromeOSTest, NotifierGroups) { EXPECT_EQ(controller()->GetNotifierGroupAt(0).name, base::UTF8ToUTF16("Profile-1")); - EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 0u); SwitchActiveUser("Profile-2"); EXPECT_EQ(controller()->GetNotifierGroupCount(), 1u); EXPECT_EQ(controller()->GetNotifierGroupAt(0).name, base::UTF8ToUTF16("Profile-2")); - EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 1u); SwitchActiveUser("Profile-1"); EXPECT_EQ(controller()->GetNotifierGroupCount(), 1u); EXPECT_EQ(controller()->GetNotifierGroupAt(0).name, base::UTF8ToUTF16("Profile-1")); - EXPECT_EQ(controller()->GetNotifierGroupAt(0).index, 0u); } // TODO(mukai): write a test case to reproduce the actual guest session scenario // in ChromeOS -- no profiles in the profile_info_cache. diff --git a/chrome/browser/notifications/notification_ui_manager_desktop.cc b/chrome/browser/notifications/notification_ui_manager_desktop.cc index c03f4be..7de03bb 100644 --- a/chrome/browser/notifications/notification_ui_manager_desktop.cc +++ b/chrome/browser/notifications/notification_ui_manager_desktop.cc @@ -11,7 +11,6 @@ #include "chrome/browser/notifications/message_center_notification_manager.h" #include "chrome/browser/notifications/message_center_settings_controller.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" // static @@ -20,10 +19,9 @@ NotificationUIManager* NotificationUIManager::Create(PrefService* local_state) { if (!profile_manager) return nullptr; - ProfileInfoCache* profile_info_cache = - &profile_manager->GetProfileInfoCache(); scoped_ptr<message_center::NotifierSettingsProvider> settings_provider( - new MessageCenterSettingsController(profile_info_cache)); + new MessageCenterSettingsController( + profile_manager->GetProfileAttributesStorage())); return new MessageCenterNotificationManager( g_browser_process->message_center(), std::move(settings_provider)); diff --git a/chrome/browser/notifications/platform_notification_service_impl.cc b/chrome/browser/notifications/platform_notification_service_impl.cc index 4ecaf15..5db0d1c 100644 --- a/chrome/browser/notifications/platform_notification_service_impl.cc +++ b/chrome/browser/notifications/platform_notification_service_impl.cc @@ -63,6 +63,8 @@ using content::BrowserThread; using content::PlatformNotificationContext; using message_center::NotifierId; +class ProfileAttributesEntry; + namespace { // Invalid id for a renderer process. Used in cases where we need to check for @@ -163,11 +165,11 @@ void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( // if it already exist. We therefore check first that the profile is there // and fail early otherwise. const base::FilePath profile_path = - profile_manager->GetProfileInfoCache().GetUserDataDir().AppendASCII( - profile_id); + profile_manager->user_data_dir().AppendASCII(profile_id); - if (profile_manager->GetProfileInfoCache().GetIndexOfProfileWithPath( - profile_path) == std::string::npos) { + ProfileAttributesEntry* entry = nullptr; + if (!profile_manager->GetProfileAttributesStorage(). + GetProfileAttributesWithPath(profile_path, &entry)) { LOG(ERROR) << "Loading a path that does not exist"; return; } diff --git a/chrome/browser/profiles/profile_attributes_storage.h b/chrome/browser/profiles/profile_attributes_storage.h index 67b82af..be37714 100644 --- a/chrome/browser/profiles/profile_attributes_storage.h +++ b/chrome/browser/profiles/profile_attributes_storage.h @@ -7,12 +7,22 @@ #include <stddef.h> +#include <string> +#include <vector> + #include "base/macros.h" +#include "base/strings/string16.h" +#include "chrome/browser/profiles/profile_info_cache_observer.h" +namespace base { +class FilePath; +} // namespace base class ProfileAttributesEntry; class ProfileAttributesStorage { public: + using Observer = ProfileInfoCacheObserver; + ProfileAttributesStorage() {} ~ProfileAttributesStorage() {} @@ -46,6 +56,10 @@ class ProfileAttributesStorage { // Returns the count of known profiles. virtual size_t GetNumberOfProfiles() const = 0; + virtual void AddObserver(ProfileAttributesStorage::Observer* observer) = 0; + virtual void RemoveObserver(ProfileAttributesStorage::Observer* observer) = 0; + + private: DISALLOW_COPY_AND_ASSIGN(ProfileAttributesStorage); }; diff --git a/chrome/browser/profiles/profile_info_cache.h b/chrome/browser/profiles/profile_info_cache.h index a8137c8..7fffcf8 100644 --- a/chrome/browser/profiles/profile_info_cache.h +++ b/chrome/browser/profiles/profile_info_cache.h @@ -182,8 +182,8 @@ class ProfileInfoCache : public ProfileInfoInterface, const base::FilePath& image_path, const base::FilePath& profile_path); - void AddObserver(ProfileInfoCacheObserver* obs); - void RemoveObserver(ProfileInfoCacheObserver* obs); + void AddObserver(ProfileInfoCacheObserver* obs) override; + void RemoveObserver(ProfileInfoCacheObserver* obs) override; void set_disable_avatar_download_for_testing( bool disable_avatar_download_for_testing) { diff --git a/ui/message_center/cocoa/settings_controller_unittest.mm b/ui/message_center/cocoa/settings_controller_unittest.mm index c686fcf..a1291b7 100644 --- a/ui/message_center/cocoa/settings_controller_unittest.mm +++ b/ui/message_center/cocoa/settings_controller_unittest.mm @@ -37,8 +37,7 @@ NotifierGroup* NewGroup(const std::string& name, const std::string& login_info) { return new NotifierGroup(gfx::Image(), base::UTF8ToUTF16(name), - base::UTF8ToUTF16(login_info), - true); + base::UTF8ToUTF16(login_info)); } Notifier* NewNotifier(const std::string& id, diff --git a/ui/message_center/fake_notifier_settings_provider.cc b/ui/message_center/fake_notifier_settings_provider.cc index 79c153a..9465149 100644 --- a/ui/message_center/fake_notifier_settings_provider.cc +++ b/ui/message_center/fake_notifier_settings_provider.cc @@ -28,8 +28,7 @@ FakeNotifierSettingsProvider::FakeNotifierSettingsProvider( NotifierGroupItem item; item.group = new NotifierGroup(gfx::Image(), base::UTF8ToUTF16("Fake name"), - base::UTF8ToUTF16("fake@email.com"), - true); + base::UTF8ToUTF16("fake@email.com")); item.notifiers = notifiers; items_.push_back(item); } diff --git a/ui/message_center/notifier_settings.cc b/ui/message_center/notifier_settings.cc index 2654611..72a378b 100644 --- a/ui/message_center/notifier_settings.cc +++ b/ui/message_center/notifier_settings.cc @@ -63,9 +63,8 @@ Notifier::~Notifier() { NotifierGroup::NotifierGroup(const gfx::Image& icon, const base::string16& name, - const base::string16& login_info, - size_t index) - : icon(icon), name(name), login_info(login_info), index(index) {} + const base::string16& login_info) + : icon(icon), name(name), login_info(login_info) {} NotifierGroup::~NotifierGroup() {} diff --git a/ui/message_center/notifier_settings.h b/ui/message_center/notifier_settings.h index 95646af..43e2032 100644 --- a/ui/message_center/notifier_settings.h +++ b/ui/message_center/notifier_settings.h @@ -8,6 +8,7 @@ #include <stddef.h> #include <string> +#include <vector> #include "base/gtest_prod_util.h" #include "base/macros.h" @@ -114,8 +115,7 @@ struct MESSAGE_CENTER_EXPORT Notifier { struct MESSAGE_CENTER_EXPORT NotifierGroup { NotifierGroup(const gfx::Image& icon, const base::string16& name, - const base::string16& login_info, - size_t index); + const base::string16& login_info); ~NotifierGroup(); // Icon of a notifier group. @@ -127,10 +127,6 @@ struct MESSAGE_CENTER_EXPORT NotifierGroup { // More display information about the notifier group. base::string16 login_info; - // Unique identifier for the notifier group so that they can be selected in - // the UI. - const size_t index; - private: DISALLOW_COPY_AND_ASSIGN(NotifierGroup); }; @@ -155,7 +151,7 @@ class MESSAGE_CENTER_EXPORT NotifierSettingsObserver { // for the clients of this module. class MESSAGE_CENTER_EXPORT NotifierSettingsProvider { public: - virtual ~NotifierSettingsProvider() {}; + virtual ~NotifierSettingsProvider() {} // Sets the delegate. virtual void AddObserver(NotifierSettingsObserver* observer) = 0; |
