File: input_method_syncer.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,655 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_INPUT_METHOD_INPUT_METHOD_SYNCER_H_
#define CHROME_BROWSER_ASH_INPUT_METHOD_INPUT_METHOD_SYNCER_H_

#include <memory>
#include <string>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "components/prefs/pref_member.h"
#include "components/sync_preferences/pref_service_syncable_observer.h"
#include "ui/base/ime/ash/input_method_manager.h"

namespace sync_preferences {
class PrefServiceSyncable;
}  // namespace sync_preferences

namespace user_prefs {
class PrefRegistrySyncable;
}  // namespace user_prefs

namespace ash {
namespace input_method {

// Helper class to handle syncing of language and input method preferences.
// Changes to local preferences are handed up to the sync server. But Chrome OS
// should not locally apply the corresponding preferences from the sync server,
// except once: when the user first logs into the device.
// Thus, the user's most recent changes to language and input method preferences
// will be brought down when signing in to a new device but not in future syncs.
class InputMethodSyncer : public sync_preferences::PrefServiceSyncableObserver {
 public:
  InputMethodSyncer(sync_preferences::PrefServiceSyncable* prefs,
                    scoped_refptr<InputMethodManager::State> ime_state);
  ~InputMethodSyncer() override;

  // Registers the syncable input method prefs.
  static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);

  // Must be called after InputMethodSyncer is created.
  void Initialize();

 private:
  // Adds the input methods from the syncable prefs to the device-local prefs.
  // This should only be called once (after user's first sync) and only adds
  // to, not removes from, the user's input method prefs.
  void MergeSyncedPrefs();

  // For the given input method pref, adds unique values from |synced_pref| to
  // values in |pref|. The new values are converted from legacy engine IDs to
  // input method IDs if necessary.
  std::string AddSupportedInputMethodValues(const std::string& pref,
                                            const std::string& synced_pref,
                                            const char* pref_name);

  // Sets language::prefs::kPreferredLanguages and sets |merging_| to false.
  void FinishMerge(const std::string& languages);

  // Callback method for preference changes. Updates the syncable prefs using
  // the local pref values.
  void OnPreferenceChanged(const std::string& pref_name);

  // sync_preferences::PrefServiceSyncableObserver implementation.
  void OnIsSyncingChanged() override;

  StringPrefMember preferred_languages_;
  StringPrefMember preload_engines_;
  StringPrefMember enabled_imes_;
  // These are syncable variants which don't change the device settings. We can
  // set these to keep track of the user's most recent choices. That way, after
  // the initial sync, we can add the user's synced choices to the values that
  // have already been chosen at OOBE.
  StringPrefMember preferred_languages_syncable_;
  StringPrefMember preload_engines_syncable_;
  StringPrefMember enabled_imes_syncable_;

  raw_ptr<sync_preferences::PrefServiceSyncable> prefs_;
  scoped_refptr<InputMethodManager::State> ime_state_;

  // Used to ignore PrefChanged events while InputMethodManager is merging.
  bool merging_;

  base::WeakPtrFactory<InputMethodSyncer> weak_factory_{this};
};

}  // namespace input_method
}  // namespace ash

#endif  // CHROME_BROWSER_ASH_INPUT_METHOD_INPUT_METHOD_SYNCER_H_