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 |
(...skipping 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 // App ID of default pinned apps. | 37 // App ID of default pinned apps. |
38 const char* kDefaultPinnedApps[] = { | 38 const char* kDefaultPinnedApps[] = { |
39 extension_misc::kGmailAppId, extension_misc::kGoogleDocAppId, | 39 extension_misc::kGmailAppId, extension_misc::kGoogleDocAppId, |
40 extension_misc::kYoutubeAppId, ArcSupportHost::kHostAppId}; | 40 extension_misc::kYoutubeAppId, ArcSupportHost::kHostAppId}; |
41 | 41 |
42 base::ListValue* CreateDefaultPinnedAppsList() { | 42 base::ListValue* CreateDefaultPinnedAppsList() { |
43 std::unique_ptr<base::ListValue> apps(new base::ListValue); | 43 std::unique_ptr<base::ListValue> apps(new base::ListValue); |
44 for (size_t i = 0; i < arraysize(kDefaultPinnedApps); ++i) | 44 for (size_t i = 0; i < arraysize(kDefaultPinnedApps); ++i) { |
45 apps->Append(CreateAppDict(kDefaultPinnedApps[i])); | 45 AppLauncherId* app_launcher_id = new AppLauncherId(kDefaultPinnedApps[i]); |
46 apps->Append(CreateAppDict(app_launcher_id)); | |
stevenjb
2016/09/21 16:06:40
This is leaky!
Just do:
apps->Append(CreateAppDic
Andra Paraschiv
2016/09/22 09:23:41
Done.
| |
47 } | |
46 | 48 |
47 return apps.release(); | 49 return apps.release(); |
48 } | 50 } |
49 | 51 |
50 // Returns the preference value for the display with the given |display_id|. | 52 // Returns the preference value for the display with the given |display_id|. |
51 // The pref value is stored in |local_path| and |path|, but the pref service may | 53 // The pref value is stored in |local_path| and |path|, but the pref service may |
52 // have per-display preferences and the value can be specified by policy. | 54 // have per-display preferences and the value can be specified by policy. |
53 // Here is the priority: | 55 // Here is the priority: |
54 // * A value managed by policy. This is a single value that applies to all | 56 // * A value managed by policy. This is a single value that applies to all |
55 // displays. | 57 // displays. |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 // copied to |local_path|. | 201 // copied to |local_path|. |
200 void PropagatePrefToLocalIfNotSet( | 202 void PropagatePrefToLocalIfNotSet( |
201 syncable_prefs::PrefServiceSyncable* pref_service, | 203 syncable_prefs::PrefServiceSyncable* pref_service, |
202 const char* local_path, | 204 const char* local_path, |
203 const char* synced_path) { | 205 const char* synced_path) { |
204 if (!pref_service->FindPreference(local_path)->HasUserSetting()) | 206 if (!pref_service->FindPreference(local_path)->HasUserSetting()) |
205 pref_service->SetString(local_path, pref_service->GetString(synced_path)); | 207 pref_service->SetString(local_path, pref_service->GetString(synced_path)); |
206 } | 208 } |
207 | 209 |
208 struct PinInfo { | 210 struct PinInfo { |
209 PinInfo(const std::string& app_id, const syncer::StringOrdinal& item_ordinal) | 211 PinInfo(AppLauncherId* app_launcher_id, |
210 : app_id(app_id), item_ordinal(item_ordinal) {} | 212 const syncer::StringOrdinal& item_ordinal) |
213 : app_launcher_id(app_launcher_id->GetAppLauncherID()), | |
214 item_ordinal(item_ordinal) {} | |
211 | 215 |
212 std::string app_id; | 216 std::string app_launcher_id; |
stevenjb
2016/09/21 16:06:40
This should be an AppLauncherId. Only use the stri
Andra Paraschiv
2016/09/22 09:23:41
If we change it to AppLauncherId, we should add an
stevenjb
2016/09/27 16:42:36
I'm not exactly sure what you are asking, but we s
| |
213 syncer::StringOrdinal item_ordinal; | 217 syncer::StringOrdinal item_ordinal; |
214 }; | 218 }; |
215 | 219 |
216 struct ComparePinInfo { | 220 struct ComparePinInfo { |
217 bool operator()(const PinInfo& pin1, const PinInfo& pin2) { | 221 bool operator()(const PinInfo& pin1, const PinInfo& pin2) { |
218 return pin1.item_ordinal.LessThan(pin2.item_ordinal); | 222 return pin1.item_ordinal.LessThan(pin2.item_ordinal); |
219 } | 223 } |
220 }; | 224 }; |
221 | 225 |
222 // Helper class to keep apps in order of appearance and to provide fast way | 226 // Helper class to keep apps in order of appearance and to provide fast way |
223 // to check if app exists in the list. | 227 // to check if app exists in the list. |
224 class AppTracker { | 228 class AppTracker { |
225 public: | 229 public: |
226 bool HasApp(const std::string& app_id) const { | 230 bool HasApp(AppLauncherId* app_launcher_id) const { |
227 return app_set_.find(app_id) != app_set_.end(); | 231 return app_set_.find(app_launcher_id->GetAppLauncherID()) != app_set_.end(); |
228 } | 232 } |
229 | 233 |
230 void AddApp(const std::string& app_id) { | 234 void AddApp(AppLauncherId* app_launcher_id) { |
231 if (HasApp(app_id)) | 235 if (HasApp(app_launcher_id)) |
232 return; | 236 return; |
233 app_list_.push_back(app_id); | 237 app_list_.push_back(app_launcher_id->GetAppLauncherID()); |
234 app_set_.insert(app_id); | 238 app_set_.insert(app_launcher_id->GetAppLauncherID()); |
235 } | 239 } |
236 | 240 |
237 void MaybeAddApp(const std::string& app_id, | 241 void MaybeAddApp(AppLauncherId* app_launcher_id, |
238 const LauncherControllerHelper* helper) { | 242 const LauncherControllerHelper* helper) { |
239 DCHECK_NE(kPinnedAppsPlaceholder, app_id); | 243 DCHECK_NE(kPinnedAppsPlaceholder, app_launcher_id->GetAppLauncherID()); |
240 if (!helper->IsValidIDForCurrentUser(app_id)) | 244 if (!helper->IsValidIDForCurrentUser(app_launcher_id->GetAppLauncherID())) |
241 return; | 245 return; |
242 AddApp(app_id); | 246 AddApp(app_launcher_id); |
243 } | 247 } |
244 | 248 |
245 void MaybeAddAppFromPref(const base::DictionaryValue* app_pref, | 249 void MaybeAddAppFromPref(const base::DictionaryValue* app_pref, |
246 const LauncherControllerHelper* helper) { | 250 const LauncherControllerHelper* helper) { |
247 std::string app_id; | 251 std::string app_id; |
248 if (!app_pref->GetString(kPinnedAppsPrefAppIDPath, &app_id)) { | 252 if (!app_pref->GetString(kPinnedAppsPrefAppIDPath, &app_id)) { |
249 LOG(ERROR) << "Cannot get app id from app pref entry."; | 253 LOG(ERROR) << "Cannot get app id from app pref entry."; |
250 return; | 254 return; |
251 } | 255 } |
252 | 256 |
253 if (app_id == kPinnedAppsPlaceholder) | 257 if (app_id == kPinnedAppsPlaceholder) |
254 return; | 258 return; |
255 | 259 |
256 bool pinned_by_policy = false; | 260 bool pinned_by_policy = false; |
257 if (app_pref->GetBoolean(kPinnedAppsPrefPinnedByPolicy, | 261 if (app_pref->GetBoolean(kPinnedAppsPrefPinnedByPolicy, |
258 &pinned_by_policy) && | 262 &pinned_by_policy) && |
259 pinned_by_policy) { | 263 pinned_by_policy) { |
260 return; | 264 return; |
261 } | 265 } |
262 | 266 |
263 MaybeAddApp(app_id, helper); | 267 AppLauncherId* app_launcher_id = new AppLauncherId(app_id); |
268 MaybeAddApp(app_launcher_id, helper); | |
264 } | 269 } |
265 | 270 |
266 const std::vector<std::string>& app_list() const { return app_list_; } | 271 const std::vector<std::string>& app_list() const { return app_list_; } |
267 | 272 |
268 private: | 273 private: |
269 std::vector<std::string> app_list_; | 274 std::vector<std::string> app_list_; |
270 std::set<std::string> app_set_; | 275 std::set<std::string> app_set_; |
271 }; | 276 }; |
272 | 277 |
273 } // namespace | 278 } // namespace |
(...skipping 28 matching lines...) Expand all Loading... | |
302 std::string()); | 307 std::string()); |
303 registry->RegisterStringPref(prefs::kShelfAlignment, | 308 registry->RegisterStringPref(prefs::kShelfAlignment, |
304 kShelfAlignmentBottom, | 309 kShelfAlignmentBottom, |
305 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 310 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
306 registry->RegisterStringPref(prefs::kShelfAlignmentLocal, std::string()); | 311 registry->RegisterStringPref(prefs::kShelfAlignmentLocal, std::string()); |
307 registry->RegisterDictionaryPref(prefs::kShelfPreferences); | 312 registry->RegisterDictionaryPref(prefs::kShelfPreferences); |
308 registry->RegisterIntegerPref(prefs::kLogoutDialogDurationMs, 20000); | 313 registry->RegisterIntegerPref(prefs::kLogoutDialogDurationMs, 20000); |
309 registry->RegisterBooleanPref(prefs::kShowLogoutButtonInTray, false); | 314 registry->RegisterBooleanPref(prefs::kShowLogoutButtonInTray, false); |
310 } | 315 } |
311 | 316 |
312 base::DictionaryValue* CreateAppDict(const std::string& app_id) { | 317 base::DictionaryValue* CreateAppDict(AppLauncherId* app_launcher_id) { |
313 std::unique_ptr<base::DictionaryValue> app_value(new base::DictionaryValue); | 318 std::unique_ptr<base::DictionaryValue> app_value(new base::DictionaryValue); |
314 app_value->SetString(kPinnedAppsPrefAppIDPath, app_id); | 319 app_value->SetString(kPinnedAppsPrefAppIDPath, |
320 app_launcher_id->GetAppLauncherID()); | |
315 return app_value.release(); | 321 return app_value.release(); |
316 } | 322 } |
317 | 323 |
318 ShelfAutoHideBehavior GetShelfAutoHideBehaviorPref(PrefService* prefs, | 324 ShelfAutoHideBehavior GetShelfAutoHideBehaviorPref(PrefService* prefs, |
319 int64_t display_id) { | 325 int64_t display_id) { |
320 DCHECK_GE(display_id, 0); | 326 DCHECK_GE(display_id, 0); |
321 | 327 |
322 // Don't show the shelf in app mode. | 328 // Don't show the shelf in app mode. |
323 if (chrome::IsRunningInAppMode()) | 329 if (chrome::IsRunningInAppMode()) |
324 return SHELF_AUTO_HIDE_ALWAYS_HIDDEN; | 330 return SHELF_AUTO_HIDE_ALWAYS_HIDDEN; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 if (!arc_app_list_pref) | 407 if (!arc_app_list_pref) |
402 continue; | 408 continue; |
403 | 409 |
404 // We are dealing with package name, not with 32 characters ID. | 410 // We are dealing with package name, not with 32 characters ID. |
405 const std::string& arc_package = app_id; | 411 const std::string& arc_package = app_id; |
406 const std::vector<std::string> activities = GetActivitiesForPackage( | 412 const std::vector<std::string> activities = GetActivitiesForPackage( |
407 arc_package, all_arc_app_ids, *arc_app_list_pref); | 413 arc_package, all_arc_app_ids, *arc_app_list_pref); |
408 for (const auto& activity : activities) { | 414 for (const auto& activity : activities) { |
409 const std::string arc_app_id = | 415 const std::string arc_app_id = |
410 ArcAppListPrefs::GetAppId(arc_package, activity); | 416 ArcAppListPrefs::GetAppId(arc_package, activity); |
411 apps->MaybeAddApp(arc_app_id, helper); | 417 AppLauncherId* app_launcher_id = new AppLauncherId(arc_app_id); |
418 apps->MaybeAddApp(app_launcher_id, helper); | |
412 } | 419 } |
413 } else { | 420 } else { |
414 apps->MaybeAddApp(app_id, helper); | 421 AppLauncherId* app_launcher_id = new AppLauncherId(app_id); |
422 apps->MaybeAddApp(app_launcher_id, helper); | |
415 } | 423 } |
416 } | 424 } |
417 } | 425 } |
418 | 426 |
419 std::vector<std::string> GetPinnedAppsFromPrefsLegacy( | 427 std::vector<std::string> GetPinnedAppsFromPrefsLegacy( |
420 const PrefService* prefs, | 428 const PrefService* prefs, |
421 const LauncherControllerHelper* helper) { | 429 const LauncherControllerHelper* helper) { |
422 // Adding the app list item to the list of items requires that the ID is not | 430 // Adding the app list item to the list of items requires that the ID is not |
423 // a valid and known ID for the extension system. The ID was constructed that | 431 // a valid and known ID for the extension system. The ID was constructed that |
424 // way - but just to make sure... | 432 // way - but just to make sure... |
425 DCHECK(!helper->IsValidIDForCurrentUser(kPinnedAppsPlaceholder)); | 433 DCHECK(!helper->IsValidIDForCurrentUser(kPinnedAppsPlaceholder)); |
426 | 434 |
427 const auto* pinned_apps = prefs->GetList(prefs::kPinnedLauncherApps); | 435 const auto* pinned_apps = prefs->GetList(prefs::kPinnedLauncherApps); |
428 | 436 |
429 // Get the sanitized preference value for the index of the Chrome app icon. | 437 // Get the sanitized preference value for the index of the Chrome app icon. |
430 const size_t chrome_icon_index = std::max<size_t>( | 438 const size_t chrome_icon_index = std::max<size_t>( |
431 0, std::min<size_t>(pinned_apps->GetSize(), | 439 0, std::min<size_t>(pinned_apps->GetSize(), |
432 prefs->GetInteger(prefs::kShelfChromeIconIndex))); | 440 prefs->GetInteger(prefs::kShelfChromeIconIndex))); |
433 | 441 |
434 // Check if Chrome is in either of the the preferences lists. | 442 // Check if Chrome is in either of the the preferences lists. |
443 AppLauncherId* chrome_app_launcher_id = | |
444 new AppLauncherId(extension_misc::kChromeAppId); | |
435 std::unique_ptr<base::Value> chrome_app( | 445 std::unique_ptr<base::Value> chrome_app( |
436 CreateAppDict(extension_misc::kChromeAppId)); | 446 CreateAppDict(chrome_app_launcher_id)); |
437 | 447 |
438 AppTracker apps; | 448 AppTracker apps; |
439 GetAppsPinnedByPolicy(prefs, helper, &apps); | 449 GetAppsPinnedByPolicy(prefs, helper, &apps); |
440 | 450 |
441 std::string app_id; | 451 std::string app_id; |
442 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) { | 452 for (size_t i = 0; i < pinned_apps->GetSize(); ++i) { |
443 // We need to position the chrome icon relative to its place in the pinned | 453 // We need to position the chrome icon relative to its place in the pinned |
444 // preference list - even if an item of that list isn't shown yet. | 454 // preference list - even if an item of that list isn't shown yet. |
445 if (i == chrome_icon_index) | 455 if (i == chrome_icon_index) { |
446 apps.AddApp(extension_misc::kChromeAppId); | 456 AppLauncherId* chrome_app_launcher_id = |
457 new AppLauncherId(extension_misc::kChromeAppId); | |
458 apps.AddApp(chrome_app_launcher_id); | |
459 } | |
447 const base::DictionaryValue* app_pref = nullptr; | 460 const base::DictionaryValue* app_pref = nullptr; |
448 if (!pinned_apps->GetDictionary(i, &app_pref)) { | 461 if (!pinned_apps->GetDictionary(i, &app_pref)) { |
449 LOG(ERROR) << "There is no dictionary for app entry."; | 462 LOG(ERROR) << "There is no dictionary for app entry."; |
450 continue; | 463 continue; |
451 } | 464 } |
452 apps.MaybeAddAppFromPref(app_pref, helper); | 465 apps.MaybeAddAppFromPref(app_pref, helper); |
453 } | 466 } |
454 | 467 |
455 // If not added yet, the chrome item will be the last item in the list. | 468 // If not added yet, the chrome item will be the last item in the list. |
456 apps.AddApp(extension_misc::kChromeAppId); | 469 apps.AddApp(chrome_app_launcher_id); |
457 return apps.app_list(); | 470 return apps.app_list(); |
458 } | 471 } |
459 | 472 |
460 // static | 473 // static |
461 std::unique_ptr<ChromeLauncherPrefsObserver> | 474 std::unique_ptr<ChromeLauncherPrefsObserver> |
462 ChromeLauncherPrefsObserver::CreateIfNecessary(Profile* profile) { | 475 ChromeLauncherPrefsObserver::CreateIfNecessary(Profile* profile) { |
463 syncable_prefs::PrefServiceSyncable* prefs = | 476 syncable_prefs::PrefServiceSyncable* prefs = |
464 PrefServiceSyncableFromProfile(profile); | 477 PrefServiceSyncableFromProfile(profile); |
465 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || | 478 if (!prefs->FindPreference(prefs::kShelfAlignmentLocal)->HasUserSetting() || |
466 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal) | 479 !prefs->FindPreference(prefs::kShelfAutoHideBehaviorLocal) |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 if (!sync_peer.second->item_pin_ordinal.IsValid()) | 603 if (!sync_peer.second->item_pin_ordinal.IsValid()) |
591 continue; | 604 continue; |
592 | 605 |
593 first_run = false; | 606 first_run = false; |
594 // Don't include apps that currently do not exist on device. | 607 // Don't include apps that currently do not exist on device. |
595 if (sync_peer.first != extension_misc::kChromeAppId && | 608 if (sync_peer.first != extension_misc::kChromeAppId && |
596 !helper->IsValidIDForCurrentUser(sync_peer.first)) { | 609 !helper->IsValidIDForCurrentUser(sync_peer.first)) { |
597 continue; | 610 continue; |
598 } | 611 } |
599 | 612 |
613 AppLauncherId* app_launcher_id = new AppLauncherId(sync_peer.first); | |
600 pin_infos.push_back( | 614 pin_infos.push_back( |
601 PinInfo(sync_peer.first, sync_peer.second->item_pin_ordinal)); | 615 PinInfo(app_launcher_id, sync_peer.second->item_pin_ordinal)); |
602 } | 616 } |
603 | 617 |
604 if (first_run) { | 618 if (first_run) { |
605 // We need to import legacy pins model and convert it to sync based | 619 // We need to import legacy pins model and convert it to sync based |
606 // model. | 620 // model. |
607 return ImportLegacyPinnedApps(prefs, helper, policy_apps); | 621 return ImportLegacyPinnedApps(prefs, helper, policy_apps); |
608 } | 622 } |
609 | 623 |
610 // Sort pins according their ordinals. | 624 // Sort pins according their ordinals. |
611 std::sort(pin_infos.begin(), pin_infos.end(), ComparePinInfo()); | 625 std::sort(pin_infos.begin(), pin_infos.end(), ComparePinInfo()); |
612 | 626 |
613 // Pinned by policy apps appear first, if they were not shown before. | 627 // Pinned by policy apps appear first, if they were not shown before. |
614 syncer::StringOrdinal front_position = GetFirstPinPosition(helper->profile()); | 628 syncer::StringOrdinal front_position = GetFirstPinPosition(helper->profile()); |
615 std::vector<std::string>::const_reverse_iterator it; | 629 std::vector<std::string>::const_reverse_iterator it; |
616 for (it = policy_apps.app_list().rbegin(); | 630 for (it = policy_apps.app_list().rbegin(); |
617 it != policy_apps.app_list().rend(); ++it) { | 631 it != policy_apps.app_list().rend(); ++it) { |
618 const std::string& app_id = *it; | 632 const std::string& app_id = *it; |
619 if (app_id == kPinnedAppsPlaceholder) | 633 if (app_id == kPinnedAppsPlaceholder) |
620 continue; | 634 continue; |
621 | 635 |
622 // Check if we already processed current app. | 636 // Check if we already processed current app. |
623 if (app_service->GetPinPosition(app_id).IsValid()) | 637 if (app_service->GetPinPosition(app_id).IsValid()) |
624 continue; | 638 continue; |
625 | 639 |
626 // Now move it to the front. | 640 // Now move it to the front. |
627 pin_infos.insert(pin_infos.begin(), PinInfo(app_id, front_position)); | 641 AppLauncherId* app_launcher_id = new AppLauncherId(app_id); |
642 pin_infos.insert(pin_infos.begin(), | |
643 PinInfo(app_launcher_id, front_position)); | |
628 app_service->SetPinPosition(app_id, front_position); | 644 app_service->SetPinPosition(app_id, front_position); |
629 front_position = front_position.CreateBefore(); | 645 front_position = front_position.CreateBefore(); |
630 } | 646 } |
631 | 647 |
632 // Now insert Chrome browser app if needed. | 648 // Now insert Chrome browser app if needed. |
633 if (!app_service->GetPinPosition(extension_misc::kChromeAppId).IsValid()) { | 649 if (!app_service->GetPinPosition(extension_misc::kChromeAppId).IsValid()) { |
650 AppLauncherId* chrome_app_launcher_id = | |
651 new AppLauncherId(extension_misc::kChromeAppId); | |
634 pin_infos.insert(pin_infos.begin(), | 652 pin_infos.insert(pin_infos.begin(), |
635 PinInfo(extension_misc::kChromeAppId, front_position)); | 653 PinInfo(chrome_app_launcher_id, front_position)); |
636 app_service->SetPinPosition(extension_misc::kChromeAppId, front_position); | 654 app_service->SetPinPosition(extension_misc::kChromeAppId, front_position); |
637 } | 655 } |
638 | 656 |
639 if (helper->IsValidIDForCurrentUser(ArcSupportHost::kHostAppId)) { | 657 if (helper->IsValidIDForCurrentUser(ArcSupportHost::kHostAppId)) { |
640 if (!app_service->GetSyncItem(ArcSupportHost::kHostAppId)) { | 658 if (!app_service->GetSyncItem(ArcSupportHost::kHostAppId)) { |
641 const syncer::StringOrdinal arc_host_position = | 659 const syncer::StringOrdinal arc_host_position = |
642 GetLastPinPosition(helper->profile()); | 660 GetLastPinPosition(helper->profile()); |
661 AppLauncherId* app_launcher_id = | |
662 new AppLauncherId(ArcSupportHost::kHostAppId); | |
643 pin_infos.insert(pin_infos.begin(), | 663 pin_infos.insert(pin_infos.begin(), |
644 PinInfo(ArcSupportHost::kHostAppId, arc_host_position)); | 664 PinInfo(app_launcher_id, arc_host_position)); |
645 app_service->SetPinPosition(ArcSupportHost::kHostAppId, | 665 app_service->SetPinPosition(ArcSupportHost::kHostAppId, |
646 arc_host_position); | 666 arc_host_position); |
647 } | 667 } |
648 } | 668 } |
649 | 669 |
650 // Convert to string array. | 670 // Convert to string array. |
651 std::vector<std::string> pins(pin_infos.size()); | 671 std::vector<std::string> pins(pin_infos.size()); |
652 for (size_t i = 0; i < pin_infos.size(); ++i) | 672 for (size_t i = 0; i < pin_infos.size(); ++i) |
653 pins[i] = pin_infos[i].app_id; | 673 pins[i] = pin_infos[i].app_launcher_id; |
654 | 674 |
655 return pins; | 675 return pins; |
656 } | 676 } |
657 | 677 |
658 void RemovePinPosition(Profile* profile, const std::string& app_id) { | 678 void RemovePinPosition(Profile* profile, AppLauncherId* app_launcher_id) { |
659 DCHECK(profile); | 679 DCHECK(profile); |
660 DCHECK(!app_id.empty()); | 680 const std::string launcher_id = app_launcher_id->GetAppLauncherID(); |
681 DCHECK(!launcher_id.empty()); | |
661 app_list::AppListSyncableService* app_service = | 682 app_list::AppListSyncableService* app_service = |
662 app_list::AppListSyncableServiceFactory::GetForProfile(profile); | 683 app_list::AppListSyncableServiceFactory::GetForProfile(profile); |
663 app_service->SetPinPosition(app_id, syncer::StringOrdinal()); | 684 app_service->SetPinPosition(launcher_id, syncer::StringOrdinal()); |
664 } | 685 } |
665 | 686 |
666 void SetPinPosition(Profile* profile, | 687 void SetPinPosition(Profile* profile, |
667 const std::string& app_id, | 688 AppLauncherId* app_launcher_id, |
668 const std::string& app_id_before, | 689 AppLauncherId* app_launcher_id_before, |
669 const std::string& app_id_after) { | 690 AppLauncherId* app_launcher_id_after) { |
670 DCHECK(profile); | 691 DCHECK(profile); |
671 DCHECK(!app_id.empty()); | 692 const std::string launcher_id = app_launcher_id->GetAppLauncherID(); |
672 DCHECK_NE(app_id, app_id_before); | 693 DCHECK(!launcher_id.empty()); |
673 DCHECK_NE(app_id, app_id_after); | 694 const std::string launcher_id_before = |
674 DCHECK(app_id_before.empty() || app_id_before != app_id_after); | 695 app_launcher_id_before->GetAppLauncherID(); |
696 DCHECK_NE(launcher_id, launcher_id_before); | |
697 const std::string launcher_id_after = | |
698 app_launcher_id_after->GetAppLauncherID(); | |
699 DCHECK_NE(launcher_id, launcher_id_after); | |
700 DCHECK(launcher_id_before.empty() || launcher_id_before != launcher_id_after); | |
675 | 701 |
676 app_list::AppListSyncableService* app_service = | 702 app_list::AppListSyncableService* app_service = |
677 app_list::AppListSyncableServiceFactory::GetForProfile(profile); | 703 app_list::AppListSyncableServiceFactory::GetForProfile(profile); |
678 // Some unit tests may not have this service. | 704 // Some unit tests may not have this service. |
679 if (!app_service) | 705 if (!app_service) |
680 return; | 706 return; |
681 | 707 |
682 syncer::StringOrdinal position_before = | 708 syncer::StringOrdinal position_before = |
683 app_id_before.empty() ? syncer::StringOrdinal() | 709 launcher_id_before.empty() |
684 : app_service->GetPinPosition(app_id_before); | 710 ? syncer::StringOrdinal() |
711 : app_service->GetPinPosition(launcher_id_before); | |
685 syncer::StringOrdinal position_after = | 712 syncer::StringOrdinal position_after = |
686 app_id_after.empty() ? syncer::StringOrdinal() | 713 launcher_id_after.empty() |
687 : app_service->GetPinPosition(app_id_after); | 714 ? syncer::StringOrdinal() |
715 : app_service->GetPinPosition(launcher_id_after); | |
688 | 716 |
689 syncer::StringOrdinal pin_position; | 717 syncer::StringOrdinal pin_position; |
690 if (position_before.IsValid() && position_after.IsValid()) | 718 if (position_before.IsValid() && position_after.IsValid()) |
691 pin_position = position_before.CreateBetween(position_after); | 719 pin_position = position_before.CreateBetween(position_after); |
692 else if (position_before.IsValid()) | 720 else if (position_before.IsValid()) |
693 pin_position = position_before.CreateAfter(); | 721 pin_position = position_before.CreateAfter(); |
694 else if (position_after.IsValid()) | 722 else if (position_after.IsValid()) |
695 pin_position = position_after.CreateBefore(); | 723 pin_position = position_after.CreateBefore(); |
696 else | 724 else |
697 pin_position = syncer::StringOrdinal::CreateInitialOrdinal(); | 725 pin_position = syncer::StringOrdinal::CreateInitialOrdinal(); |
698 app_service->SetPinPosition(app_id, pin_position); | 726 app_service->SetPinPosition(launcher_id, pin_position); |
699 } | 727 } |
700 | 728 |
729 AppLauncherId::AppLauncherId(const std::string& app_id) | |
730 : app_launcher_id_(app_id) {} | |
731 | |
732 AppLauncherId::~AppLauncherId() {} | |
733 | |
701 } // namespace launcher | 734 } // namespace launcher |
702 } // namespace ash | 735 } // namespace ash |
OLD | NEW |