Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / chromeos / ime / component_extension_ime_manager.h
blob23a5d891a75949c69693962a79f40b017ddb7b74
1 // Copyright 2013 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 CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_
6 #define CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h"
11 #include "chromeos/chromeos_export.h"
12 #include "chromeos/ime/input_method_descriptor.h"
14 namespace chromeos {
16 // Represents an engine in component extension IME.
17 struct CHROMEOS_EXPORT ComponentExtensionEngine {
18 ComponentExtensionEngine();
19 ~ComponentExtensionEngine();
20 std::string engine_id; // The engine id.
21 std::string display_name; // The display name.
22 std::string language_code; // The engine's language(ex. "en").
23 std::string description; // The engine description.
24 std::vector<std::string> layouts; // The list of keyboard layout of engine.
27 // Represents a component extension IME.
28 // TODO(nona): Use GURL for |option_page_url| instead of string.
29 struct CHROMEOS_EXPORT ComponentExtensionIME {
30 ComponentExtensionIME();
31 ~ComponentExtensionIME();
32 std::string id; // extension id.
33 std::string manifest; // the contents of manifest.json
34 std::string description; // description of extension.
35 GURL options_page_url; // an URL to option page.
36 base::FilePath path;
37 std::vector<ComponentExtensionEngine> engines;
40 // Provides an interface to list/load/unload for component extension IME.
41 class CHROMEOS_EXPORT ComponentExtensionIMEManagerDelegate {
42 public:
43 ComponentExtensionIMEManagerDelegate();
44 virtual ~ComponentExtensionIMEManagerDelegate();
46 // Lists installed component extension IMEs.
47 virtual std::vector<ComponentExtensionIME> ListIME() = 0;
49 // Loads component extension IME associated with |extension_id|.
50 // Returns false if it fails, otherwise returns true.
51 virtual bool Load(const std::string& extension_id,
52 const std::string& manifest,
53 const base::FilePath& path) = 0;
55 // Unloads component extension IME associated with |extension_id|.
56 // Returns false if it fails, otherwise returns true;
57 virtual bool Unload(const std::string& extension_id,
58 const base::FilePath& path) = 0;
61 // This class manages component extension input method.
62 class CHROMEOS_EXPORT ComponentExtensionIMEManager {
63 public:
64 class Observer {
65 public:
66 // Called when the initialization is done.
67 virtual void OnInitialized() = 0;
70 ComponentExtensionIMEManager();
71 virtual ~ComponentExtensionIMEManager();
73 // Initializes component extension manager. This function create internal
74 // mapping between input method id and engine components. This function must
75 // be called before using any other function.
76 void Initialize(scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate);
78 // Returns true if the initialization is done, otherwise returns false.
79 bool IsInitialized();
81 // Loads |input_method_id| component extension IME. This function returns true
82 // on success. This function is safe to call multiple times. Returns false if
83 // already corresponding component extension is loaded.
84 bool LoadComponentExtensionIME(const std::string& input_method_id);
86 // Unloads |input_method_id| component extension IME. This function returns
87 // true on success. This function is safe to call multiple times. Returns
88 // false if already corresponding component extension is unloaded.
89 bool UnloadComponentExtensionIME(const std::string& input_method_id);
91 // Returns true if |input_method_id| is component extension ime id. Note that
92 // this function does not check the |input_method_id| is really whitelisted
93 // one or not. If you want to check |input_method_id| is whitelisted component
94 // extension ime, please use IsWhitelisted instead.
95 static bool IsComponentExtensionIMEId(const std::string& input_method_id);
97 // Returns true if |input_method_id| is whitelisted component extension input
98 // method.
99 bool IsWhitelisted(const std::string& input_method_id);
101 // Returns true if |extension_id| is whitelisted component extension.
102 bool IsWhitelistedExtension(const std::string& extension_id);
104 // Returns InputMethodId. This function returns empty string if |extension_id|
105 // and |engine_id| is not a whitelisted component extention IME.
106 std::string GetId(const std::string& extension_id,
107 const std::string& engine_id);
109 // Returns localized name of |input_method_id|.
110 std::string GetName(const std::string& input_method_id);
112 // Returns localized description of |input_method_id|.
113 std::string GetDescription(const std::string& input_method_id);
115 // Returns list of input method id associated with |language|.
116 std::vector<std::string> ListIMEByLanguage(const std::string& language);
118 // Returns all IME as InputMethodDescriptors.
119 input_method::InputMethodDescriptors GetAllIMEAsInputMethodDescriptor();
121 void AddObserver(Observer* observer);
122 void RemoveObserver(Observer* observer);
124 protected:
125 // Returns InputMethodId for |engine_id| in |extension_id|. This function does
126 // not check |extension_id| is component one or |engine_id| is really a member
127 // of |extension_id|. Do not use this function outside from this class, just
128 // for protected for unit testing.
129 static std::string GetComponentExtensionIMEId(const std::string& extension_id,
130 const std::string& engine_id);
132 private:
133 // Finds ComponentExtensionIME and EngineDescription associated with
134 // |input_method_id|. This function retruns true if it is found, otherwise
135 // returns false. |out_extension| and |out_engine| can be NULL.
136 bool FindEngineEntry(const std::string& input_method_id,
137 ComponentExtensionIME* out_extension,
138 ComponentExtensionEngine* out_engine);
139 scoped_ptr<ComponentExtensionIMEManagerDelegate> delegate_;
141 std::vector<ComponentExtensionIME> component_extension_imes_;
143 ObserverList<Observer> observers_;
145 bool is_initialized_;
147 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManager);
150 } // namespace chromeos
152 #endif // CHROMEOS_IME_COMPONENT_EXTENSION_IME_MANAGER_H_