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 17 matching lines...) Expand all Loading... | |
52 using message_center::Notifier; | 55 using message_center::Notifier; |
53 using message_center::NotifierId; | 56 using message_center::NotifierId; |
54 | 57 |
55 namespace message_center { | 58 namespace message_center { |
56 | 59 |
57 class ProfileNotifierGroup : public message_center::NotifierGroup { | 60 class ProfileNotifierGroup : public message_center::NotifierGroup { |
58 public: | 61 public: |
59 ProfileNotifierGroup(const gfx::Image& icon, | 62 ProfileNotifierGroup(const gfx::Image& icon, |
60 const base::string16& display_name, | 63 const base::string16& display_name, |
61 const base::string16& login_info, | 64 const base::string16& login_info, |
62 size_t index, | |
63 const base::FilePath& profile_path); | 65 const base::FilePath& profile_path); |
64 ProfileNotifierGroup(const gfx::Image& icon, | 66 ProfileNotifierGroup(const gfx::Image& icon, |
65 const base::string16& display_name, | 67 const base::string16& display_name, |
66 const base::string16& login_info, | 68 const base::string16& login_info, |
67 size_t index, | |
68 Profile* profile); | 69 Profile* profile); |
69 virtual ~ProfileNotifierGroup() {} | 70 virtual ~ProfileNotifierGroup() {} |
70 | 71 |
71 Profile* profile() const { return profile_; } | 72 Profile* profile() const { return profile_; } |
72 | 73 |
73 private: | 74 private: |
74 Profile* profile_; | 75 Profile* profile_; |
75 }; | 76 }; |
76 | 77 |
77 ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, | 78 ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, |
78 const base::string16& display_name, | 79 const base::string16& display_name, |
79 const base::string16& login_info, | 80 const base::string16& login_info, |
80 size_t index, | |
81 const base::FilePath& profile_path) | 81 const base::FilePath& profile_path) |
82 : message_center::NotifierGroup(icon, display_name, login_info, index), | 82 : message_center::NotifierGroup(icon, display_name, login_info), |
83 profile_(NULL) { | 83 profile_(NULL) { |
84 // Try to get the profile | 84 // Try to get the profile |
85 profile_ = | 85 profile_ = |
86 g_browser_process->profile_manager()->GetProfileByPath(profile_path); | 86 g_browser_process->profile_manager()->GetProfileByPath(profile_path); |
87 } | 87 } |
88 | 88 |
89 ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, | 89 ProfileNotifierGroup::ProfileNotifierGroup(const gfx::Image& icon, |
90 const base::string16& display_name, | 90 const base::string16& display_name, |
91 const base::string16& login_info, | 91 const base::string16& login_info, |
92 size_t index, | |
93 Profile* profile) | 92 Profile* profile) |
94 : message_center::NotifierGroup(icon, display_name, login_info, index), | 93 : message_center::NotifierGroup(icon, display_name, login_info), |
95 profile_(profile) { | 94 profile_(profile) { |
96 } | 95 } |
97 | 96 |
98 } // namespace message_center | 97 } // namespace message_center |
99 | 98 |
100 namespace { | 99 namespace { |
101 class NotifierComparator { | 100 class NotifierComparator { |
102 public: | 101 public: |
103 explicit NotifierComparator(icu::Collator* collator) : collator_(collator) {} | 102 explicit NotifierComparator(icu::Collator* collator) : collator_(collator) {} |
104 | 103 |
105 bool operator() (Notifier* n1, Notifier* n2) { | 104 bool operator() (Notifier* n1, Notifier* n2) { |
106 if (n1->notifier_id.type != n2->notifier_id.type) | 105 if (n1->notifier_id.type != n2->notifier_id.type) |
107 return n1->notifier_id.type < n2->notifier_id.type; | 106 return n1->notifier_id.type < n2->notifier_id.type; |
108 | 107 |
109 if (collator_) { | 108 if (collator_) { |
110 return base::i18n::CompareString16WithCollator(*collator_, n1->name, | 109 return base::i18n::CompareString16WithCollator(*collator_, n1->name, |
111 n2->name) == UCOL_LESS; | 110 n2->name) == UCOL_LESS; |
112 } | 111 } |
113 return n1->name < n2->name; | 112 return n1->name < n2->name; |
114 } | 113 } |
115 | 114 |
116 private: | 115 private: |
117 icu::Collator* collator_; | 116 icu::Collator* collator_; |
118 }; | 117 }; |
119 | 118 |
120 } // namespace | 119 } // namespace |
121 | 120 |
122 MessageCenterSettingsController::MessageCenterSettingsController( | 121 MessageCenterSettingsController::MessageCenterSettingsController( |
123 ProfileInfoCache* profile_info_cache) | 122 ProfileAttributesStorage& storage) |
124 : current_notifier_group_(0), | 123 : current_notifier_group_(0), |
125 profile_info_cache_(profile_info_cache), | 124 storage_(storage), |
126 weak_factory_(this) { | 125 weak_factory_(this) { |
127 DCHECK(profile_info_cache_); | |
128 // The following events all represent changes that may need to be reflected in | 126 // 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 | 127 // the profile selector context menu, so listen for them all. We'll just |
130 // rebuild the list when we get any of them. | 128 // rebuild the list when we get any of them. |
131 registrar_.Add(this, | 129 registrar_.Add(this, |
132 chrome::NOTIFICATION_PROFILE_CREATED, | 130 chrome::NOTIFICATION_PROFILE_CREATED, |
133 content::NotificationService::AllBrowserContextsAndSources()); | 131 content::NotificationService::AllBrowserContextsAndSources()); |
134 registrar_.Add(this, | 132 registrar_.Add(this, |
135 chrome::NOTIFICATION_PROFILE_ADDED, | 133 chrome::NOTIFICATION_PROFILE_ADDED, |
136 content::NotificationService::AllBrowserContextsAndSources()); | 134 content::NotificationService::AllBrowserContextsAndSources()); |
137 registrar_.Add(this, | 135 registrar_.Add(this, |
138 chrome::NOTIFICATION_PROFILE_DESTROYED, | 136 chrome::NOTIFICATION_PROFILE_DESTROYED, |
139 content::NotificationService::AllBrowserContextsAndSources()); | 137 content::NotificationService::AllBrowserContextsAndSources()); |
140 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); | 138 storage_.AddObserver(this); |
141 RebuildNotifierGroups(false); | 139 RebuildNotifierGroups(false); |
142 | 140 |
143 #if defined(OS_CHROMEOS) | 141 #if defined(OS_CHROMEOS) |
144 // UserManager may not exist in some tests. | 142 // UserManager may not exist in some tests. |
145 if (user_manager::UserManager::IsInitialized()) | 143 if (user_manager::UserManager::IsInitialized()) |
146 user_manager::UserManager::Get()->AddSessionStateObserver(this); | 144 user_manager::UserManager::Get()->AddSessionStateObserver(this); |
147 #endif | 145 #endif |
148 } | 146 } |
149 | 147 |
150 MessageCenterSettingsController::~MessageCenterSettingsController() { | 148 MessageCenterSettingsController::~MessageCenterSettingsController() { |
151 g_browser_process->profile_manager()-> | 149 storage_.RemoveObserver(this); |
152 GetProfileInfoCache().RemoveObserver(this); | |
153 #if defined(OS_CHROMEOS) | 150 #if defined(OS_CHROMEOS) |
154 // UserManager may not exist in some tests. | 151 // UserManager may not exist in some tests. |
155 if (user_manager::UserManager::IsInitialized()) | 152 if (user_manager::UserManager::IsInitialized()) |
156 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); | 153 user_manager::UserManager::Get()->RemoveSessionStateObserver(this); |
157 #endif | 154 #endif |
158 } | 155 } |
159 | 156 |
160 void MessageCenterSettingsController::AddObserver( | 157 void MessageCenterSettingsController::AddObserver( |
161 message_center::NotifierSettingsObserver* observer) { | 158 message_center::NotifierSettingsObserver* observer) { |
162 observers_.AddObserver(observer); | 159 observers_.AddObserver(observer); |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 | 482 |
486 user_manager::User* user = user_manager->GetActiveUser(); | 483 user_manager::User* user = user_manager->GetActiveUser(); |
487 Profile* profile = | 484 Profile* profile = |
488 chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 485 chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
489 DCHECK(profile); | 486 DCHECK(profile); |
490 | 487 |
491 scoped_ptr<message_center::ProfileNotifierGroup> group( | 488 scoped_ptr<message_center::ProfileNotifierGroup> group( |
492 new message_center::ProfileNotifierGroup(gfx::Image(user->GetImage()), | 489 new message_center::ProfileNotifierGroup(gfx::Image(user->GetImage()), |
493 user->GetDisplayName(), | 490 user->GetDisplayName(), |
494 user->GetDisplayName(), | 491 user->GetDisplayName(), |
495 0, | |
496 profile)); | 492 profile)); |
497 | 493 |
498 notifier_groups_.push_back(std::move(group)); | 494 notifier_groups_.push_back(std::move(group)); |
499 | 495 |
500 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 496 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
501 observers_, | 497 observers_, |
502 NotifierGroupChanged()); | 498 NotifierGroupChanged()); |
503 } | 499 } |
504 #endif | 500 #endif |
505 | 501 |
506 void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) { | 502 void MessageCenterSettingsController::RebuildNotifierGroups(bool notify) { |
507 notifier_groups_.clear(); | 503 notifier_groups_.clear(); |
508 current_notifier_group_ = 0; | 504 current_notifier_group_ = 0; |
509 | 505 |
510 const size_t count = profile_info_cache_->GetNumberOfProfiles(); | 506 std::vector<ProfileAttributesEntry*> entries = |
511 for (size_t i = 0; i < count; ++i) { | 507 storage_.GetAllProfilesAttributes(); |
lwchkg
2016/02/07 16:36:23
Is it needed to sort the entries in a particular o
dewittj
2016/02/08 18:07:10
At this point, I believe the number of profiles wi
lwchkg
2016/02/08 19:06:43
Confused. Does the "1" count the profiles that are
dewittj
2016/02/08 19:11:45
This code is used to show a UI so users can choose
lwchkg
2016/02/08 19:22:00
I see. How can I access that UI?
dewittj
2016/02/08 19:28:03
1. Get a notification (could be from https://tests
lwchkg
2016/02/10 14:57:24
Thanks for explanation. I'll just land the CL.
| |
508 for (const auto entry : entries) { | |
512 scoped_ptr<message_center::ProfileNotifierGroup> group( | 509 scoped_ptr<message_center::ProfileNotifierGroup> group( |
513 new message_center::ProfileNotifierGroup( | 510 new message_center::ProfileNotifierGroup( |
514 profile_info_cache_->GetAvatarIconOfProfileAtIndex(i), | 511 entry->GetAvatarIcon(), |
515 profile_info_cache_->GetNameOfProfileAtIndex(i), | 512 entry->GetName(), |
516 profile_info_cache_->GetUserNameOfProfileAtIndex(i), | 513 entry->GetUserName(), |
517 i, | 514 entry->GetPath())); |
518 profile_info_cache_->GetPathOfProfileAtIndex(i))); | |
519 if (group->profile() == NULL) | 515 if (group->profile() == NULL) |
520 continue; | 516 continue; |
521 | 517 |
522 #if defined(OS_CHROMEOS) | 518 #if defined(OS_CHROMEOS) |
523 // Allows the active user only. | 519 // Allows the active user only. |
524 // UserManager may not exist in some tests. | 520 // UserManager may not exist in some tests. |
525 if (user_manager::UserManager::IsInitialized()) { | 521 if (user_manager::UserManager::IsInitialized()) { |
526 user_manager::UserManager* user_manager = | 522 user_manager::UserManager* user_manager = |
527 user_manager::UserManager::Get(); | 523 user_manager::UserManager::Get(); |
528 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != | 524 if (chromeos::ProfileHelper::Get()->GetUserByProfile(group->profile()) != |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 weak_factory_.GetWeakPtr())); | 556 weak_factory_.GetWeakPtr())); |
561 } | 557 } |
562 #endif | 558 #endif |
563 | 559 |
564 if (notify) { | 560 if (notify) { |
565 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, | 561 FOR_EACH_OBSERVER(message_center::NotifierSettingsObserver, |
566 observers_, | 562 observers_, |
567 NotifierGroupChanged()); | 563 NotifierGroupChanged()); |
568 } | 564 } |
569 } | 565 } |
OLD | NEW |