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

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc

Issue 2176613003: [Media Router] Clean up issues related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 1 month 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 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 "description", MediaCastModeToDescription(cast_mode, source_host)); 178 "description", MediaCastModeToDescription(cast_mode, source_host));
179 cast_mode_val->SetString("host", source_host); 179 cast_mode_val->SetString("host", source_host);
180 value->Append(std::move(cast_mode_val)); 180 value->Append(std::move(cast_mode_val));
181 } 181 }
182 182
183 return value; 183 return value;
184 } 184 }
185 185
186 // Returns an Issue dictionary created from |issue| that can be used in WebUI. 186 // Returns an Issue dictionary created from |issue| that can be used in WebUI.
187 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { 187 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) {
188 const IssueInfo& issue_info = issue.info();
188 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 189 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
189 dictionary->SetString("id", issue.id()); 190 dictionary->SetInteger("id", issue.id());
190 dictionary->SetString("title", issue.title()); 191 dictionary->SetString("title", issue_info.title);
191 dictionary->SetString("message", issue.message()); 192 dictionary->SetString("message", issue_info.message);
192 dictionary->SetInteger("defaultActionType", issue.default_action().type()); 193 dictionary->SetInteger("defaultActionType",
193 if (!issue.secondary_actions().empty()) { 194 static_cast<int>(issue_info.default_action));
195 if (!issue_info.secondary_actions.empty()) {
194 dictionary->SetInteger("secondaryActionType", 196 dictionary->SetInteger("secondaryActionType",
195 issue.secondary_actions().begin()->type()); 197 static_cast<int>(issue_info.secondary_actions[0]));
196 } 198 }
197 if (!issue.route_id().empty()) 199 if (!issue_info.route_id.empty())
198 dictionary->SetString("routeId", issue.route_id()); 200 dictionary->SetString("routeId", issue_info.route_id);
199 dictionary->SetBoolean("isBlocking", issue.is_blocking()); 201 dictionary->SetBoolean("isBlocking", issue_info.is_blocking);
200 if (issue.help_page_id() > 0) 202 if (issue_info.help_page_id > 0)
201 dictionary->SetInteger("helpPageId", issue.help_page_id()); 203 dictionary->SetInteger("helpPageId", issue_info.help_page_id);
202 204
203 return dictionary; 205 return dictionary;
204 } 206 }
205 207
206 bool IsValidIssueActionTypeNum(int issue_action_type_num) { 208 bool IsValidIssueActionTypeNum(int issue_action_type_num) {
207 return issue_action_type_num >= 0 && 209 return issue_action_type_num >= 0 &&
208 issue_action_type_num < IssueAction::TYPE_MAX; 210 issue_action_type_num <
211 static_cast<int>(IssueInfo::Action::NUM_VALUES);
209 } 212 }
210 213
211 // Composes a "learn more" URL. The URL depends on template arguments in |args|. 214 // Composes a "learn more" URL. The URL depends on template arguments in |args|.
212 // Returns an empty string if |args| is invalid. 215 // Returns an empty string if |args| is invalid.
213 std::string GetLearnMoreUrl(const base::DictionaryValue* args) { 216 std::string GetLearnMoreUrl(const base::DictionaryValue* args) {
214 // TODO(imcheng): The template arguments for determining the learn more URL 217 // TODO(imcheng): The template arguments for determining the learn more URL
215 // should come from the Issue object in the browser, not from WebUI. 218 // should come from the Issue object in the browser, not from WebUI.
216 int help_page_id = -1; 219 int help_page_id = -1;
217 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) { 220 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) {
218 DVLOG(1) << "Invalid help page id."; 221 DVLOG(1) << "Invalid help page id.";
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 if (!IsValidCastModeNum(cast_mode_num)) { 448 if (!IsValidCastModeNum(cast_mode_num)) {
446 // TODO(imcheng): Record error condition with UMA. 449 // TODO(imcheng): Record error condition with UMA.
447 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; 450 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting.";
448 return; 451 return;
449 } 452 }
450 453
451 MediaRouterUI* media_router_ui = 454 MediaRouterUI* media_router_ui =
452 static_cast<MediaRouterUI*>(web_ui()->GetController()); 455 static_cast<MediaRouterUI*>(web_ui()->GetController());
453 if (media_router_ui->HasPendingRouteRequest()) { 456 if (media_router_ui->HasPendingRouteRequest()) {
454 DVLOG(1) << "UI already has pending route request. Ignoring."; 457 DVLOG(1) << "UI already has pending route request. Ignoring.";
455 Issue issue( 458 IssueInfo issue(
456 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), 459 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE),
457 std::string(), IssueAction(IssueAction::TYPE_DISMISS), 460 IssueInfo::Action::DISMISS, IssueInfo::Severity::NOTIFICATION);
458 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
459 false, -1);
460 media_router_ui_->AddIssue(issue); 461 media_router_ui_->AddIssue(issue);
461 return; 462 return;
462 } 463 }
463 464
464 DVLOG(2) << __func__ << ": sink id: " << sink_id 465 DVLOG(2) << __func__ << ": sink id: " << sink_id
465 << ", cast mode: " << cast_mode_num; 466 << ", cast mode: " << cast_mode_num;
466 467
467 // TODO(haibinlu): Pass additional parameters into the CreateRoute request, 468 // TODO(haibinlu): Pass additional parameters into the CreateRoute request,
468 // e.g. low-fps-mirror, user-override. (crbug.com/490364) 469 // e.g. low-fps-mirror, user-override. (crbug.com/490364)
469 if (!media_router_ui->CreateRoute( 470 if (!media_router_ui->CreateRoute(
(...skipping 22 matching lines...) Expand all
492 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true); 493 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true);
493 } 494 }
494 495
495 void MediaRouterWebUIMessageHandler::OnActOnIssue( 496 void MediaRouterWebUIMessageHandler::OnActOnIssue(
496 const base::ListValue* args) { 497 const base::ListValue* args) {
497 DVLOG(1) << "OnActOnIssue"; 498 DVLOG(1) << "OnActOnIssue";
498 const base::DictionaryValue* args_dict = nullptr; 499 const base::DictionaryValue* args_dict = nullptr;
499 Issue::Id issue_id; 500 Issue::Id issue_id;
500 int action_type_num = -1; 501 int action_type_num = -1;
501 if (!args->GetDictionary(0, &args_dict) || 502 if (!args->GetDictionary(0, &args_dict) ||
502 !args_dict->GetString("issueId", &issue_id) || 503 !args_dict->GetInteger("issueId", &issue_id) ||
503 !args_dict->GetInteger("actionType", &action_type_num)) { 504 !args_dict->GetInteger("actionType", &action_type_num)) {
504 DVLOG(1) << "Unable to extract args."; 505 DVLOG(1) << "Unable to extract args.";
505 return; 506 return;
506 } 507 }
507 if (!IsValidIssueActionTypeNum(action_type_num)) { 508 if (!IsValidIssueActionTypeNum(action_type_num)) {
508 DVLOG(1) << "Invalid action type: " << action_type_num; 509 DVLOG(1) << "Invalid action type: " << action_type_num;
509 return; 510 return;
510 } 511 }
511 IssueAction::Type action_type = 512 IssueInfo::Action action_type =
512 static_cast<IssueAction::Type>(action_type_num); 513 static_cast<IssueInfo::Action>(action_type_num);
513 if (ActOnIssueType(action_type, args_dict)) 514 if (ActOnIssueType(action_type, args_dict))
514 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; 515 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id;
515 media_router_ui_->ClearIssue(issue_id); 516 media_router_ui_->ClearIssue(issue_id);
516 } 517 }
517 518
518 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { 519 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) {
519 DVLOG(1) << "OnJoinRoute"; 520 DVLOG(1) << "OnJoinRoute";
520 const base::DictionaryValue* args_dict = nullptr; 521 const base::DictionaryValue* args_dict = nullptr;
521 std::string route_id; 522 std::string route_id;
522 std::string sink_id; 523 std::string sink_id;
(...skipping 13 matching lines...) Expand all
536 if (route_id.empty()) { 537 if (route_id.empty()) {
537 DVLOG(1) << "Media Route UI did not respond with a " 538 DVLOG(1) << "Media Route UI did not respond with a "
538 << "valid route ID. Aborting."; 539 << "valid route ID. Aborting.";
539 return; 540 return;
540 } 541 }
541 542
542 MediaRouterUI* media_router_ui = 543 MediaRouterUI* media_router_ui =
543 static_cast<MediaRouterUI*>(web_ui()->GetController()); 544 static_cast<MediaRouterUI*>(web_ui()->GetController());
544 if (media_router_ui->HasPendingRouteRequest()) { 545 if (media_router_ui->HasPendingRouteRequest()) {
545 DVLOG(1) << "UI already has pending route request. Ignoring."; 546 DVLOG(1) << "UI already has pending route request. Ignoring.";
546 Issue issue( 547 IssueInfo issue(
547 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), 548 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE),
548 std::string(), IssueAction(IssueAction::TYPE_DISMISS), 549 IssueInfo::Action::DISMISS, IssueInfo::Severity::NOTIFICATION);
549 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
550 false, -1);
551 media_router_ui_->AddIssue(issue); 550 media_router_ui_->AddIssue(issue);
552 return; 551 return;
553 } 552 }
554 553
555 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) { 554 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) {
556 DVLOG(1) << "Error initiating route join request."; 555 DVLOG(1) << "Error initiating route join request.";
557 } 556 }
558 } 557 }
559 558
560 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { 559 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 } 768 }
770 769
771 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( 770 void MediaRouterWebUIMessageHandler::OnInitialDataReceived(
772 const base::ListValue* args) { 771 const base::ListValue* args) {
773 DVLOG(1) << "OnInitialDataReceived"; 772 DVLOG(1) << "OnInitialDataReceived";
774 media_router_ui_->OnUIInitialDataReceived(); 773 media_router_ui_->OnUIInitialDataReceived();
775 MaybeUpdateFirstRunFlowData(); 774 MaybeUpdateFirstRunFlowData();
776 } 775 }
777 776
778 bool MediaRouterWebUIMessageHandler::ActOnIssueType( 777 bool MediaRouterWebUIMessageHandler::ActOnIssueType(
779 const IssueAction::Type& action_type, 778 IssueInfo::Action action_type,
780 const base::DictionaryValue* args) { 779 const base::DictionaryValue* args) {
781 if (action_type == IssueAction::TYPE_LEARN_MORE) { 780 if (action_type == IssueInfo::Action::LEARN_MORE) {
782 std::string learn_more_url = GetLearnMoreUrl(args); 781 std::string learn_more_url = GetLearnMoreUrl(args);
783 if (learn_more_url.empty()) 782 if (learn_more_url.empty())
784 return false; 783 return false;
785 std::unique_ptr<base::ListValue> open_args(new base::ListValue); 784 std::unique_ptr<base::ListValue> open_args(new base::ListValue);
786 open_args->AppendString(learn_more_url); 785 open_args->AppendString(learn_more_url);
787 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); 786 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args);
788 return true; 787 return true;
789 } else { 788 } else {
790 // Do nothing; no other issue action types require any other action. 789 // Do nothing; no other issue action types require any other action.
791 return true; 790 return true;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 } 879 }
881 880
882 return value; 881 return value;
883 } 882 }
884 883
885 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 884 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
886 set_web_ui(web_ui); 885 set_web_ui(web_ui);
887 } 886 }
888 887
889 } // namespace media_router 888 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698