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 21 matching lines...) Expand all Loading... |
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(prefs::kPinnedLauncherApps, this); |
| 177 pref_change_registrar_.Add(prefs::kShelfAlignmentLocal, this); |
| 178 pref_change_registrar_.Add(prefs::kShelfAutoHideBehaviorLocal, this); |
177 } | 179 } |
178 | 180 |
179 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { | 181 ChromeLauncherControllerPerApp::~ChromeLauncherControllerPerApp() { |
180 // Reset the shell window controller here since it has a weak pointer to this. | 182 // Reset the shell window controller here since it has a weak pointer to this. |
181 shell_window_controller_.reset(); | 183 shell_window_controller_.reset(); |
182 | 184 |
183 model_->RemoveObserver(this); | 185 model_->RemoveObserver(this); |
184 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); | 186 for (IDToItemControllerMap::iterator i = id_to_item_controller_map_.begin(); |
185 i != id_to_item_controller_map_.end(); ++i) { | 187 i != id_to_item_controller_map_.end(); ++i) { |
186 i->second->OnRemoved(); | 188 i->second->OnRemoved(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 updater.Get()->Clear(); | 222 updater.Get()->Clear(); |
221 } | 223 } |
222 | 224 |
223 UpdateAppLaunchersFromPref(); | 225 UpdateAppLaunchersFromPref(); |
224 | 226 |
225 // 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. |
226 if (ash::Shell::HasInstance()) { | 228 if (ash::Shell::HasInstance()) { |
227 SetShelfAutoHideBehaviorFromPrefs(); | 229 SetShelfAutoHideBehaviorFromPrefs(); |
228 SetShelfAlignmentFromPrefs(); | 230 SetShelfAlignmentFromPrefs(); |
229 PrefService* prefs = profile_->GetPrefs(); | 231 PrefService* prefs = profile_->GetPrefs(); |
230 if (prefs->GetString(prefs::kShelfAlignmentLocal).empty() || | 232 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || |
231 prefs->GetString(prefs::kShelfAutoHideBehaviorLocal).empty()) { | 233 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal)-> |
| 234 HasUserSetting()) { |
232 prefs->AddObserver(this); | 235 prefs->AddObserver(this); |
233 } | 236 } |
234 ash::Shell::GetInstance()->AddShellObserver(this); | 237 ash::Shell::GetInstance()->AddShellObserver(this); |
235 } | 238 } |
236 } | 239 } |
237 | 240 |
238 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( | 241 ash::LauncherID ChromeLauncherControllerPerApp::CreateTabbedLauncherItem( |
239 LauncherItemController* controller, | 242 LauncherItemController* controller, |
240 IncognitoState is_incognito, | 243 IncognitoState is_incognito, |
241 ash::LauncherItemStatus status) { | 244 ash::LauncherItemStatus status) { |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() { | 554 void ChromeLauncherControllerPerApp::CreateNewIncognitoWindow() { |
552 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile()); | 555 chrome::NewEmptyWindow(GetProfileForNewWindows()->GetOffTheRecordProfile()); |
553 } | 556 } |
554 | 557 |
555 bool ChromeLauncherControllerPerApp::CanPin() const { | 558 bool ChromeLauncherControllerPerApp::CanPin() const { |
556 const PrefService::Preference* pref = | 559 const PrefService::Preference* pref = |
557 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); | 560 profile_->GetPrefs()->FindPreference(prefs::kPinnedLauncherApps); |
558 return pref && pref->IsUserModifiable(); | 561 return pref && pref->IsUserModifiable(); |
559 } | 562 } |
560 | 563 |
561 void ChromeLauncherControllerPerApp::SetAutoHideBehavior( | 564 ash::ShelfAutoHideBehavior |
562 ash::ShelfAutoHideBehavior behavior, | 565 ChromeLauncherControllerPerApp::GetShelfAutoHideBehavior( |
| 566 aura::RootWindow* root_window) const { |
| 567 // TODO(oshima): Support multiple launchers. |
| 568 |
| 569 // See comment in |kShelfAlignment| as to why we consider two prefs. |
| 570 const std::string behavior_value( |
| 571 GetLocalOrRemotePref(profile_->GetPrefs(), |
| 572 prefs::kShelfAutoHideBehaviorLocal, |
| 573 prefs::kShelfAutoHideBehavior)); |
| 574 |
| 575 // Note: To maintain sync compatibility with old images of chrome/chromeos |
| 576 // the set of values that may be encountered includes the now-extinct |
| 577 // "Default" as well as "Never" and "Always", "Default" should now |
| 578 // be treated as "Never" (http://crbug.com/146773). |
| 579 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) |
| 580 return ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
| 581 return ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; |
| 582 } |
| 583 |
| 584 bool ChromeLauncherControllerPerApp::CanUserModifyShelfAutoHideBehavior( |
| 585 aura::RootWindow* root_window) const { |
| 586 // TODO(oshima): Support multiple launchers. |
| 587 return profile_->GetPrefs()-> |
| 588 FindPreference(prefs::kShelfAutoHideBehaviorLocal)->IsUserModifiable(); |
| 589 } |
| 590 |
| 591 void ChromeLauncherControllerPerApp::ToggleShelfAutoHideBehavior( |
563 aura::RootWindow* root_window) { | 592 aura::RootWindow* root_window) { |
564 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( | 593 ash::ShelfAutoHideBehavior behavior = GetShelfAutoHideBehavior(root_window) == |
565 behavior, | 594 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS ? |
566 root_window); | 595 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER : |
567 // TODO(oshima): Support multiple launcher. | 596 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
568 if (root_window != ash::Shell::GetPrimaryRootWindow()) | 597 SetShelfAutoHideBehaviorPrefs(behavior, root_window); |
569 return; | 598 return; |
570 | |
571 const char* value = NULL; | |
572 switch (behavior) { | |
573 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | |
574 value = ash::kShelfAutoHideBehaviorAlways; | |
575 break; | |
576 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | |
577 value = ash::kShelfAutoHideBehaviorNever; | |
578 break; | |
579 } | |
580 // See comment in |kShelfAlignment| about why we have two prefs here. | |
581 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); | |
582 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); | |
583 } | 599 } |
584 | 600 |
585 void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( | 601 void ChromeLauncherControllerPerApp::RemoveTabFromRunningApp( |
586 TabContents* tab, | 602 TabContents* tab, |
587 const std::string& app_id) { | 603 const std::string& app_id) { |
588 tab_contents_to_app_id_.erase(tab); | 604 tab_contents_to_app_id_.erase(tab); |
589 AppIDToTabContentsListMap::iterator i_app_id = | 605 AppIDToTabContentsListMap::iterator i_app_id = |
590 app_id_to_tab_contents_list_.find(app_id); | 606 app_id_to_tab_contents_list_.find(app_id); |
591 if (i_app_id != app_id_to_tab_contents_list_.end()) { | 607 if (i_app_id != app_id_to_tab_contents_list_.end()) { |
592 TabContentsList* tab_list = &i_app_id->second; | 608 TabContentsList* tab_list = &i_app_id->second; |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
980 LauncherItemClosed(item.id); | 996 LauncherItemClosed(item.id); |
981 else | 997 else |
982 ++index; | 998 ++index; |
983 } | 999 } |
984 | 1000 |
985 // Append unprocessed items from the pref to the end of the model. | 1001 // Append unprocessed items from the pref to the end of the model. |
986 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) | 1002 for (; pref_app_id != pinned_apps.end(); ++pref_app_id) |
987 DoPinAppWithID(*pref_app_id); | 1003 DoPinAppWithID(*pref_app_id); |
988 } | 1004 } |
989 | 1005 |
| 1006 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorPrefs( |
| 1007 ash::ShelfAutoHideBehavior behavior, |
| 1008 aura::RootWindow* root_window) { |
| 1009 // TODO(oshima): Support multiple launchers. |
| 1010 if (root_window != ash::Shell::GetPrimaryRootWindow()) |
| 1011 return; |
| 1012 |
| 1013 const char* value = NULL; |
| 1014 switch (behavior) { |
| 1015 case ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 1016 value = ash::kShelfAutoHideBehaviorAlways; |
| 1017 break; |
| 1018 case ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| 1019 value = ash::kShelfAutoHideBehaviorNever; |
| 1020 break; |
| 1021 } |
| 1022 // See comment in |kShelfAlignment| about why we have two prefs here. |
| 1023 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehaviorLocal, value); |
| 1024 profile_->GetPrefs()->SetString(prefs::kShelfAutoHideBehavior, value); |
| 1025 } |
| 1026 |
990 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { | 1027 void ChromeLauncherControllerPerApp::SetShelfAutoHideBehaviorFromPrefs() { |
991 // See comment in |kShelfAlignment| as to why we consider two prefs. | |
992 const std::string behavior_value( | |
993 GetLocalOrRemotePref(profile_->GetPrefs(), | |
994 prefs::kShelfAutoHideBehaviorLocal, | |
995 prefs::kShelfAutoHideBehavior)); | |
996 | |
997 // Note: To maintain sync compatibility with old images of chrome/chromeos | |
998 // the set of values that may be encountered includes the now-extinct | |
999 // "Default" as well as "Never" and "Always", "Default" should now | |
1000 // be treated as "Never". | |
1001 // (http://code.google.com/p/chromium/issues/detail?id=146773) | |
1002 ash::ShelfAutoHideBehavior behavior = | |
1003 ash::SHELF_AUTO_HIDE_BEHAVIOR_NEVER; | |
1004 if (behavior_value == ash::kShelfAutoHideBehaviorAlways) | |
1005 behavior = ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | |
1006 // TODO(oshima): Support multiple displays. | 1028 // TODO(oshima): Support multiple displays. |
| 1029 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow(); |
1007 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( | 1030 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( |
1008 behavior, ash::Shell::GetPrimaryRootWindow()); | 1031 GetShelfAutoHideBehavior(root_window), root_window); |
1009 } | 1032 } |
1010 | 1033 |
1011 void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { | 1034 void ChromeLauncherControllerPerApp::SetShelfAlignmentFromPrefs() { |
1012 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 1035 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
1013 switches::kShowLauncherAlignmentMenu)) | 1036 switches::kShowLauncherAlignmentMenu)) |
1014 return; | 1037 return; |
1015 | 1038 |
1016 // See comment in |kShelfAlignment| as to why we consider two prefs. | 1039 // See comment in |kShelfAlignment| as to why we consider two prefs. |
1017 const std::string alignment_value( | 1040 const std::string alignment_value( |
1018 GetLocalOrRemotePref(profile_->GetPrefs(), | 1041 GetLocalOrRemotePref(profile_->GetPrefs(), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( | 1121 void ChromeLauncherControllerPerApp::SetAppIconLoaderForTest( |
1099 AppIconLoader* loader) { | 1122 AppIconLoader* loader) { |
1100 app_icon_loader_.reset(loader); | 1123 app_icon_loader_.reset(loader); |
1101 } | 1124 } |
1102 | 1125 |
1103 const std::string& | 1126 const std::string& |
1104 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( | 1127 ChromeLauncherControllerPerApp::GetAppIdFromLauncherIdForTest( |
1105 ash::LauncherID id) { | 1128 ash::LauncherID id) { |
1106 return id_to_item_controller_map_[id]->app_id(); | 1129 return id_to_item_controller_map_[id]->app_id(); |
1107 } | 1130 } |
OLD | NEW |