| OLD | NEW |
| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 void ExtensionDictionaryEventRouter::DispatchLoadedEventIfLoaded() { | 43 void ExtensionDictionaryEventRouter::DispatchLoadedEventIfLoaded() { |
| 44 if (!loaded_) | 44 if (!loaded_) |
| 45 return; | 45 return; |
| 46 | 46 |
| 47 extensions::EventRouter* router = extensions::EventRouter::Get(context_); | 47 extensions::EventRouter* router = extensions::EventRouter::Get(context_); |
| 48 if (!router->HasEventListener(OnDictionaryLoaded::kEventName)) { | 48 if (!router->HasEventListener(OnDictionaryLoaded::kEventName)) { |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 | 51 |
| 52 scoped_ptr<base::ListValue> args(new base::ListValue()); | 52 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 53 // 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. |
| 54 scoped_ptr<extensions::Event> event(new extensions::Event( | 54 std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 55 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_LOADED, | 55 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_LOADED, |
| 56 OnDictionaryLoaded::kEventName, std::move(args))); | 56 OnDictionaryLoaded::kEventName, std::move(args))); |
| 57 event->restrict_to_browser_context = context_; | 57 event->restrict_to_browser_context = context_; |
| 58 router->BroadcastEvent(std::move(event)); | 58 router->BroadcastEvent(std::move(event)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void ExtensionDictionaryEventRouter::OnCustomDictionaryLoaded() { | 61 void ExtensionDictionaryEventRouter::OnCustomDictionaryLoaded() { |
| 62 loaded_ = true; | 62 loaded_ = true; |
| 63 DispatchLoadedEventIfLoaded(); | 63 DispatchLoadedEventIfLoaded(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ExtensionDictionaryEventRouter::OnCustomDictionaryChanged( | 66 void ExtensionDictionaryEventRouter::OnCustomDictionaryChanged( |
| 67 const SpellcheckCustomDictionary::Change& dictionary_change) { | 67 const SpellcheckCustomDictionary::Change& dictionary_change) { |
| 68 extensions::EventRouter* router = extensions::EventRouter::Get(context_); | 68 extensions::EventRouter* router = extensions::EventRouter::Get(context_); |
| 69 | 69 |
| 70 if (!router->HasEventListener(OnDictionaryChanged::kEventName)) { | 70 if (!router->HasEventListener(OnDictionaryChanged::kEventName)) { |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 | 73 |
| 74 scoped_ptr<base::ListValue> added_words(new base::ListValue()); | 74 std::unique_ptr<base::ListValue> added_words(new base::ListValue()); |
| 75 for (const std::string& word : dictionary_change.to_add()) | 75 for (const std::string& word : dictionary_change.to_add()) |
| 76 added_words->AppendString(word); | 76 added_words->AppendString(word); |
| 77 | 77 |
| 78 scoped_ptr<base::ListValue> removed_words(new base::ListValue()); | 78 std::unique_ptr<base::ListValue> removed_words(new base::ListValue()); |
| 79 for (const std::string& word : dictionary_change.to_remove()) | 79 for (const std::string& word : dictionary_change.to_remove()) |
| 80 removed_words->AppendString(word); | 80 removed_words->AppendString(word); |
| 81 | 81 |
| 82 scoped_ptr<base::ListValue> args(new base::ListValue()); | 82 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 83 args->Append(added_words.release()); | 83 args->Append(added_words.release()); |
| 84 args->Append(removed_words.release()); | 84 args->Append(removed_words.release()); |
| 85 | 85 |
| 86 // 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. |
| 87 scoped_ptr<extensions::Event> event(new extensions::Event( | 87 std::unique_ptr<extensions::Event> event(new extensions::Event( |
| 88 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_CHANGED, | 88 extensions::events::INPUT_METHOD_PRIVATE_ON_DICTIONARY_CHANGED, |
| 89 OnDictionaryChanged::kEventName, std::move(args))); | 89 OnDictionaryChanged::kEventName, std::move(args))); |
| 90 event->restrict_to_browser_context = context_; | 90 event->restrict_to_browser_context = context_; |
| 91 router->BroadcastEvent(std::move(event)); | 91 router->BroadcastEvent(std::move(event)); |
| 92 } | 92 } |
| 93 | 93 |
| 94 } // namespace chromeos | 94 } // namespace chromeos |
| OLD | NEW |