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 CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_IMPL_H_
6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_IMPL_H_
11 #include "base/bind.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/sequenced_task_runner.h"
14 #include "base/threading/thread_checker.h"
15 #include "base/values.h"
16 #include "chromeos/ime/component_extension_ime_manager.h"
20 // The implementation class of ComponentExtensionIMEManagerDelegate.
21 class ComponentExtensionIMEManagerImpl
22 : public ComponentExtensionIMEManagerDelegate
{
24 ComponentExtensionIMEManagerImpl();
25 virtual ~ComponentExtensionIMEManagerImpl();
27 // ComponentExtensionIMEManagerDelegate overrides:
28 virtual std::vector
<ComponentExtensionIME
> ListIME() OVERRIDE
;
29 virtual bool Load(const std::string
& extension_id
,
30 const std::string
& manifest
,
31 const base::FilePath
& file_path
) OVERRIDE
;
32 virtual bool Unload(const std::string
& extension_id
,
33 const base::FilePath
& file_path
) OVERRIDE
;
35 // Loads extension list and reads their manifest file. After finished
36 // initialization, |callback| will be called on original thread.
37 void InitializeAsync(const base::Closure
& callback
);
39 // Returns true if this class is initialized and ready to use, otherwise
44 // Reads component extensions and extract their localized information: name,
45 // description and ime id. This function fills them into |out_imes|. This
46 // function must be called on file thread.
47 static void ReadComponentExtensionsInfo(
48 std::vector
<ComponentExtensionIME
>* out_imes
);
50 // This function is called on UI thread after ReadComponentExtensionsInfo
51 // function is finished. No need to release |result|.
52 void OnReadComponentExtensionsInfo(std::vector
<ComponentExtensionIME
>* result
,
53 const base::Closure
& callback
);
55 // Reads manifest.json file in |file_path|. This function must be called on
57 static scoped_ptr
<base::DictionaryValue
> GetManifest(
58 const base::FilePath
& file_path
);
60 // Reads extension information: description, option page. This function
61 // returns true on success, otherwise returns false. This function must be
62 // called on file thread.
63 static bool ReadExtensionInfo(const base::DictionaryValue
& manifest
,
64 const std::string
& extension_id
,
65 ComponentExtensionIME
* out
);
67 // Reads each engine component in |dict|. |dict| is given by GetList with
68 // kInputComponents key from manifest. This function returns true on success,
69 // otherwise retrun false. This function must be called on FILE thread.
70 static bool ReadEngineComponent(const base::DictionaryValue
& dict
,
71 ComponentExtensionEngine
* out
);
73 // True if initialized.
76 // The list of component extension IME.
77 std::vector
<ComponentExtensionIME
> component_extension_list_
;
79 // The list of already loaded extension ids.
80 std::set
<std::string
> loaded_extension_id_
;
82 // For checking the function should be called on UI thread.
83 base::ThreadChecker thread_checker_
;
84 base::WeakPtrFactory
<ComponentExtensionIMEManagerImpl
> weak_ptr_factory_
;
86 DISALLOW_COPY_AND_ASSIGN(ComponentExtensionIMEManagerImpl
);
89 } // namespace chromeos
91 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_COMPONENT_EXTENSION_IME_MANAGER_IMPL_H_