| 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/chrome_launcher_prefs.h" | 5 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/app_mode/app_mode_utils.h" | 15 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 16 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 17 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 18 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 18 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" | 19 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" |
| 20 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" | 20 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h" |
| 21 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | 21 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
| 22 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 22 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "components/pref_registry/pref_registry_syncable.h" | 25 #include "components/pref_registry/pref_registry_syncable.h" |
| 26 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "components/prefs/scoped_user_pref_update.h" | 27 #include "components/prefs/scoped_user_pref_update.h" |
| 28 #include "components/sync/model/string_ordinal.h" | 28 #include "components/sync/model/string_ordinal.h" |
| 29 #include "components/syncable_prefs/pref_service_syncable.h" | 29 #include "components/sync_preferences/pref_service_syncable.h" |
| 30 #include "ui/display/display.h" | 30 #include "ui/display/display.h" |
| 31 #include "ui/display/screen.h" | 31 #include "ui/display/screen.h" |
| 32 | 32 |
| 33 namespace ash { | 33 namespace ash { |
| 34 namespace launcher { | 34 namespace launcher { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // App ID of default pinned apps. | 38 // App ID of default pinned apps. |
| 39 const char* kDefaultPinnedApps[] = { | 39 const char* kDefaultPinnedApps[] = { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (app_info->package_name == package) { | 192 if (app_info->package_name == package) { |
| 193 activities.push_back(app_info->activity); | 193 activities.push_back(app_info->activity); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 return activities; | 196 return activities; |
| 197 } | 197 } |
| 198 | 198 |
| 199 // If no user-set value exists at |local_path|, the value from |synced_path| is | 199 // If no user-set value exists at |local_path|, the value from |synced_path| is |
| 200 // copied to |local_path|. | 200 // copied to |local_path|. |
| 201 void PropagatePrefToLocalIfNotSet( | 201 void PropagatePrefToLocalIfNotSet( |
| 202 syncable_prefs::PrefServiceSyncable* pref_service, | 202 sync_preferences::PrefServiceSyncable* pref_service, |
| 203 const char* local_path, | 203 const char* local_path, |
| 204 const char* synced_path) { | 204 const char* synced_path) { |
| 205 if (!pref_service->FindPreference(local_path)->HasUserSetting()) | 205 if (!pref_service->FindPreference(local_path)->HasUserSetting()) |
| 206 pref_service->SetString(local_path, pref_service->GetString(synced_path)); | 206 pref_service->SetString(local_path, pref_service->GetString(synced_path)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 struct PinInfo { | 209 struct PinInfo { |
| 210 PinInfo(const AppLauncherId& app_launcher_id, | 210 PinInfo(const AppLauncherId& app_launcher_id, |
| 211 const syncer::StringOrdinal& item_ordinal) | 211 const syncer::StringOrdinal& item_ordinal) |
| 212 : app_launcher_id(app_launcher_id), item_ordinal(item_ordinal) {} | 212 : app_launcher_id(app_launcher_id), item_ordinal(item_ordinal) {} |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 478 } |
| 479 | 479 |
| 480 // If not added yet, the chrome item will be the last item in the list. | 480 // If not added yet, the chrome item will be the last item in the list. |
| 481 apps.AddApp(AppLauncherId(extension_misc::kChromeAppId)); | 481 apps.AddApp(AppLauncherId(extension_misc::kChromeAppId)); |
| 482 return apps.app_list(); | 482 return apps.app_list(); |
| 483 } | 483 } |
| 484 | 484 |
| 485 // static | 485 // static |
| 486 std::unique_ptr<ChromeLauncherPrefsObserver> | 486 std::unique_ptr<ChromeLauncherPrefsObserver> |
| 487 ChromeLauncherPrefsObserver::CreateIfNecessary(Profile* profile) { | 487 ChromeLauncherPrefsObserver::CreateIfNecessary(Profile* profile) { |
| 488 syncable_prefs::PrefServiceSyncable* prefs = | 488 sync_preferences::PrefServiceSyncable* prefs = |
| 489 PrefServiceSyncableFromProfile(profile); | 489 PrefServiceSyncableFromProfile(profile); |
| 490 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || | 490 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || |
| 491 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal) | 491 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal) |
| 492 ->HasUserSetting()) { | 492 ->HasUserSetting()) { |
| 493 return base::WrapUnique(new ChromeLauncherPrefsObserver(prefs)); | 493 return base::WrapUnique(new ChromeLauncherPrefsObserver(prefs)); |
| 494 } | 494 } |
| 495 return nullptr; | 495 return nullptr; |
| 496 } | 496 } |
| 497 | 497 |
| 498 ChromeLauncherPrefsObserver::~ChromeLauncherPrefsObserver() { | 498 ChromeLauncherPrefsObserver::~ChromeLauncherPrefsObserver() { |
| 499 prefs_->RemoveObserver(this); | 499 prefs_->RemoveObserver(this); |
| 500 } | 500 } |
| 501 | 501 |
| 502 ChromeLauncherPrefsObserver::ChromeLauncherPrefsObserver( | 502 ChromeLauncherPrefsObserver::ChromeLauncherPrefsObserver( |
| 503 syncable_prefs::PrefServiceSyncable* prefs) | 503 sync_preferences::PrefServiceSyncable* prefs) |
| 504 : prefs_(prefs) { | 504 : prefs_(prefs) { |
| 505 // This causes OnIsSyncingChanged to be called when the value of | 505 // This causes OnIsSyncingChanged to be called when the value of |
| 506 // PrefService::IsSyncing() changes. | 506 // PrefService::IsSyncing() changes. |
| 507 prefs_->AddObserver(this); | 507 prefs_->AddObserver(this); |
| 508 } | 508 } |
| 509 | 509 |
| 510 void ChromeLauncherPrefsObserver::OnIsSyncingChanged() { | 510 void ChromeLauncherPrefsObserver::OnIsSyncingChanged() { |
| 511 // If prefs have synced, copy the values from |synced_path| to |local_path| | 511 // If prefs have synced, copy the values from |synced_path| to |local_path| |
| 512 // if the local values haven't already been set. | 512 // if the local values haven't already been set. |
| 513 if (!prefs_->IsSyncing()) | 513 if (!prefs_->IsSyncing()) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 pin_position = position_before.CreateAfter(); | 739 pin_position = position_before.CreateAfter(); |
| 740 else if (position_after.IsValid()) | 740 else if (position_after.IsValid()) |
| 741 pin_position = position_after.CreateBefore(); | 741 pin_position = position_after.CreateBefore(); |
| 742 else | 742 else |
| 743 pin_position = syncer::StringOrdinal::CreateInitialOrdinal(); | 743 pin_position = syncer::StringOrdinal::CreateInitialOrdinal(); |
| 744 app_service->SetPinPosition(app_launcher_id_str, pin_position); | 744 app_service->SetPinPosition(app_launcher_id_str, pin_position); |
| 745 } | 745 } |
| 746 | 746 |
| 747 } // namespace launcher | 747 } // namespace launcher |
| 748 } // namespace ash | 748 } // namespace ash |
| OLD | NEW |