Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/browser/chromeos/extensions/dictionary_event_router.cc

Issue 1587913002: Use common generated file for inputMethodPrivate APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/input_method_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h" 5 #include "chrome/browser/chromeos/extensions/dictionary_event_router.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/chromeos/extensions/input_method_api.h" 12 #include "chrome/browser/chromeos/extensions/input_method_api.h"
13 #include "chrome/browser/spellchecker/spellcheck_factory.h" 13 #include "chrome/browser/spellchecker/spellcheck_factory.h"
14 #include "chrome/common/extensions/api/input_method_private.h"
14 #include "content/public/browser/browser_context.h" 15 #include "content/public/browser/browser_context.h"
15 #include "extensions/browser/event_router.h" 16 #include "extensions/browser/event_router.h"
16 #include "extensions/browser/extension_system.h" 17 #include "extensions/browser/extension_system.h"
17 18
19 namespace OnDictionaryChanged =
20 extensions::api::input_method_private::OnDictionaryChanged;
21 namespace OnDictionaryLoaded =
22 extensions::api::input_method_private::OnDictionaryLoaded;
23
18 namespace chromeos { 24 namespace chromeos {
19 25
20 ExtensionDictionaryEventRouter::ExtensionDictionaryEventRouter( 26 ExtensionDictionaryEventRouter::ExtensionDictionaryEventRouter(
21 content::BrowserContext* context) 27 content::BrowserContext* context)
22 : context_(context), loaded_() { 28 : context_(context), loaded_() {
23 SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext( 29 SpellcheckService* spellcheck = SpellcheckServiceFactory::GetForContext(
24 context_); 30 context_);
25 if (spellcheck) { 31 if (spellcheck) {
26 service_ = spellcheck->GetWeakPtr(); 32 service_ = spellcheck->GetWeakPtr();
27 service_->GetCustomDictionary()->AddObserver(this); 33 service_->GetCustomDictionary()->AddObserver(this);
28 loaded_ = service_->GetCustomDictionary()->IsLoaded(); 34 loaded_ = service_->GetCustomDictionary()->IsLoaded();
29 } 35 }
30 } 36 }
31 37
32 ExtensionDictionaryEventRouter::~ExtensionDictionaryEventRouter() { 38 ExtensionDictionaryEventRouter::~ExtensionDictionaryEventRouter() {
33 if (service_) 39 if (service_)
34 service_->GetCustomDictionary()->RemoveObserver(this); 40 service_->GetCustomDictionary()->RemoveObserver(this);
35 } 41 }
36 42
37 void ExtensionDictionaryEventRouter::DispatchLoadedEventIfLoaded() { 43 void ExtensionDictionaryEventRouter::DispatchLoadedEventIfLoaded() {
38 if (!loaded_) 44 if (!loaded_)
39 return; 45 return;
40 46
41 extensions::EventRouter* router = extensions::EventRouter::Get(context_); 47 extensions::EventRouter* router = extensions::EventRouter::Get(context_);
42 if (!router->HasEventListener( 48 if (!router->HasEventListener(OnDictionaryLoaded::kEventName)) {
43 extensions::InputMethodAPI::kOnDictionaryLoaded)) {
44 return; 49 return;
45 } 50 }
46 51
47 scoped_ptr<base::ListValue> args(new base::ListValue()); 52 scoped_ptr<base::ListValue> args(new base::ListValue());
48 // The router will only send the event to extensions that are listening. 53 // The router will only send the event to extensions that are listening.
49 scoped_ptr<extensions::Event> event(new extensions::Event( 54 scoped_ptr<extensions::Event> event(new extensions::Event(
50 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_LOADED, 55 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_LOADED,
51 extensions::InputMethodAPI::kOnDictionaryLoaded, std::move(args))); 56 OnDictionaryLoaded::kEventName, std::move(args)));
52 event->restrict_to_browser_context = context_; 57 event->restrict_to_browser_context = context_;
53 router->BroadcastEvent(std::move(event)); 58 router->BroadcastEvent(std::move(event));
54 } 59 }
55 60
56 void ExtensionDictionaryEventRouter::OnCustomDictionaryLoaded() { 61 void ExtensionDictionaryEventRouter::OnCustomDictionaryLoaded() {
57 loaded_ = true; 62 loaded_ = true;
58 DispatchLoadedEventIfLoaded(); 63 DispatchLoadedEventIfLoaded();
59 } 64 }
60 65
61 void ExtensionDictionaryEventRouter::OnCustomDictionaryChanged( 66 void ExtensionDictionaryEventRouter::OnCustomDictionaryChanged(
62 const SpellcheckCustomDictionary::Change& dictionary_change) { 67 const SpellcheckCustomDictionary::Change& dictionary_change) {
63 extensions::EventRouter* router = extensions::EventRouter::Get(context_); 68 extensions::EventRouter* router = extensions::EventRouter::Get(context_);
64 69
65 if (!router->HasEventListener( 70 if (!router->HasEventListener(OnDictionaryChanged::kEventName)) {
66 extensions::InputMethodAPI::kOnDictionaryChanged)) {
67 return; 71 return;
68 } 72 }
69 73
70 scoped_ptr<base::ListValue> added_words(new base::ListValue()); 74 scoped_ptr<base::ListValue> added_words(new base::ListValue());
71 for (const std::string& word : dictionary_change.to_add()) 75 for (const std::string& word : dictionary_change.to_add())
72 added_words->AppendString(word); 76 added_words->AppendString(word);
73 77
74 scoped_ptr<base::ListValue> removed_words(new base::ListValue()); 78 scoped_ptr<base::ListValue> removed_words(new base::ListValue());
75 for (const std::string& word : dictionary_change.to_remove()) 79 for (const std::string& word : dictionary_change.to_remove())
76 removed_words->AppendString(word); 80 removed_words->AppendString(word);
77 81
78 scoped_ptr<base::ListValue> args(new base::ListValue()); 82 scoped_ptr<base::ListValue> args(new base::ListValue());
79 args->Append(added_words.release()); 83 args->Append(added_words.release());
80 args->Append(removed_words.release()); 84 args->Append(removed_words.release());
81 85
82 // The router will only send the event to extensions that are listening. 86 // The router will only send the event to extensions that are listening.
83 scoped_ptr<extensions::Event> event(new extensions::Event( 87 scoped_ptr<extensions::Event> event(new extensions::Event(
84 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_CHANGED, 88 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_CHANGED,
85 extensions::InputMethodAPI::kOnDictionaryChanged, std::move(args))); 89 OnDictionaryChanged::kEventName, std::move(args)));
86 event->restrict_to_browser_context = context_; 90 event->restrict_to_browser_context = context_;
87 router->BroadcastEvent(std::move(event)); 91 router->BroadcastEvent(std::move(event));
88 } 92 }
89 93
90 } // namespace chromeos 94 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/input_method_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698