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

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

Issue 2898383002: [Extensions] Make Event::restrict_to_browser_context const. (Closed)
Patch Set: sync @tott Created 3 years, 6 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/ime_menu_event_router.cc » ('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/memory/ptr_util.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "chrome/browser/chromeos/extensions/input_method_api.h" 13 #include "chrome/browser/chromeos/extensions/input_method_api.h"
13 #include "chrome/browser/spellchecker/spellcheck_factory.h" 14 #include "chrome/browser/spellchecker/spellcheck_factory.h"
14 #include "chrome/common/extensions/api/input_method_private.h" 15 #include "chrome/common/extensions/api/input_method_private.h"
15 #include "content/public/browser/browser_context.h" 16 #include "content/public/browser/browser_context.h"
16 #include "extensions/browser/event_router.h" 17 #include "extensions/browser/event_router.h"
17 #include "extensions/browser/extension_system.h" 18 #include "extensions/browser/extension_system.h"
18 19
19 namespace OnDictionaryChanged = 20 namespace OnDictionaryChanged =
20 extensions::api::input_method_private::OnDictionaryChanged; 21 extensions::api::input_method_private::OnDictionaryChanged;
(...skipping 21 matching lines...) Expand all
42 43
43 void ExtensionDictionaryEventRouter::DispatchLoadedEventIfLoaded() { 44 void ExtensionDictionaryEventRouter::DispatchLoadedEventIfLoaded() {
44 if (!loaded_) 45 if (!loaded_)
45 return; 46 return;
46 47
47 extensions::EventRouter* router = extensions::EventRouter::Get(context_); 48 extensions::EventRouter* router = extensions::EventRouter::Get(context_);
48 if (!router->HasEventListener(OnDictionaryLoaded::kEventName)) { 49 if (!router->HasEventListener(OnDictionaryLoaded::kEventName)) {
49 return; 50 return;
50 } 51 }
51 52
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 std::unique_ptr<extensions::Event> event(new extensions::Event( 54 auto event = base::MakeUnique<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, base::MakeUnique<base::ListValue>(),
57 event->restrict_to_browser_context = context_; 57 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 std::unique_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 std::unique_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 std::unique_ptr<base::ListValue> args(new base::ListValue()); 82 std::unique_ptr<base::ListValue> args(new base::ListValue());
83 args->Append(std::move(added_words)); 83 args->Append(std::move(added_words));
84 args->Append(std::move(removed_words)); 84 args->Append(std::move(removed_words));
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 std::unique_ptr<extensions::Event> event(new extensions::Event( 87 auto event = base::MakeUnique<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), context_);
90 event->restrict_to_browser_context = context_;
91 router->BroadcastEvent(std::move(event)); 90 router->BroadcastEvent(std::move(event));
92 } 91 }
93 92
94 } // namespace chromeos 93 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/extensions/ime_menu_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698