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