Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / chromeos / input_method / input_method_syncer.h
blobf68910bb45bed4fd7176c9201249e85e24b00c96
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 "components/syncable_prefs/pref_service_syncable_observer.h"
14 #include "ui/base/ime/chromeos/input_method_manager.h"
16 namespace syncable_prefs {
17 class PrefServiceSyncable;
20 namespace user_prefs {
21 class PrefRegistrySyncable;
24 namespace chromeos {
25 namespace input_method {
27 // Helper class to handle syncing of language and input method preferences.
28 // Changes to local preferences are handed up to the sync server. But Chrome OS
29 // should not locally apply the corresponding preferences from the sync server,
30 // except once: when the user first logs into the device.
31 // Thus, the user's most recent changes to language and input method preferences
32 // will be brought down when signing in to a new device but not in future syncs.
33 class InputMethodSyncer : public syncable_prefs::PrefServiceSyncableObserver {
34 public:
35 InputMethodSyncer(
36 syncable_prefs::PrefServiceSyncable* prefs,
37 scoped_refptr<input_method::InputMethodManager::State> ime_state);
38 ~InputMethodSyncer() override;
40 // Registers the syncable input method prefs.
41 static void RegisterProfilePrefs(
42 user_prefs::PrefRegistrySyncable* registry);
44 // Must be called after InputMethodSyncer is created.
45 void Initialize();
47 private:
48 // Adds the input methods from the syncable prefs to the device-local prefs.
49 // This should only be called once (after user's first sync) and only adds
50 // to, not removes from, the user's input method prefs.
51 void MergeSyncedPrefs();
53 // For the given input method pref, adds unique values from |synced_pref| to
54 // values in |pref|. The new values are converted from legacy engine IDs to
55 // input method IDs if necessary.
56 std::string AddSupportedInputMethodValues(
57 const std::string& pref,
58 const std::string& synced_pref,
59 const char* pref_name);
61 // Sets prefs::kLanguagePreferredLanguages and sets |merging_| to false.
62 void FinishMerge(const std::string& languages);
64 // Callback method for preference changes. Updates the syncable prefs using
65 // the local pref values.
66 void OnPreferenceChanged(const std::string& pref_name);
68 // syncable_prefs::PrefServiceSyncableObserver implementation.
69 void OnIsSyncingChanged() override;
71 StringPrefMember preferred_languages_;
72 StringPrefMember preload_engines_;
73 StringPrefMember enabled_extension_imes_;
74 // These are syncable variants which don't change the device settings. We can
75 // set these to keep track of the user's most recent choices. That way, after
76 // the initial sync, we can add the user's synced choices to the values that
77 // have already been chosen at OOBE.
78 StringPrefMember preferred_languages_syncable_;
79 StringPrefMember preload_engines_syncable_;
80 StringPrefMember enabled_extension_imes_syncable_;
82 syncable_prefs::PrefServiceSyncable* prefs_;
83 scoped_refptr<input_method::InputMethodManager::State> ime_state_;
85 // Used to ignore PrefChanged events while InputMethodManager is merging.
86 bool merging_;
88 base::WeakPtrFactory<InputMethodSyncer> weak_factory_;
91 } // namespace input_method
92 } // namespace chromeos
94 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHOD_SYNCER_H_