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
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
6
7#include "base/basictypes.h"
8#include "base/memory/scoped_ptr.h"
9#include "base/values.h"
10#include "chrome/common/extensions/extension_constants.h"
11#include "chrome/common/pref_names.h"
12#include "components/pref_registry/pref_registry_syncable.h"
13
14namespace {
15
16// App ID of default pinned apps.
17const char* kDefaultPinnedApps[] = {
18  extension_misc::kGmailAppId,
19  extension_misc::kGoogleSearchAppId,
20  extension_misc::kGoogleDocAppId,
21  extension_misc::kYoutubeAppId,
22};
23
24base::ListValue* CreateDefaultPinnedAppsList() {
25  scoped_ptr<base::ListValue> apps(new base::ListValue);
26  for (size_t i = 0; i < arraysize(kDefaultPinnedApps); ++i)
27    apps->Append(ash::CreateAppDict(kDefaultPinnedApps[i]));
28
29  return apps.release();
30}
31
32}  // namespace
33
34namespace ash {
35
36const char kPinnedAppsPrefAppIDPath[] = "id";
37
38const char kShelfAutoHideBehaviorAlways[] = "Always";
39const char kShelfAutoHideBehaviorNever[] = "Never";
40
41extern const char kShelfAlignmentBottom[] = "Bottom";
42extern const char kShelfAlignmentLeft[] = "Left";
43extern const char kShelfAlignmentRight[] = "Right";
44extern const char kShelfAlignmentTop[] = "Top";
45
46void RegisterChromeLauncherUserPrefs(
47    user_prefs::PrefRegistrySyncable* registry) {
48  // TODO: If we want to support multiple profiles this will likely need to be
49  // pushed to local state and we'll need to track profile per item.
50  registry->RegisterIntegerPref(
51      prefs::kShelfChromeIconIndex,
52      0,
53      user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
54  registry->RegisterListPref(prefs::kPinnedLauncherApps,
55                             CreateDefaultPinnedAppsList(),
56                             user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
57  registry->RegisterStringPref(prefs::kShelfAutoHideBehavior,
58                               kShelfAutoHideBehaviorNever,
59                               user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
60  registry->RegisterStringPref(
61      prefs::kShelfAutoHideBehaviorLocal,
62      std::string(),
63      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
64  registry->RegisterStringPref(prefs::kShelfAlignment,
65                               kShelfAlignmentBottom,
66                               user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
67  registry->RegisterStringPref(
68      prefs::kShelfAlignmentLocal,
69      std::string(),
70      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
71  registry->RegisterDictionaryPref(
72      prefs::kShelfPreferences,
73      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
74  registry->RegisterIntegerPref(
75      prefs::kLogoutDialogDurationMs,
76      20000,
77      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
78  registry->RegisterBooleanPref(
79      prefs::kShowLogoutButtonInTray,
80      false,
81      user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
82}
83
84base::DictionaryValue* CreateAppDict(const std::string& app_id) {
85  scoped_ptr<base::DictionaryValue> app_value(new base::DictionaryValue);
86  app_value->SetString(kPinnedAppsPrefAppIDPath, app_id);
87  return app_value.release();
88}
89
90}  // namespace ash
91