| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 // If the value of the pref at |local_path is not empty, it is returned | 121 // If the value of the pref at |local_path is not empty, it is returned |
| 122 // otherwise the value of the pref at |synced_path| is returned. | 122 // otherwise the value of the pref at |synced_path| is returned. |
| 123 std::string GetLocalOrRemotePref(PrefService* pref_service, | 123 std::string GetLocalOrRemotePref(PrefService* pref_service, |
| 124 const char* local_path, | 124 const char* local_path, |
| 125 const char* synced_path) { | 125 const char* synced_path) { |
| 126 const std::string value(pref_service->GetString(local_path)); | 126 const std::string value(pref_service->GetString(local_path)); |
| 127 return value.empty() ? pref_service->GetString(synced_path) : value; | 127 return value.empty() ? pref_service->GetString(synced_path) : value; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // If prefs have synced and the pref value at |local_path| is empty the value | 130 // If prefs have synced and no user-set value exists at |local_path|, the value |
| 131 // from |synced_path| is copied to |local_path|. | 131 // from |synced_path| is copied to |local_path|. |
| 132 void MaybePropagatePrefToLocal(PrefService* pref_service, | 132 void MaybePropagatePrefToLocal(PrefService* pref_service, |
| 133 const char* local_path, | 133 const char* local_path, |
| 134 const char* synced_path) { | 134 const char* synced_path) { |
| 135 if (pref_service->GetString(local_path).empty() && | 135 if (!pref_service->FindPreference(local_path)->HasUserSetting() && |
| 136 pref_service->IsSyncing()) { | 136 pref_service->IsSyncing()) { |
| 137 // First time the user is using this machine, propagate from remote to | 137 // First time the user is using this machine, propagate from remote to |
| 138 // local. | 138 // local. |
| 139 pref_service->SetString(local_path, pref_service->GetString(synced_path)); | 139 pref_service->SetString(local_path, pref_service->GetString(synced_path)); |
| 140 } | 140 } |
| 141 } | 141 } |
| 142 | 142 |
| 143 } // namespace | 143 } // namespace |
| 144 | 144 |
| 145 // ChromeLauncherControllerPerApp --------------------------------------------- | 145 // ChromeLauncherControllerPerApp --------------------------------------------- |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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( |
| 177 prefs::kPinnedLauncherApps, | 177 prefs::kPinnedLauncherApps, |
| 178 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, | 178 base::Bind(&ChromeLauncherControllerPerApp::UpdateAppLaunchersFromPref, |
| 179 base::Unretained(this))); | 179 base::Unretained(this))); |
| 180 pref_change_registrar_.Add( |
| 181 prefs::kShelfAlignmentLocal, |
| 182 base::Bind(&ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs, |
| 183 base::Unretained(this))); |
| 184 pref_change_registrar_.Add( |
| 185 prefs::kShelfAutoHideBehaviorLocal, |
| 186 base::Bind(&ChromeLauncherControllerPerApp:: |
| 187 SetShelfAutoHideBehaviorFromPrefs, |
| 188 base::Unretained(this))); |
| 180 } | 189 } |
| 181 | 190 |
| 182 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { | 191 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { |
| 183 // Reset the shell window controller here since it has a weak pointer to this. | 192 // Reset the shell window controller here since it has a weak pointer to this. |
| 184 shell_window_controller_.reset(); | 193 shell_window_controller_.reset(); |
| 185 | 194 |
| 186 model_->RemoveObserver(this); | 195 model_->RemoveObserver(this); |
| 187 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 196 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
| 188 i != id_to_item_controller_map_.end(); ++i) { | 197 i != id_to_item_controller_map_.end(); ++i) { |
| 189 i->second->OnRemoved(); | 198 i->second->OnRemoved(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 updater.Get()->Clear(); | 232 updater.Get()->Clear(); |
| 224 } | 233 } |
| 225 | 234 |
| 226 UpdateAppLaunchersFromPref(); | 235 UpdateAppLaunchersFromPref(); |
| 227 | 236 |
| 228 // TODO(sky): update unit test so that this test isn't necessary. | 237 // TODO(sky): update unit test so that this test isn't necessary. |
| 229 if (ash::Shell::HasInstance()) { | 238 if (ash::Shell::HasInstance()) { |
| 230 SetShelfAutoHideBehaviorFromPrefs(); | 239 SetShelfAutoHideBehaviorFromPrefs(); |
| 231 SetShelfAlignmentFromPrefs(); | 240 SetShelfAlignmentFromPrefs(); |
| 232 PrefService* prefs = profile_->GetPrefs(); | 241 PrefService* prefs = profile_->GetPrefs(); |
| 233 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || | 242 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || |
| 234 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { | 243 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)-> |
| 244 HasUserSetting()) { |
| 235 // This causes OnIsSyncingChanged to be called when the value of | 245 // This causes OnIsSyncingChanged to be called when the value of |
| 236 // PrefService::IsSyncing() changes. | 246 // PrefService::IsSyncing() changes. |
| 237 prefs->AddObserver(this); | 247 prefs->AddObserver(this); |
| 238 } | 248 } |
| 239 ash::Shell::GetInstance()->AddShellObserver(this); | 249 ash::Shell::GetInstance()->AddShellObserver(this); |
| 240 } | 250 } |
| 241 } | 251 } |
| 242 | 252 |
| 243 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( | 253 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( |
| 244 LauncherItemController* controller, | 254 LauncherItemController* controller, |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() { | 566 void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() { |
| 557 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile()); | 567 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile()); |
| 558 } | 568 } |
| 559 | 569 |
| 560 bool ChromeLauncherControllerPerApp::CanPin() const { | 570 bool ChromeLauncherControllerPerApp::CanPin() const { |
| 561 const PrefService::Preference* pref = | 571 const PrefService::Preference* pref = |
| 562 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); | 572 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); |
| 563 return pref && pref->IsUserModifiable(); | 573 return pref && pref->IsUserModifiable(); |
| 564 } | 574 } |
| 565 | 575 |
| 566 void ChromeLauncherControllerPerApp::SetAutoHideBehavior( | 576 ash::ShelfAutoHideBehavior |
| 567 ash::ShelfAutoHideBehavior behavior, | 577 ChromeLauncherControllerPerApp::GetShelfAutoHideBehavior( |
| 578 aura::RootWindow* root_window) const { |
| 579 // TODO(oshima): Support multiple launchers. |
| 580 |
| 581 // See comment in |kShelfAlignment| as to why we consider two prefs. |
| 582 const std::string behavior_value( |
| 583 GetLocalOrRemotePref(profile_->GetPrefs(), |
| 584 prefs::kShelfAutoHideBehaviorLocal, |
| 585 prefs::kShelfAutoHideBehavior)); |
| 586 |
| 587 // Note: To maintain sync compatibility with old images of chrome/chromeos |
| 588 // the set of values that may be encountered includes the now-extinct |
| 589 // "Default" as well as "Never" and "Always", "Default" should now |
| 590 // be treated as "Never" (http://crbug.com/146773). |
| 591 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) |
| 592 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
| 593 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; |
| 594 } |
| 595 |
| 596 bool ChromeLauncherControllerPerApp::CanUserModifyShelfAutoHideBehavior( |
| 597 aura::RootWindow* root_window) const { |
| 598 // TODO(oshima): Support multiple launchers. |
| 599 return profile_->GetPrefs()-> |
| 600 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); |
| 601 } |
| 602 |
| 603 void ChromeLauncherControllerPerApp::ToggleShelfAutoHideBehavior( |
| 568 aura::RootWindow* root_window) { | 604 aura::RootWindow* root_window) { |
| 569 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( | 605 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == |
| 570 behavior, | 606 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? |
| 571 root_window); | 607 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : |
| 572 // TODO(oshima): Support multiple launcher. | 608 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
| 573 if (root_window != ash::Shell::GetPrimaryRootWindow()) | 609 SetShelfAutoHideBehaviorPrefs(behavior, root_window); |
| 574 return; | 610 return; |
| 575 | |
| 576 const char* value = NULL; | |
| 577 switch (behavior) { | |
| 578 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | |
| 579 value = ash::kShelfAutoHideBehaviorAlways; | |
| 580 break; | |
| 581 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | |
| 582 value = ash::kShelfAutoHideBehaviorNever; | |
| 583 break; | |
| 584 } | |
| 585 // See comment in |kShelfAlignment| about why we have two prefs here. | |
| 586 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); | |
| 587 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); | |
| 588 } | 611 } |
| 589 | 612 |
| 590 void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( | 613 void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( |
| 591 TabContents* tab, | 614 TabContents* tab, |
| 592 const std::string& app_id) { | 615 const std::string& app_id) { |
| 593 tab_contents_to_app_id_.erase(tab); | 616 tab_contents_to_app_id_.erase(tab); |
| 594 AppIDToTabContentsListMap::iterator i_app_id = | 617 AppIDToTabContentsListMap::iterator i_app_id = |
| 595 app_id_to_tab_contents_list_.find(app_id); | 618 app_id_to_tab_contents_list_.find(app_id); |
| 596 if (i_app_id != app_id_to_tab_contents_list_.end()) { | 619 if (i_app_id != app_id_to_tab_contents_list_.end()) { |
| 597 TabContentsList* tab_list = &i_app_id->second; | 620 TabContentsList* tab_list = &i_app_id->second; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 LauncherItemClosed(item.id); | 997 LauncherItemClosed(item.id); |
| 975 else | 998 else |
| 976 ++index; | 999 ++index; |
| 977 } | 1000 } |
| 978 | 1001 |
| 979 // Append unprocessed items from the pref to the end of the model. | 1002 // Append unprocessed items from the pref to the end of the model. |
| 980 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) | 1003 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) |
| 981 DoPinAppWithID(*pref_app_id); | 1004 DoPinAppWithID(*pref_app_id); |
| 982 } | 1005 } |
| 983 | 1006 |
| 1007 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorPrefs( |
| 1008 ash::ShelfAutoHideBehavior behavior, |
| 1009 aura::RootWindow* root_window) { |
| 1010 // TODO(oshima): Support multiple launchers. |
| 1011 if (root_window != ash::Shell::GetPrimaryRootWindow()) |
| 1012 return; |
| 1013 |
| 1014 const char* value = NULL; |
| 1015 switch (behavior) { |
| 1016 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 1017 value = ash::kShelfAutoHideBehaviorAlways; |
| 1018 break; |
| 1019 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| 1020 value = ash::kShelfAutoHideBehaviorNever; |
| 1021 break; |
| 1022 } |
| 1023 // See comment in |kShelfAlignment| about why we have two prefs here. |
| 1024 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); |
| 1025 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); |
| 1026 } |
| 1027 |
| 984 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { | 1028 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { |
| 985 // See comment in |kShelfAlignment| as to why we consider two prefs. | |
| 986 const std::string behavior_value( | |
| 987 GetLocalOrRemotePref(profile_->GetPrefs(), | |
| 988 prefs::kShelfAutoHideBehaviorLocal, | |
| 989 prefs::kShelfAutoHideBehavior)); | |
| 990 | |
| 991 // Note: To maintain sync compatibility with old images of chrome/chromeos | |
| 992 // the set of values that may be encountered includes the now-extinct | |
| 993 // "Default" as well as "Never" and "Always", "Default" should now | |
| 994 // be treated as "Never". | |
| 995 // (http://code.google.com/p/chromium/issues/detail?id=146773) | |
| 996 ash::ShelfAutoHideBehavior behavior = | |
| 997 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; | |
| 998 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) | |
| 999 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | |
| 1000 // TODO(oshima): Support multiple displays. | 1029 // TODO(oshima): Support multiple displays. |
| 1030 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); |
| 1001 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( | 1031 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( |
| 1002 behavior, ash::Shell::GetPrimaryRootWindow()); | 1032 GetShelfAutoHideBehavior(root_window), root_window); |
| 1003 } | 1033 } |
| 1004 | 1034 |
| 1005 void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { | 1035 void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { |
| 1006 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 1036 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 1007 switches::kShowLauncherAlignmentMenu)) | 1037 switches::kShowLauncherAlignmentMenu)) |
| 1008 return; | 1038 return; |
| 1009 | 1039 |
| 1010 // See comment in |kShelfAlignment| as to why we consider two prefs. | 1040 // See comment in |kShelfAlignment| as to why we consider two prefs. |
| 1011 const std::string alignment_value( | 1041 const std::string alignment_value( |
| 1012 GetLocalOrRemotePref(profile_->GetPrefs(), | 1042 GetLocalOrRemotePref(profile_->GetPrefs(), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1092 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( | 1122 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( |
| 1093 AppIconLoader* loader) { | 1123 AppIconLoader* loader) { |
| 1094 app_icon_loader_.reset(loader); | 1124 app_icon_loader_.reset(loader); |
| 1095 } | 1125 } |
| 1096 | 1126 |
| 1097 const std::string& | 1127 const std::string& |
| 1098 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( | 1128 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( |
| 1099 ash::LauncherID id) { | 1129 ash::LauncherID id) { |
| 1100 return id_to_item_controller_map_[id]->app_id(); | 1130 return id_to_item_controller_map_[id]->app_id(); |
| 1101 } | 1131 } |
| OLD | NEW |