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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_api.cc

Issue 238633009: cleanup: Use EventRouter instead of ExtensionSystem::Get->event_router() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile error for chromeos build. Created 6 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extensions/api/notifications/notifications_api.h" 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/notifications/desktop_notification_service.h" 14 #include "chrome/browser/notifications/desktop_notification_service.h"
15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
16 #include "chrome/browser/notifications/notification.h" 16 #include "chrome/browser/notifications/notification.h"
17 #include "chrome/browser/notifications/notification_ui_manager.h" 17 #include "chrome/browser/notifications/notification_ui_manager.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/common/chrome_version_info.h" 19 #include "chrome/common/chrome_version_info.h"
20 #include "content/public/browser/render_process_host.h" 20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "extensions/browser/event_router.h" 23 #include "extensions/browser/event_router.h"
24 #include "extensions/browser/extension_system.h"
25 #include "extensions/common/extension.h" 24 #include "extensions/common/extension.h"
26 #include "extensions/common/features/feature.h" 25 #include "extensions/common/features/feature.h"
27 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
28 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/image/image_skia.h" 28 #include "ui/gfx/image/image_skia.h"
30 #include "ui/gfx/image/image_skia_rep.h" 29 #include "ui/gfx/image/image_skia_rep.h"
31 #include "ui/message_center/message_center_style.h" 30 #include "ui/message_center/message_center_style.h"
32 #include "ui/message_center/message_center_util.h" 31 #include "ui/message_center/message_center_util.h"
33 #include "ui/message_center/notifier_settings.h" 32 #include "ui/message_center/notifier_settings.h"
34 #include "url/gurl.h" 33 #include "url/gurl.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 args->Append(new base::FundamentalValue(by_user)); 150 args->Append(new base::FundamentalValue(by_user));
152 SendEvent(notifications::OnClosed::kEventName, args.Pass()); 151 SendEvent(notifications::OnClosed::kEventName, args.Pass());
153 } 152 }
154 153
155 virtual void Click() OVERRIDE { 154 virtual void Click() OVERRIDE {
156 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); 155 scoped_ptr<base::ListValue> args(CreateBaseEventArgs());
157 SendEvent(notifications::OnClicked::kEventName, args.Pass()); 156 SendEvent(notifications::OnClicked::kEventName, args.Pass());
158 } 157 }
159 158
160 virtual bool HasClickedListener() OVERRIDE { 159 virtual bool HasClickedListener() OVERRIDE {
161 return ExtensionSystem::Get(profile_)->event_router()->HasEventListener( 160 return EventRouter::Get(profile_)->HasEventListener(
162 notifications::OnClicked::kEventName); 161 notifications::OnClicked::kEventName);
163 } 162 }
164 163
165 virtual void ButtonClick(int index) OVERRIDE { 164 virtual void ButtonClick(int index) OVERRIDE {
166 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); 165 scoped_ptr<base::ListValue> args(CreateBaseEventArgs());
167 args->Append(new base::FundamentalValue(index)); 166 args->Append(new base::FundamentalValue(index));
168 SendEvent(notifications::OnButtonClicked::kEventName, args.Pass()); 167 SendEvent(notifications::OnButtonClicked::kEventName, args.Pass());
169 } 168 }
170 169
171 virtual std::string id() const OVERRIDE { 170 virtual std::string id() const OVERRIDE {
(...skipping 19 matching lines...) Expand all
191 190
192 virtual void ReleaseRenderViewHost() OVERRIDE { 191 virtual void ReleaseRenderViewHost() OVERRIDE {
193 api_function_ = NULL; 192 api_function_ = NULL;
194 } 193 }
195 194
196 private: 195 private:
197 virtual ~NotificationsApiDelegate() {} 196 virtual ~NotificationsApiDelegate() {}
198 197
199 void SendEvent(const std::string& name, scoped_ptr<base::ListValue> args) { 198 void SendEvent(const std::string& name, scoped_ptr<base::ListValue> args) {
200 scoped_ptr<Event> event(new Event(name, args.Pass())); 199 scoped_ptr<Event> event(new Event(name, args.Pass()));
201 ExtensionSystem::Get(profile_)->event_router()->DispatchEventToExtension( 200 EventRouter::Get(profile_)->DispatchEventToExtension(extension_id_,
202 extension_id_, event.Pass()); 201 event.Pass());
203 } 202 }
204 203
205 scoped_ptr<base::ListValue> CreateBaseEventArgs() { 204 scoped_ptr<base::ListValue> CreateBaseEventArgs() {
206 scoped_ptr<base::ListValue> args(new base::ListValue()); 205 scoped_ptr<base::ListValue> args(new base::ListValue());
207 args->Append(new base::StringValue(id_)); 206 args->Append(new base::StringValue(id_));
208 return args.Pass(); 207 return args.Pass();
209 } 208 }
210 209
211 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; 210 scoped_refptr<ChromeAsyncExtensionFunction> api_function_;
212 Profile* profile_; 211 Profile* profile_;
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 ? api::notifications::PERMISSION_LEVEL_GRANTED 615 ? api::notifications::PERMISSION_LEVEL_GRANTED
617 : api::notifications::PERMISSION_LEVEL_DENIED; 616 : api::notifications::PERMISSION_LEVEL_DENIED;
618 617
619 SetResult(new base::StringValue(api::notifications::ToString(result))); 618 SetResult(new base::StringValue(api::notifications::ToString(result)));
620 SendResponse(true); 619 SendResponse(true);
621 620
622 return true; 621 return true;
623 } 622 }
624 623
625 } // namespace extensions 624 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698