OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/ash/launcher/chrome_launcher_controller_per_browser.
h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_browser.
h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); | 167 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); |
168 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); | 168 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); |
169 | 169 |
170 notification_registrar_.Add(this, | 170 notification_registrar_.Add(this, |
171 chrome::NOTIFICATION_EXTENSION_LOADED, | 171 chrome::NOTIFICATION_EXTENSION_LOADED, |
172 content::Source<Profile>(profile_)); | 172 content::Source<Profile>(profile_)); |
173 notification_registrar_.Add(this, | 173 notification_registrar_.Add(this, |
174 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 174 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
175 content::Source<Profile>(profile_)); | 175 content::Source<Profile>(profile_)); |
176 pref_change_registrar_.Init(profile_->GetPrefs()); | 176 pref_change_registrar_.Init(profile_->GetPrefs()); |
177 pref_change_registrar_.Add( | 177 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); |
178 prefs::kPinnedLauncherApps, | |
179 base::Bind(&ChromeLauncherControllerPerBrowser:: | |
180 UpdateAppLaunchersFromPref, | |
181 base::Unretained(this))); | |
182 } | 178 } |
183 | 179 |
184 ChromeLauncherControllerPerBrowser::~ChromeLauncherControllerPerBrowser() { | 180 ChromeLauncherControllerPerBrowser::~ChromeLauncherControllerPerBrowser() { |
185 // Reset the shell window controller here since it has a weak pointer to | 181 // Reset the shell window controller here since it has a weak pointer to |
186 // this. | 182 // this. |
187 shell_window_controller_.reset(); | 183 shell_window_controller_.reset(); |
188 | 184 |
189 model_->RemoveObserver(this); | 185 model_->RemoveObserver(this); |
190 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 186 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
191 i != id_to_item_controller_map_.end(); ++i) { | 187 i != id_to_item_controller_map_.end(); ++i) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 updater.Get()->Clear(); | 222 updater.Get()->Clear(); |
227 } | 223 } |
228 | 224 |
229 UpdateAppLaunchersFromPref(); | 225 UpdateAppLaunchersFromPref(); |
230 | 226 |
231 // TODO(sky): update unit test so that this test isn't necessary. | 227 // TODO(sky): update unit test so that this test isn't necessary. |
232 if (ash::Shell::HasInstance()) { | 228 if (ash::Shell::HasInstance()) { |
233 SetShelfAutoHideBehaviorFromPrefs(); | 229 SetShelfAutoHideBehaviorFromPrefs(); |
234 SetShelfAlignmentFromPrefs(); | 230 SetShelfAlignmentFromPrefs(); |
235 PrefService* prefs = profile_->GetPrefs(); | 231 PrefService* prefs = profile_->GetPrefs(); |
236 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty()) { | 232 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || |
237 pref_change_registrar_.Add( | 233 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { |
238 prefs::kShelfAlignmentLocal, | 234 prefs->AddObserver(this); |
239 base::Bind(&ChromeLauncherControllerPerBrowser:: | |
240 SetShelfAlignmentFromPrefs, | |
241 base::Unretained(this))); | |
242 } | |
243 if (prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { | |
244 pref_change_registrar_.Add( | |
245 prefs::kShelfAutoHideBehaviorLocal, | |
246 base::Bind(&ChromeLauncherControllerPerBrowser:: | |
247 SetShelfAutoHideBehaviorFromPrefs, | |
248 base::Unretained(this))); | |
249 } | 235 } |
250 ash::Shell::GetInstance()->AddShellObserver(this); | 236 ash::Shell::GetInstance()->AddShellObserver(this); |
251 } | 237 } |
252 } | 238 } |
253 | 239 |
254 ash::LauncherID ChromeLauncherControllerPerBrowser::CreateTabbedLauncherItem( | 240 ash::LauncherID ChromeLauncherControllerPerBrowser::CreateTabbedLauncherItem( |
255 LauncherItemController* controller, | 241 LauncherItemController* controller, |
256 IncognitoState is_incognito, | 242 IncognitoState is_incognito, |
257 ash::LauncherItemStatus status) { | 243 ash::LauncherItemStatus status) { |
258 ash::LauncherID id = model_->next_id(); | 244 ash::LauncherID id = model_->next_id(); |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 if (IsAppPinned(extension->id())) | 781 if (IsAppPinned(extension->id())) |
796 DoUnpinAppsWithID(extension->id()); | 782 DoUnpinAppsWithID(extension->id()); |
797 app_icon_loader_->ClearImage(extension->id()); | 783 app_icon_loader_->ClearImage(extension->id()); |
798 break; | 784 break; |
799 } | 785 } |
800 default: | 786 default: |
801 NOTREACHED() << "Unexpected notification type=" << type; | 787 NOTREACHED() << "Unexpected notification type=" << type; |
802 } | 788 } |
803 } | 789 } |
804 | 790 |
| 791 void ChromeLauncherControllerPerBrowser::OnPreferenceChanged( |
| 792 PrefServiceBase* service, |
| 793 const std::string& pref_name) { |
| 794 if (pref_name == prefs::kPinnedLauncherApps) { |
| 795 UpdateAppLaunchersFromPref(); |
| 796 } else if (pref_name == prefs::kShelfAlignmentLocal) { |
| 797 SetShelfAlignmentFromPrefs(); |
| 798 } else if (pref_name == prefs::kShelfAutoHideBehaviorLocal) { |
| 799 SetShelfAutoHideBehaviorFromPrefs(); |
| 800 } else { |
| 801 NOTREACHED() << "Unexpected pref change for " << pref_name; |
| 802 } |
| 803 } |
| 804 |
805 void ChromeLauncherControllerPerBrowser::OnShelfAlignmentChanged() { | 805 void ChromeLauncherControllerPerBrowser::OnShelfAlignmentChanged() { |
806 const char* pref_value = NULL; | 806 const char* pref_value = NULL; |
807 // TODO(oshima): Support multiple displays. | 807 // TODO(oshima): Support multiple displays. |
808 switch (ash::Shell::GetInstance()->GetShelfAlignment( | 808 switch (ash::Shell::GetInstance()->GetShelfAlignment( |
809 ash::Shell::GetPrimaryRootWindow())) { | 809 ash::Shell::GetPrimaryRootWindow())) { |
810 case ash::SHELF_ALIGNMENT_BOTTOM: | 810 case ash::SHELF_ALIGNMENT_BOTTOM: |
811 pref_value = ash::kShelfAlignmentBottom; | 811 pref_value = ash::kShelfAlignmentBottom; |
812 break; | 812 break; |
813 case ash::SHELF_ALIGNMENT_LEFT: | 813 case ash::SHELF_ALIGNMENT_LEFT: |
814 pref_value = ash::kShelfAlignmentLeft; | 814 pref_value = ash::kShelfAlignmentLeft; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 ash::LauncherID id = model_->items()[i].id; | 863 ash::LauncherID id = model_->items()[i].id; |
864 if (HasItemController(id) && IsPinned(id)) { | 864 if (HasItemController(id) && IsPinned(id)) { |
865 base::DictionaryValue* app_value = ash::CreateAppDict( | 865 base::DictionaryValue* app_value = ash::CreateAppDict( |
866 id_to_item_controller_map_[id]->app_id()); | 866 id_to_item_controller_map_[id]->app_id()); |
867 if (app_value) | 867 if (app_value) |
868 updater->Append(app_value); | 868 updater->Append(app_value); |
869 } | 869 } |
870 } | 870 } |
871 } | 871 } |
872 } | 872 } |
873 pref_change_registrar_.Add( | 873 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); |
874 prefs::kPinnedLauncherApps, | |
875 base::Bind(&ChromeLauncherControllerPerBrowser:: | |
876 UpdateAppLaunchersFromPref, | |
877 base::Unretained(this))); | |
878 } | 874 } |
879 | 875 |
880 ash::LauncherModel* ChromeLauncherControllerPerBrowser::model() { | 876 ash::LauncherModel* ChromeLauncherControllerPerBrowser::model() { |
881 return model_; | 877 return model_; |
882 } | 878 } |
883 | 879 |
884 Profile* ChromeLauncherControllerPerBrowser::profile() { | 880 Profile* ChromeLauncherControllerPerBrowser::profile() { |
885 return profile_; | 881 return profile_; |
886 } | 882 } |
887 | 883 |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 AppIconLoader* loader) { | 1106 AppIconLoader* loader) { |
1111 app_icon_loader_.reset(loader); | 1107 app_icon_loader_.reset(loader); |
1112 } | 1108 } |
1113 | 1109 |
1114 const std::string& | 1110 const std::string& |
1115 ChromeLauncherControllerPerBrowser::GetAppIdFromLauncherIdForTest( | 1111 ChromeLauncherControllerPerBrowser::GetAppIdFromLauncherIdForTest( |
1116 ash::LauncherID id) { | 1112 ash::LauncherID id) { |
1117 return id_to_item_controller_map_[id]->app_id(); | 1113 return id_to_item_controller_map_[id]->app_id(); |
1118 } | 1114 } |
1119 | 1115 |
OLD | NEW |