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

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

Issue 1236493004: Final batch adding real histogram values for extension events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments, rebase, dcheck, etc Created 5 years, 5 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"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 base::Bind(&NotificationsApiDelegate::Shutdown, 140 base::Bind(&NotificationsApiDelegate::Shutdown,
141 base::Unretained(this))); 141 base::Unretained(this)));
142 } 142 }
143 143
144 void Close(bool by_user) override { 144 void Close(bool by_user) override {
145 EventRouter::UserGestureState gesture = 145 EventRouter::UserGestureState gesture =
146 by_user ? EventRouter::USER_GESTURE_ENABLED 146 by_user ? EventRouter::USER_GESTURE_ENABLED
147 : EventRouter::USER_GESTURE_NOT_ENABLED; 147 : EventRouter::USER_GESTURE_NOT_ENABLED;
148 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); 148 scoped_ptr<base::ListValue> args(CreateBaseEventArgs());
149 args->Append(new base::FundamentalValue(by_user)); 149 args->Append(new base::FundamentalValue(by_user));
150 SendEvent(notifications::OnClosed::kEventName, gesture, args.Pass()); 150 SendEvent(events::NOTIFICATIONS_ON_CLOSED,
151 notifications::OnClosed::kEventName, gesture, args.Pass());
151 } 152 }
152 153
153 void Click() override { 154 void Click() override {
154 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); 155 scoped_ptr<base::ListValue> args(CreateBaseEventArgs());
155 SendEvent(notifications::OnClicked::kEventName, 156 SendEvent(events::NOTIFICATIONS_ON_CLICKED,
156 EventRouter::USER_GESTURE_ENABLED, 157 notifications::OnClicked::kEventName,
157 args.Pass()); 158 EventRouter::USER_GESTURE_ENABLED, args.Pass());
158 } 159 }
159 160
160 bool HasClickedListener() override { 161 bool HasClickedListener() override {
161 if (!event_router_) 162 if (!event_router_)
162 return false; 163 return false;
163 164
164 return event_router_->HasEventListener( 165 return event_router_->HasEventListener(
165 notifications::OnClicked::kEventName); 166 notifications::OnClicked::kEventName);
166 } 167 }
167 168
168 void ButtonClick(int index) override { 169 void ButtonClick(int index) override {
169 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); 170 scoped_ptr<base::ListValue> args(CreateBaseEventArgs());
170 args->Append(new base::FundamentalValue(index)); 171 args->Append(new base::FundamentalValue(index));
171 SendEvent(notifications::OnButtonClicked::kEventName, 172 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED,
172 EventRouter::USER_GESTURE_ENABLED, 173 notifications::OnButtonClicked::kEventName,
173 args.Pass()); 174 EventRouter::USER_GESTURE_ENABLED, args.Pass());
174 } 175 }
175 176
176 std::string id() const override { return scoped_id_; } 177 std::string id() const override { return scoped_id_; }
177 178
178 private: 179 private:
179 ~NotificationsApiDelegate() override {} 180 ~NotificationsApiDelegate() override {}
180 181
181 void SendEvent(const std::string& name, 182 void SendEvent(events::HistogramValue histogram_value,
183 const std::string& name,
182 EventRouter::UserGestureState user_gesture, 184 EventRouter::UserGestureState user_gesture,
183 scoped_ptr<base::ListValue> args) { 185 scoped_ptr<base::ListValue> args) {
184 if (!event_router_) 186 if (!event_router_)
185 return; 187 return;
186 188
187 scoped_ptr<Event> event(new Event(events::UNKNOWN, name, args.Pass())); 189 scoped_ptr<Event> event(new Event(histogram_value, name, args.Pass()));
188 event->user_gesture = user_gesture; 190 event->user_gesture = user_gesture;
189 event_router_->DispatchEventToExtension(extension_id_, event.Pass()); 191 event_router_->DispatchEventToExtension(extension_id_, event.Pass());
190 } 192 }
191 193
192 void Shutdown() { 194 void Shutdown() {
193 event_router_ = nullptr; 195 event_router_ = nullptr;
194 shutdown_notifier_subscription_.reset(); 196 shutdown_notifier_subscription_.reset();
195 } 197 }
196 198
197 scoped_ptr<base::ListValue> CreateBaseEventArgs() { 199 scoped_ptr<base::ListValue> CreateBaseEventArgs() {
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 ? api::notifications::PERMISSION_LEVEL_GRANTED 685 ? api::notifications::PERMISSION_LEVEL_GRANTED
684 : api::notifications::PERMISSION_LEVEL_DENIED; 686 : api::notifications::PERMISSION_LEVEL_DENIED;
685 687
686 SetResult(new base::StringValue(api::notifications::ToString(result))); 688 SetResult(new base::StringValue(api::notifications::ToString(result)));
687 SendResponse(true); 689 SendResponse(true);
688 690
689 return true; 691 return true;
690 } 692 }
691 693
692 } // namespace extensions 694 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698