Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / input_method / input_method_syncer.h
blob20d04fed64fe3a4b3d2f81376c0d119f5548a0b1
1 // Copyright 2014 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.
5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_SYNCER_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_SYNCER_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/prefs/pref_member.h"
13 #include "chrome/browser/prefs/pref_service_syncable_observer.h"
14 #include "ui/base/ime/chromeos/input_method_manager.h"
16 class PrefServiceSyncable;
18 namespace user_prefs {
19 class PrefRegistrySyncable;
22 namespace chromeos {
23 namespace input_method {
25 // Helper class to handle syncing of language and input method preferences.
26 // Changes to local preferences are handed up to the sync server. But Chrome OS
27 // should not locally apply the corresponding preferences from the sync server,
28 // except once: when the user first logs into the device.
29 // Thus, the user's most recent changes to language and input method preferences
30 // will be brought down when signing in to a new device but not in future syncs.
31 class InputMethodSyncer : public PrefServiceSyncableObserver {
32 public:
33 InputMethodSyncer(
34 PrefServiceSyncable* prefs,
35 scoped_refptr<input_method::InputMethodManager::State> ime_state);
36 ~InputMethodSyncer() override;
38 // Registers the syncable input method prefs.
39 static void RegisterProfilePrefs(
40 user_prefs::PrefRegistrySyncable* registry);
42 // Must be called after InputMethodSyncer is created.
43 void Initialize();
45 private:
46 // Adds the input methods from the syncable prefs to the device-local prefs.
47 // This should only be called once (after user's first sync) and only adds
48 // to, not removes from, the user's input method prefs.
49 void MergeSyncedPrefs();
51 // For the given input method pref, adds unique values from |synced_pref| to
52 // values in |pref|. The new values are converted from legacy engine IDs to
53 // input method IDs if necessary.
54 std::string AddSupportedInputMethodValues(
55 const std::string& pref,
56 const std::string& synced_pref,
57 const char* pref_name);
59 // Sets prefs::kLanguagePreferredLanguages and sets |merging_| to false.
60 void FinishMerge(const std::string& languages);
62 // Callback method for preference changes. Updates the syncable prefs using
63 // the local pref values.
64 void OnPreferenceChanged(const std::string& pref_name);
66 // PrefServiceSyncableObserver implementation.
67 void OnIsSyncingChanged() override;
69 StringPrefMember preferred_languages_;
70 StringPrefMember preload_engines_;
71 StringPrefMember enabled_extension_imes_;
72 // These are syncable variants which don't change the device settings. We can
73 // set these to keep track of the user's most recent choices. That way, after
74 // the initial sync, we can add the user's synced choices to the values that
75 // have already been chosen at OOBE.
76 StringPrefMember preferred_languages_syncable_;
77 StringPrefMember preload_engines_syncable_;
78 StringPrefMember enabled_extension_imes_syncable_;
80 PrefServiceSyncable* prefs_;
81 scoped_refptr<input_method::InputMethodManager::State> ime_state_;
83 // Used to ignore PrefChanged events while InputMethodManager is merging.
84 bool merging_;
86 base::WeakPtrFactory<InputMethodSyncer> weak_factory_;
89 } // namespace input_method
90 } // namespace chromeos
92 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_SYNCER_H_