| 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_app.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_per_app.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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); | 166 app_tab_helper_.reset(new LauncherAppTabHelper(profile_)); |
| 167 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); | 167 app_icon_loader_.reset(new LauncherAppIconLoader(profile_, this)); |
| 168 | 168 |
| 169 notification_registrar_.Add(this, | 169 notification_registrar_.Add(this, |
| 170 chrome::NOTIFICATION_EXTENSION_LOADED, | 170 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 171 content::Source<Profile>(profile_)); | 171 content::Source<Profile>(profile_)); |
| 172 notification_registrar_.Add(this, | 172 notification_registrar_.Add(this, |
| 173 chrome::NOTIFICATION_EXTENSION_UNLOADED, | 173 chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 174 content::Source<Profile>(profile_)); | 174 content::Source<Profile>(profile_)); |
| 175 pref_change_registrar_.Init(profile_->GetPrefs()); | 175 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 176 pref_change_registrar_.Add( | 176 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); |
| 177 prefs::kPinnedLauncherApps, | |
| 178 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, | |
| 179 base::Unretained(this))); | |
| 180 } | 177 } |
| 181 | 178 |
| 182 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { | 179 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { |
| 183 // Reset the shell window controller here since it has a weak pointer to this. | 180 // Reset the shell window controller here since it has a weak pointer to this. |
| 184 shell_window_controller_.reset(); | 181 shell_window_controller_.reset(); |
| 185 | 182 |
| 186 model_->RemoveObserver(this); | 183 model_->RemoveObserver(this); |
| 187 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 184 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
| 188 i != id_to_item_controller_map_.end(); ++i) { | 185 i != id_to_item_controller_map_.end(); ++i) { |
| 189 i->second->OnRemoved(); | 186 i->second->OnRemoved(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 updater.Get()->Clear(); | 220 updater.Get()->Clear(); |
| 224 } | 221 } |
| 225 | 222 |
| 226 UpdateAppLaunchersFromPref(); | 223 UpdateAppLaunchersFromPref(); |
| 227 | 224 |
| 228 // TODO(sky): update unit test so that this test isn't necessary. | 225 // TODO(sky): update unit test so that this test isn't necessary. |
| 229 if (ash::Shell::HasInstance()) { | 226 if (ash::Shell::HasInstance()) { |
| 230 SetShelfAutoHideBehaviorFromPrefs(); | 227 SetShelfAutoHideBehaviorFromPrefs(); |
| 231 SetShelfAlignmentFromPrefs(); | 228 SetShelfAlignmentFromPrefs(); |
| 232 PrefService* prefs = profile_->GetPrefs(); | 229 PrefService* prefs = profile_->GetPrefs(); |
| 233 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty()) { | 230 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || |
| 234 pref_change_registrar_.Add( | 231 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { |
| 235 prefs::kShelfAlignmentLocal, | 232 prefs->AddObserver(this); |
| 236 base::Bind( | |
| 237 &ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs, | |
| 238 base::Unretained(this))); | |
| 239 } | |
| 240 if (prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { | |
| 241 pref_change_registrar_.Add( | |
| 242 prefs::kShelfAutoHideBehaviorLocal, | |
| 243 base::Bind(&ChromeLauncherControllerPerApp:: | |
| 244 SetShelfAutoHideBehaviorFromPrefs, | |
| 245 base::Unretained(this))); | |
| 246 } | 233 } |
| 247 ash::Shell::GetInstance()->AddShellObserver(this); | 234 ash::Shell::GetInstance()->AddShellObserver(this); |
| 248 } | 235 } |
| 249 } | 236 } |
| 250 | 237 |
| 251 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( | 238 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( |
| 252 LauncherItemController* controller, | 239 LauncherItemController* controller, |
| 253 IncognitoState is_incognito, | 240 IncognitoState is_incognito, |
| 254 ash::LauncherItemStatus status) { | 241 ash::LauncherItemStatus status) { |
| 255 ash::LauncherID id = model_->next_id(); | 242 ash::LauncherID id = model_->next_id(); |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 if (IsAppPinned(extension->id())) | 776 if (IsAppPinned(extension->id())) |
| 790 DoUnpinAppsWithID(extension->id()); | 777 DoUnpinAppsWithID(extension->id()); |
| 791 app_icon_loader_->ClearImage(extension->id()); | 778 app_icon_loader_->ClearImage(extension->id()); |
| 792 break; | 779 break; |
| 793 } | 780 } |
| 794 default: | 781 default: |
| 795 NOTREACHED() << "Unexpected notification type=" << type; | 782 NOTREACHED() << "Unexpected notification type=" << type; |
| 796 } | 783 } |
| 797 } | 784 } |
| 798 | 785 |
| 786 void ChromeLauncherControllerPerApp::OnPreferenceChanged( |
| 787 PrefServiceBase* service, |
| 788 const std::string& pref_name) { |
| 789 if (pref_name == prefs::kPinnedLauncherApps) { |
| 790 UpdateAppLaunchersFromPref(); |
| 791 } else if (pref_name == prefs::kShelfAlignmentLocal) { |
| 792 SetShelfAlignmentFromPrefs(); |
| 793 } else if (pref_name == prefs::kShelfAutoHideBehaviorLocal) { |
| 794 SetShelfAutoHideBehaviorFromPrefs(); |
| 795 } else { |
| 796 NOTREACHED() << "Unexpected pref change for " << pref_name; |
| 797 } |
| 798 } |
| 799 |
| 799 void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged() { | 800 void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged() { |
| 800 const char* pref_value = NULL; | 801 const char* pref_value = NULL; |
| 801 // TODO(oshima): Support multiple displays. | 802 // TODO(oshima): Support multiple displays. |
| 802 switch (ash::Shell::GetInstance()->GetShelfAlignment( | 803 switch (ash::Shell::GetInstance()->GetShelfAlignment( |
| 803 ash::Shell::GetPrimaryRootWindow())) { | 804 ash::Shell::GetPrimaryRootWindow())) { |
| 804 case ash::SHELF_ALIGNMENT_BOTTOM: | 805 case ash::SHELF_ALIGNMENT_BOTTOM: |
| 805 pref_value = ash::kShelfAlignmentBottom; | 806 pref_value = ash::kShelfAlignmentBottom; |
| 806 break; | 807 break; |
| 807 case ash::SHELF_ALIGNMENT_LEFT: | 808 case ash::SHELF_ALIGNMENT_LEFT: |
| 808 pref_value = ash::kShelfAlignmentLeft; | 809 pref_value = ash::kShelfAlignmentLeft; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 ash::LauncherID id = model_->items()[i].id; | 858 ash::LauncherID id = model_->items()[i].id; |
| 858 if (HasItemController(id) && IsPinned(id)) { | 859 if (HasItemController(id) && IsPinned(id)) { |
| 859 base::DictionaryValue* app_value = ash::CreateAppDict( | 860 base::DictionaryValue* app_value = ash::CreateAppDict( |
| 860 id_to_item_controller_map_[id]->app_id()); | 861 id_to_item_controller_map_[id]->app_id()); |
| 861 if (app_value) | 862 if (app_value) |
| 862 updater->Append(app_value); | 863 updater->Append(app_value); |
| 863 } | 864 } |
| 864 } | 865 } |
| 865 } | 866 } |
| 866 } | 867 } |
| 867 pref_change_registrar_.Add( | 868 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); |
| 868 prefs::kPinnedLauncherApps, | |
| 869 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, | |
| 870 base::Unretained(this))); | |
| 871 } | 869 } |
| 872 | 870 |
| 873 ash::LauncherModel* ChromeLauncherControllerPerApp::model() { | 871 ash::LauncherModel* ChromeLauncherControllerPerApp::model() { |
| 874 return model_; | 872 return model_; |
| 875 } | 873 } |
| 876 | 874 |
| 877 Profile* ChromeLauncherControllerPerApp::profile() { | 875 Profile* ChromeLauncherControllerPerApp::profile() { |
| 878 return profile_; | 876 return profile_; |
| 879 } | 877 } |
| 880 | 878 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( | 1098 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( |
| 1101 AppIconLoader* loader) { | 1099 AppIconLoader* loader) { |
| 1102 app_icon_loader_.reset(loader); | 1100 app_icon_loader_.reset(loader); |
| 1103 } | 1101 } |
| 1104 | 1102 |
| 1105 const std::string& | 1103 const std::string& |
| 1106 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( | 1104 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( |
| 1107 ash::LauncherID id) { | 1105 ash::LauncherID id) { |
| 1108 return id_to_item_controller_map_[id]->app_id(); | 1106 return id_to_item_controller_map_[id]->app_id(); |
| 1109 } | 1107 } |
| OLD | NEW |