OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/message_center_settings_controller.h" | 5 #include "chrome/browser/notifications/message_center_settings_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/i18n/string_compare.h" | 12 #include "base/i18n/string_compare.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/task/cancelable_task_tracker.h" | 14 #include "base/task/cancelable_task_tracker.h" |
14 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
19 #include "chrome/browser/extensions/app_icon_loader_impl.h" | 20 #include "chrome/browser/extensions/app_icon_loader_impl.h" |
20 #include "chrome/browser/favicon/favicon_service_factory.h" | 21 #include "chrome/browser/favicon/favicon_service_factory.h" |
21 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 22 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
22 #include "chrome/browser/notifications/notifier_state_tracker.h" | 23 #include "chrome/browser/notifications/notifier_state_tracker.h" |
23 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 24 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/profiles/profile_attributes_entry.h" | |
27 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
25 #include "chrome/browser/profiles/profile_info_cache.h" | 28 #include "chrome/browser/profiles/profile_info_cache.h" |
26 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/common/extensions/api/notifications.h" | 30 #include "chrome/common/extensions/api/notifications.h" |
28 #include "chrome/common/extensions/extension_constants.h" | 31 #include "chrome/common/extensions/extension_constants.h" |
29 #include "components/content_settings/core/browser/host_content_settings_map.h" | 32 #include "components/content_settings/core/browser/host_content_settings_map.h" |
30 #include "components/favicon/core/favicon_service.h" | 33 #include "components/favicon/core/favicon_service.h" |
31 #include "components/favicon_base/favicon_types.h" | 34 #include "components/favicon_base/favicon_types.h" |
32 #include "components/history/core/browser/history_types.h" | 35 #include "components/history/core/browser/history_types.h" |
33 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
34 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 return n1->name < n2->name; | 116 return n1->name < n2->name; |
114 } | 117 } |
115 | 118 |
116 private: | 119 private: |
117 icu::Collator* collator_; | 120 icu::Collator* collator_; |
118 }; | 121 }; |
119 | 122 |
120 } // namespace | 123 } // namespace |
121 | 124 |
122 MessageCenterSettingsController::MessageCenterSettingsController( | 125 MessageCenterSettingsController::MessageCenterSettingsController( |
123 ProfileInfoCache* profile_info_cache) | 126 ProfileAttributesStorage& storage) |
124 : current_notifier_group_(0), | 127 : current_notifier_group_(0), |
125 profile_info_cache_(profile_info_cache), | 128 storage_(storage), |
126 weak_factory_(this) { | 129 weak_factory_(this) { |
127 DCHECK(profile_info_cache_); | |
128 // The following events all represent changes that may need to be reflected in | 130 // The following events all represent changes that may need to be reflected in |
129 // the profile selector context menu, so listen for them all. We'll just | 131 // the profile selector context menu, so listen for them all. We'll just |
130 // rebuild the list when we get any of them. | 132 // rebuild the list when we get any of them. |
131 registrar_.Add(this, | 133 registrar_.Add(this, |
132 chrome::NOTIFICATION_PROFILE_CREATED, | 134 chrome::NOTIFICATION_PROFILE_CREATED, |
133 content::NotificationService::AllBrowserContextsAndSources()); | 135 content::NotificationService::AllBrowserContextsAndSources()); |
134 registrar_.Add(this, | 136 registrar_.Add(this, |
135 chrome::NOTIFICATION_PROFILE_ADDED, | 137 chrome::NOTIFICATION_PROFILE_ADDED, |
136 content::NotificationService::AllBrowserContextsAndSources()); | 138 content::NotificationService::AllBrowserContextsAndSources()); |
137 registrar_.Add(this, | 139 registrar_.Add(this, |
138 chrome::NOTIFICATION_PROFILE_DESTROYED, | 140 chrome::NOTIFICATION_PROFILE_DESTROYED, |
139 content::NotificationService::AllBrowserContextsAndSources()); | 141 content::NotificationService::AllBrowserContextsAndSources()); |
140 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 142 storage_.AddObserver(this); |
141 RebuildNotifierGroups(false); | 143 RebuildNotifierGroups(false); |
142 | 144 |
143 #if defined(OS_CHROMEOS) | 145 #if defined(OS_CHROMEOS) |
144 // UserManager may not exist in some tests. | 146 // UserManager may not exist in some tests. |
145 if (user_manager::UserManager::IsInitialized()) | 147 if (user_manager::UserManager::IsInitialized()) |
146 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 148 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
147 #endif | 149 #endif |
148 } | 150 } |
149 | 151 |
150 MessageCenterSettingsController::~MessageCenterSettingsController() { | 152 MessageCenterSettingsController::~MessageCenterSettingsController() { |
151 g_browser_process->profile_manager()-> | 153 storage_.RemoveObserver(this); |
152 GetProfileInfoCache().RemoveObserver(this); | |
153 #if defined(OS_CHROMEOS) | 154 #if defined(OS_CHROMEOS) |
154 // UserManager may not exist in some tests. | 155 // UserManager may not exist in some tests. |
155 if (user_manager::UserManager::IsInitialized()) | 156 if (user_manager::UserManager::IsInitialized()) |
156 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); | 157 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
157 #endif | 158 #endif |
158 } | 159 } |
159 | 160 |
160 void MessageCenterSettingsController::AddObserver( | 161 void MessageCenterSettingsController::AddObserver( |
161 message_center::NotifierSettingsObserver* observer) { | 162 message_center::NotifierSettingsObserver* observer) { |
162 observers_.AddObserver(observer); | 163 observers_.AddObserver(observer); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 501 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
501 observers_, | 502 observers_, |
502 NotifierGroupChanged()); | 503 NotifierGroupChanged()); |
503 } | 504 } |
504 #endif | 505 #endif |
505 | 506 |
506 void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) { | 507 void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) { |
507 notifier_groups_.clear(); | 508 notifier_groups_.clear(); |
508 current_notifier_group_ = 0; | 509 current_notifier_group_ = 0; |
509 | 510 |
510 const size_t count = profile_info_cache_->GetNumberOfProfiles(); | 511 std::vector<ProfileAttributesEntry*> entries = |
511 for (size_t i = 0; i < count; ++i) { | 512 storage_.GetAllProfilesAttributes(); |
513 ProfileInfoCache& cache = g_browser_process->profile_manager()-> | |
514 GetProfileInfoCache(); | |
515 for (const auto entry : entries) { | |
512 scoped_ptr<message_center::ProfileNotifierGroup> group( | 516 scoped_ptr<message_center::ProfileNotifierGroup> group( |
513 new message_center::ProfileNotifierGroup( | 517 new message_center::ProfileNotifierGroup( |
514 profile_info_cache_->GetAvatarIconOfProfileAtIndex(i), | 518 entry->GetAvatarIcon(), |
515 profile_info_cache_->GetNameOfProfileAtIndex(i), | 519 entry->GetName(), |
516 profile_info_cache_->GetUserNameOfProfileAtIndex(i), | 520 entry->GetUserName(), |
517 i, | 521 cache.GetIndexOfProfileWithPath(entry->GetPath()), |
518 profile_info_cache_->GetPathOfProfileAtIndex(i))); | 522 entry->GetPath())); |
lwchkg
2016/02/03 17:40:12
Do you know what is the use of the index in Profil
dewittj
2016/02/03 17:43:59
According to code search it isn't used at all. I
| |
519 if (group->profile() == NULL) | 523 if (group->profile() == NULL) |
520 continue; | 524 continue; |
521 | 525 |
522 #if defined(OS_CHROMEOS) | 526 #if defined(OS_CHROMEOS) |
523 // Allows the active user only. | 527 // Allows the active user only. |
524 // UserManager may not exist in some tests. | 528 // UserManager may not exist in some tests. |
525 if (user_manager::UserManager::IsInitialized()) { | 529 if (user_manager::UserManager::IsInitialized()) { |
526 user_manager::UserManager* user_manager = | 530 user_manager::UserManager* user_manager = |
527 user_manager::UserManager::Get(); | 531 user_manager::UserManager::Get(); |
528 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != | 532 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 weak_factory_.GetWeakPtr())); | 564 weak_factory_.GetWeakPtr())); |
561 } | 565 } |
562 #endif | 566 #endif |
563 | 567 |
564 if (notify) { | 568 if (notify) { |
565 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 569 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
566 observers_, | 570 observers_, |
567 NotifierGroupChanged()); | 571 NotifierGroupChanged()); |
568 } | 572 } |
569 } | 573 } |
OLD | NEW |