Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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/ui/webui/media_router/media_router_webui_message_handle r.h" | 5 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle r.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/metrics/histogram_base.h" | |
|
Ilya Sherman
2015/10/23 20:40:22
Please replace these with a histogram_macros inclu
apacible
2015/10/23 22:52:55
Done.
| |
| 10 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/media/router/issue.h" | 13 #include "chrome/browser/media/router/issue.h" |
| 12 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | 14 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 13 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 14 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 16 | 18 |
| 17 namespace media_router { | 19 namespace media_router { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 const char kHelpPageUrlPrefix[] = | 23 const char kHelpPageUrlPrefix[] = |
| 22 "https://support.google.com/chromecast/answer/%d"; | 24 "https://support.google.com/chromecast/answer/%d"; |
| 23 | 25 |
| 24 // Message names. | 26 // Message names. |
| 25 const char kRequestInitialData[] = "requestInitialData"; | 27 const char kRequestInitialData[] = "requestInitialData"; |
| 26 const char kCreateRoute[] = "requestRoute"; | 28 const char kCreateRoute[] = "requestRoute"; |
| 27 const char kActOnIssue[] = "actOnIssue"; | 29 const char kActOnIssue[] = "actOnIssue"; |
| 28 const char kCloseRoute[] = "closeRoute"; | 30 const char kCloseRoute[] = "closeRoute"; |
| 29 const char kCloseDialog[] = "closeDialog"; | 31 const char kCloseDialog[] = "closeDialog"; |
| 32 const char kReportSinkCount[] = "reportSinkCount"; | |
| 30 | 33 |
| 31 // JS function names. | 34 // JS function names. |
| 32 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 35 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 33 const char kNotifyRouteCreationTimeout[] = | 36 const char kNotifyRouteCreationTimeout[] = |
| 34 "media_router.ui.onNotifyRouteCreationTimeout"; | 37 "media_router.ui.onNotifyRouteCreationTimeout"; |
| 35 const char kOnCreateRouteResponseReceived[] = | 38 const char kOnCreateRouteResponseReceived[] = |
| 36 "media_router.ui.onCreateRouteResponseReceived"; | 39 "media_router.ui.onCreateRouteResponseReceived"; |
| 37 const char kSetIssue[] = "media_router.ui.setIssue"; | 40 const char kSetIssue[] = "media_router.ui.setIssue"; |
| 38 const char kSetSinkList[] = "media_router.ui.setSinkList"; | 41 const char kSetSinkList[] = "media_router.ui.setSinkList"; |
| 39 const char kSetRouteList[] = "media_router.ui.setRouteList"; | 42 const char kSetRouteList[] = "media_router.ui.setRouteList"; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 | 198 |
| 196 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( | 199 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| 197 const MediaSink::Id& sink_id, | 200 const MediaSink::Id& sink_id, |
| 198 const MediaRoute* route) { | 201 const MediaRoute* route) { |
| 199 DVLOG(2) << "OnCreateRouteResponseReceived"; | 202 DVLOG(2) << "OnCreateRouteResponseReceived"; |
| 200 if (route) { | 203 if (route) { |
| 201 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route, | 204 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route, |
| 202 media_router_ui_->GetRouteProviderExtensionId())); | 205 media_router_ui_->GetRouteProviderExtensionId())); |
| 203 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 206 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 204 base::StringValue(sink_id), *route_value); | 207 base::StringValue(sink_id), *route_value); |
| 208 | |
| 209 UMA_HISTOGRAM_BOOLEAN( | |
| 210 "MediaRouter.Ui.Action.StartLocalSessionSuccessful", true); | |
| 205 } else { | 211 } else { |
| 206 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 212 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 207 base::StringValue(sink_id), | 213 base::StringValue(sink_id), |
| 208 *base::Value::CreateNullValue()); | 214 *base::Value::CreateNullValue()); |
| 215 | |
| 216 UMA_HISTOGRAM_BOOLEAN( | |
| 217 "MediaRouter.Ui.Action.StartLocalSessionSuccessful", false); | |
|
Ilya Sherman
2015/10/23 20:40:22
Please record this as UMA_HISTOGRAM_BOOLEAN(..., r
apacible
2015/10/23 22:52:55
Done.
apacible
2015/10/26 17:52:32
Switched back because of these warnings:
e:\b\bui
| |
| 209 } | 218 } |
| 210 } | 219 } |
| 211 | 220 |
| 212 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 221 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 213 DVLOG(2) << "UpdateIssue"; | 222 DVLOG(2) << "UpdateIssue"; |
| 214 if (issue) { | 223 if (issue) { |
| 215 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); | 224 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); |
| 216 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); | 225 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); |
| 217 } else { | 226 } else { |
| 218 // Clears the issue in the WebUI. | 227 // Clears the issue in the WebUI. |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 239 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, | 248 base::Bind(&MediaRouterWebUIMessageHandler::OnActOnIssue, |
| 240 base::Unretained(this))); | 249 base::Unretained(this))); |
| 241 web_ui()->RegisterMessageCallback( | 250 web_ui()->RegisterMessageCallback( |
| 242 kCloseRoute, | 251 kCloseRoute, |
| 243 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, | 252 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseRoute, |
| 244 base::Unretained(this))); | 253 base::Unretained(this))); |
| 245 web_ui()->RegisterMessageCallback( | 254 web_ui()->RegisterMessageCallback( |
| 246 kCloseDialog, | 255 kCloseDialog, |
| 247 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, | 256 base::Bind(&MediaRouterWebUIMessageHandler::OnCloseDialog, |
| 248 base::Unretained(this))); | 257 base::Unretained(this))); |
| 258 web_ui()->RegisterMessageCallback( | |
| 259 kReportSinkCount, | |
| 260 base::Bind(&MediaRouterWebUIMessageHandler::OnReportSinkCount, | |
| 261 base::Unretained(this))); | |
| 249 } | 262 } |
| 250 | 263 |
| 251 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 264 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 252 const base::ListValue* args) { | 265 const base::ListValue* args) { |
| 253 DVLOG(1) << "OnRequestInitialData"; | 266 DVLOG(1) << "OnRequestInitialData"; |
| 254 base::DictionaryValue initial_data; | 267 base::DictionaryValue initial_data; |
| 255 | 268 |
| 256 // "No Cast devices found?" Chromecast help center page. | 269 // "No Cast devices found?" Chromecast help center page. |
| 257 initial_data.SetString("deviceMissingUrl", | 270 initial_data.SetString("deviceMissingUrl", |
| 258 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 271 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 void MediaRouterWebUIMessageHandler::OnCloseDialog( | 379 void MediaRouterWebUIMessageHandler::OnCloseDialog( |
| 367 const base::ListValue* args) { | 380 const base::ListValue* args) { |
| 368 DVLOG(1) << "OnCloseDialog"; | 381 DVLOG(1) << "OnCloseDialog"; |
| 369 if (dialog_closing_) | 382 if (dialog_closing_) |
| 370 return; | 383 return; |
| 371 | 384 |
| 372 dialog_closing_ = true; | 385 dialog_closing_ = true; |
| 373 media_router_ui_->Close(); | 386 media_router_ui_->Close(); |
| 374 } | 387 } |
| 375 | 388 |
| 389 void MediaRouterWebUIMessageHandler::OnReportSinkCount( | |
| 390 const base::ListValue* args) { | |
| 391 DVLOG(1) << "OnReportSinkCount"; | |
| 392 const base::DictionaryValue* args_dict = nullptr; | |
| 393 int sink_count = -1; | |
| 394 if (!args->GetDictionary(0, &args_dict) || | |
| 395 !args_dict->GetInteger("sinkCount", &sink_count)) { | |
| 396 DVLOG(1) << "Unable to extract args."; | |
| 397 return; | |
| 398 } | |
| 399 UMA_HISTOGRAM_COUNTS_100("MediaRouter.Ui.Device.Count", sink_count); | |
| 400 } | |
| 401 | |
| 376 bool MediaRouterWebUIMessageHandler::ActOnIssueType( | 402 bool MediaRouterWebUIMessageHandler::ActOnIssueType( |
| 377 const IssueAction::Type& action_type, | 403 const IssueAction::Type& action_type, |
| 378 const base::DictionaryValue* args) { | 404 const base::DictionaryValue* args) { |
| 379 if (action_type == IssueAction::TYPE_LEARN_MORE) { | 405 if (action_type == IssueAction::TYPE_LEARN_MORE) { |
| 380 std::string learn_more_url = GetLearnMoreUrl(args); | 406 std::string learn_more_url = GetLearnMoreUrl(args); |
| 381 if (learn_more_url.empty()) | 407 if (learn_more_url.empty()) |
| 382 return false; | 408 return false; |
| 383 scoped_ptr<base::ListValue> open_args(new base::ListValue); | 409 scoped_ptr<base::ListValue> open_args(new base::ListValue); |
| 384 open_args->AppendString(learn_more_url); | 410 open_args->AppendString(learn_more_url); |
| 385 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 411 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 386 return true; | 412 return true; |
| 387 } else { | 413 } else { |
| 388 // Do nothing; no other issue action types require any other action. | 414 // Do nothing; no other issue action types require any other action. |
| 389 return true; | 415 return true; |
| 390 } | 416 } |
| 391 } | 417 } |
| 392 | 418 |
| 393 } // namespace media_router | 419 } // namespace media_router |
| OLD | NEW |