| 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(prefs::kPinnedLauncherApps, this); | 176 pref_change_registrar_.Add( |
| 177 prefs::kPinnedLauncherApps, |
| 178 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, |
| 179 base::Unretained(this))); |
| 177 } | 180 } |
| 178 | 181 |
| 179 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { | 182 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { |
| 180 // Reset the shell window controller here since it has a weak pointer to this. | 183 // Reset the shell window controller here since it has a weak pointer to this. |
| 181 shell_window_controller_.reset(); | 184 shell_window_controller_.reset(); |
| 182 | 185 |
| 183 model_->RemoveObserver(this); | 186 model_->RemoveObserver(this); |
| 184 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 187 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
| 185 i != id_to_item_controller_map_.end(); ++i) { | 188 i != id_to_item_controller_map_.end(); ++i) { |
| 186 i->second->OnRemoved(); | 189 i->second->OnRemoved(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 225 |
| 223 UpdateAppLaunchersFromPref(); | 226 UpdateAppLaunchersFromPref(); |
| 224 | 227 |
| 225 // TODO(sky): update unit test so that this test isn't necessary. | 228 // TODO(sky): update unit test so that this test isn't necessary. |
| 226 if (ash::Shell::HasInstance()) { | 229 if (ash::Shell::HasInstance()) { |
| 227 SetShelfAutoHideBehaviorFromPrefs(); | 230 SetShelfAutoHideBehaviorFromPrefs(); |
| 228 SetShelfAlignmentFromPrefs(); | 231 SetShelfAlignmentFromPrefs(); |
| 229 PrefService* prefs = profile_->GetPrefs(); | 232 PrefService* prefs = profile_->GetPrefs(); |
| 230 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || | 233 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || |
| 231 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { | 234 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { |
| 235 // This causes OnIsSyncingChanged to be called when the value of |
| 236 // PrefService::IsSyncing() changes. |
| 232 prefs->AddObserver(this); | 237 prefs->AddObserver(this); |
| 233 } | 238 } |
| 234 ash::Shell::GetInstance()->AddShellObserver(this); | 239 ash::Shell::GetInstance()->AddShellObserver(this); |
| 235 } | 240 } |
| 236 } | 241 } |
| 237 | 242 |
| 238 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( | 243 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( |
| 239 LauncherItemController* controller, | 244 LauncherItemController* controller, |
| 240 IncognitoState is_incognito, | 245 IncognitoState is_incognito, |
| 241 ash::LauncherItemStatus status) { | 246 ash::LauncherItemStatus status) { |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 if (IsAppPinned(extension->id())) | 781 if (IsAppPinned(extension->id())) |
| 777 DoUnpinAppsWithID(extension->id()); | 782 DoUnpinAppsWithID(extension->id()); |
| 778 app_icon_loader_->ClearImage(extension->id()); | 783 app_icon_loader_->ClearImage(extension->id()); |
| 779 break; | 784 break; |
| 780 } | 785 } |
| 781 default: | 786 default: |
| 782 NOTREACHED() << "Unexpected notification type=" << type; | 787 NOTREACHED() << "Unexpected notification type=" << type; |
| 783 } | 788 } |
| 784 } | 789 } |
| 785 | 790 |
| 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 | |
| 800 void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged() { | 791 void ChromeLauncherControllerPerApp::OnShelfAlignmentChanged() { |
| 801 const char* pref_value = NULL; | 792 const char* pref_value = NULL; |
| 802 // TODO(oshima): Support multiple displays. | 793 // TODO(oshima): Support multiple displays. |
| 803 switch (ash::Shell::GetInstance()->GetShelfAlignment( | 794 switch (ash::Shell::GetInstance()->GetShelfAlignment( |
| 804 ash::Shell::GetPrimaryRootWindow())) { | 795 ash::Shell::GetPrimaryRootWindow())) { |
| 805 case ash::SHELF_ALIGNMENT_BOTTOM: | 796 case ash::SHELF_ALIGNMENT_BOTTOM: |
| 806 pref_value = ash::kShelfAlignmentBottom; | 797 pref_value = ash::kShelfAlignmentBottom; |
| 807 break; | 798 break; |
| 808 case ash::SHELF_ALIGNMENT_LEFT: | 799 case ash::SHELF_ALIGNMENT_LEFT: |
| 809 pref_value = ash::kShelfAlignmentLeft; | 800 pref_value = ash::kShelfAlignmentLeft; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 ash::LauncherID id = model_->items()[i].id; | 849 ash::LauncherID id = model_->items()[i].id; |
| 859 if (HasItemController(id) && IsPinned(id)) { | 850 if (HasItemController(id) && IsPinned(id)) { |
| 860 base::DictionaryValue* app_value = ash::CreateAppDict( | 851 base::DictionaryValue* app_value = ash::CreateAppDict( |
| 861 id_to_item_controller_map_[id]->app_id()); | 852 id_to_item_controller_map_[id]->app_id()); |
| 862 if (app_value) | 853 if (app_value) |
| 863 updater->Append(app_value); | 854 updater->Append(app_value); |
| 864 } | 855 } |
| 865 } | 856 } |
| 866 } | 857 } |
| 867 } | 858 } |
| 868 pref_change_registrar_.Add(prefs::kPinnedLauncherApps, this); | 859 pref_change_registrar_.Add( |
| 860 prefs::kPinnedLauncherApps, |
| 861 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, |
| 862 base::Unretained(this))); |
| 869 } | 863 } |
| 870 | 864 |
| 871 ash::LauncherModel* ChromeLauncherControllerPerApp::model() { | 865 ash::LauncherModel* ChromeLauncherControllerPerApp::model() { |
| 872 return model_; | 866 return model_; |
| 873 } | 867 } |
| 874 | 868 |
| 875 Profile* ChromeLauncherControllerPerApp::profile() { | 869 Profile* ChromeLauncherControllerPerApp::profile() { |
| 876 return profile_; | 870 return profile_; |
| 877 } | 871 } |
| 878 | 872 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( | 1092 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( |
| 1099 AppIconLoader* loader) { | 1093 AppIconLoader* loader) { |
| 1100 app_icon_loader_.reset(loader); | 1094 app_icon_loader_.reset(loader); |
| 1101 } | 1095 } |
| 1102 | 1096 |
| 1103 const std::string& | 1097 const std::string& |
| 1104 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( | 1098 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( |
| 1105 ash::LauncherID id) { | 1099 ash::LauncherID id) { |
| 1106 return id_to_item_controller_map_[id]->app_id(); | 1100 return id_to_item_controller_map_[id]->app_id(); |
| 1107 } | 1101 } |
| OLD | NEW |