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

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: IssueObserver init behavior and use StructTraits Created 4 years, 2 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 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 "description", MediaCastModeToDescription(cast_mode, source_host)); 180 "description", MediaCastModeToDescription(cast_mode, source_host));
181 cast_mode_val->SetString("host", source_host); 181 cast_mode_val->SetString("host", source_host);
182 value->Append(std::move(cast_mode_val)); 182 value->Append(std::move(cast_mode_val));
183 } 183 }
184 184
185 return value; 185 return value;
186 } 186 }
187 187
188 // Returns an Issue dictionary created from |issue| that can be used in WebUI. 188 // Returns an Issue dictionary created from |issue| that can be used in WebUI.
189 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) { 189 std::unique_ptr<base::DictionaryValue> IssueToValue(const Issue& issue) {
190 const IssueInfo& issue_info = issue.info();
190 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 191 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
191 dictionary->SetString("id", issue.id()); 192 dictionary->SetInteger("id", issue.id());
192 dictionary->SetString("title", issue.title()); 193 dictionary->SetString("title", issue_info.title);
193 dictionary->SetString("message", issue.message()); 194 dictionary->SetString("message", issue_info.message);
194 dictionary->SetInteger("defaultActionType", issue.default_action().type()); 195 dictionary->SetInteger("defaultActionType",
195 if (!issue.secondary_actions().empty()) { 196 static_cast<int>(issue_info.default_action));
197 if (!issue_info.secondary_actions.empty()) {
196 dictionary->SetInteger("secondaryActionType", 198 dictionary->SetInteger("secondaryActionType",
197 issue.secondary_actions().begin()->type()); 199 static_cast<int>(issue_info.secondary_actions[0]));
198 } 200 }
199 if (!issue.route_id().empty()) 201 if (!issue_info.route_id.empty())
200 dictionary->SetString("routeId", issue.route_id()); 202 dictionary->SetString("routeId", issue_info.route_id);
201 dictionary->SetBoolean("isBlocking", issue.is_blocking()); 203 dictionary->SetBoolean("isBlocking", issue_info.is_blocking);
202 if (issue.help_page_id() > 0) 204 if (issue_info.help_page_id > 0)
203 dictionary->SetInteger("helpPageId", issue.help_page_id()); 205 dictionary->SetInteger("helpPageId", issue_info.help_page_id);
204 206
205 return dictionary; 207 return dictionary;
206 } 208 }
207 209
208 bool IsValidIssueActionTypeNum(int issue_action_type_num) { 210 bool IsValidIssueActionTypeNum(int issue_action_type_num) {
209 return issue_action_type_num >= 0 && 211 return issue_action_type_num >= 0 &&
210 issue_action_type_num < IssueAction::TYPE_MAX; 212 issue_action_type_num <
213 static_cast<int>(IssueInfo::Action::NUM_VALUES);
211 } 214 }
212 215
213 // Composes a "learn more" URL. The URL depends on template arguments in |args|. 216 // Composes a "learn more" URL. The URL depends on template arguments in |args|.
214 // Returns an empty string if |args| is invalid. 217 // Returns an empty string if |args| is invalid.
215 std::string GetLearnMoreUrl(const base::DictionaryValue* args) { 218 std::string GetLearnMoreUrl(const base::DictionaryValue* args) {
216 // TODO(imcheng): The template arguments for determining the learn more URL 219 // TODO(imcheng): The template arguments for determining the learn more URL
217 // should come from the Issue object in the browser, not from WebUI. 220 // should come from the Issue object in the browser, not from WebUI.
218 int help_page_id = -1; 221 int help_page_id = -1;
219 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) { 222 if (!args->GetInteger("helpPageId", &help_page_id) || help_page_id < 0) {
220 DVLOG(1) << "Invalid help page id."; 223 DVLOG(1) << "Invalid help page id.";
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (!IsValidCastModeNum(cast_mode_num)) { 450 if (!IsValidCastModeNum(cast_mode_num)) {
448 // TODO(imcheng): Record error condition with UMA. 451 // TODO(imcheng): Record error condition with UMA.
449 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting."; 452 DVLOG(1) << "Invalid cast mode: " << cast_mode_num << ". Aborting.";
450 return; 453 return;
451 } 454 }
452 455
453 MediaRouterUI* media_router_ui = 456 MediaRouterUI* media_router_ui =
454 static_cast<MediaRouterUI*>(web_ui()->GetController()); 457 static_cast<MediaRouterUI*>(web_ui()->GetController());
455 if (media_router_ui->HasPendingRouteRequest()) { 458 if (media_router_ui->HasPendingRouteRequest()) {
456 DVLOG(1) << "UI already has pending route request. Ignoring."; 459 DVLOG(1) << "UI already has pending route request. Ignoring.";
457 Issue issue( 460 IssueInfo issue(
458 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), 461 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE),
459 std::string(), IssueAction(IssueAction::TYPE_DISMISS), 462 IssueInfo::Action::DISMISS, IssueInfo::Severity::NOTIFICATION);
460 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
461 false, -1);
462 media_router_ui_->AddIssue(issue); 463 media_router_ui_->AddIssue(issue);
463 return; 464 return;
464 } 465 }
465 466
466 DVLOG(2) << __func__ << ": sink id: " << sink_id 467 DVLOG(2) << __func__ << ": sink id: " << sink_id
467 << ", cast mode: " << cast_mode_num; 468 << ", cast mode: " << cast_mode_num;
468 469
469 // TODO(haibinlu): Pass additional parameters into the CreateRoute request, 470 // TODO(haibinlu): Pass additional parameters into the CreateRoute request,
470 // e.g. low-fps-mirror, user-override. (crbug.com/490364) 471 // e.g. low-fps-mirror, user-override. (crbug.com/490364)
471 if (!media_router_ui->CreateRoute( 472 if (!media_router_ui->CreateRoute(
(...skipping 24 matching lines...) Expand all
496 #endif // defined(GOOGLE_CHROME_BUILD) 497 #endif // defined(GOOGLE_CHROME_BUILD)
497 } 498 }
498 499
499 void MediaRouterWebUIMessageHandler::OnActOnIssue( 500 void MediaRouterWebUIMessageHandler::OnActOnIssue(
500 const base::ListValue* args) { 501 const base::ListValue* args) {
501 DVLOG(1) << "OnActOnIssue"; 502 DVLOG(1) << "OnActOnIssue";
502 const base::DictionaryValue* args_dict = nullptr; 503 const base::DictionaryValue* args_dict = nullptr;
503 Issue::Id issue_id; 504 Issue::Id issue_id;
504 int action_type_num = -1; 505 int action_type_num = -1;
505 if (!args->GetDictionary(0, &args_dict) || 506 if (!args->GetDictionary(0, &args_dict) ||
506 !args_dict->GetString("issueId", &issue_id) || 507 !args_dict->GetInteger("issueId", &issue_id) ||
507 !args_dict->GetInteger("actionType", &action_type_num)) { 508 !args_dict->GetInteger("actionType", &action_type_num)) {
508 DVLOG(1) << "Unable to extract args."; 509 DVLOG(1) << "Unable to extract args.";
509 return; 510 return;
510 } 511 }
511 if (!IsValidIssueActionTypeNum(action_type_num)) { 512 if (!IsValidIssueActionTypeNum(action_type_num)) {
512 DVLOG(1) << "Invalid action type: " << action_type_num; 513 DVLOG(1) << "Invalid action type: " << action_type_num;
513 return; 514 return;
514 } 515 }
515 IssueAction::Type action_type = 516 IssueInfo::Action action_type =
516 static_cast<IssueAction::Type>(action_type_num); 517 static_cast<IssueInfo::Action>(action_type_num);
517 if (ActOnIssueType(action_type, args_dict)) 518 if (ActOnIssueType(action_type, args_dict))
518 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id; 519 DVLOG(1) << "ActOnIssueType failed for Issue ID " << issue_id;
519 media_router_ui_->ClearIssue(issue_id); 520 media_router_ui_->ClearIssue(issue_id);
520 } 521 }
521 522
522 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) { 523 void MediaRouterWebUIMessageHandler::OnJoinRoute(const base::ListValue* args) {
523 DVLOG(1) << "OnJoinRoute"; 524 DVLOG(1) << "OnJoinRoute";
524 const base::DictionaryValue* args_dict = nullptr; 525 const base::DictionaryValue* args_dict = nullptr;
525 std::string route_id; 526 std::string route_id;
526 std::string sink_id; 527 std::string sink_id;
(...skipping 13 matching lines...) Expand all
540 if (route_id.empty()) { 541 if (route_id.empty()) {
541 DVLOG(1) << "Media Route UI did not respond with a " 542 DVLOG(1) << "Media Route UI did not respond with a "
542 << "valid route ID. Aborting."; 543 << "valid route ID. Aborting.";
543 return; 544 return;
544 } 545 }
545 546
546 MediaRouterUI* media_router_ui = 547 MediaRouterUI* media_router_ui =
547 static_cast<MediaRouterUI*>(web_ui()->GetController()); 548 static_cast<MediaRouterUI*>(web_ui()->GetController());
548 if (media_router_ui->HasPendingRouteRequest()) { 549 if (media_router_ui->HasPendingRouteRequest()) {
549 DVLOG(1) << "UI already has pending route request. Ignoring."; 550 DVLOG(1) << "UI already has pending route request. Ignoring.";
550 Issue issue( 551 IssueInfo issue(
551 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), 552 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE),
552 std::string(), IssueAction(IssueAction::TYPE_DISMISS), 553 IssueInfo::Action::DISMISS, IssueInfo::Severity::NOTIFICATION);
553 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
554 false, -1);
555 media_router_ui_->AddIssue(issue); 554 media_router_ui_->AddIssue(issue);
556 return; 555 return;
557 } 556 }
558 557
559 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) { 558 if (!media_router_ui_->ConnectRoute(sink_id, route_id)) {
560 DVLOG(1) << "Error initiating route join request."; 559 DVLOG(1) << "Error initiating route join request.";
561 } 560 }
562 } 561 }
563 562
564 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) { 563 void MediaRouterWebUIMessageHandler::OnCloseRoute(const base::ListValue* args) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 772 }
774 773
775 void MediaRouterWebUIMessageHandler::OnInitialDataReceived( 774 void MediaRouterWebUIMessageHandler::OnInitialDataReceived(
776 const base::ListValue* args) { 775 const base::ListValue* args) {
777 DVLOG(1) << "OnInitialDataReceived"; 776 DVLOG(1) << "OnInitialDataReceived";
778 media_router_ui_->OnUIInitialDataReceived(); 777 media_router_ui_->OnUIInitialDataReceived();
779 MaybeUpdateFirstRunFlowData(); 778 MaybeUpdateFirstRunFlowData();
780 } 779 }
781 780
782 bool MediaRouterWebUIMessageHandler::ActOnIssueType( 781 bool MediaRouterWebUIMessageHandler::ActOnIssueType(
783 const IssueAction::Type& action_type, 782 IssueInfo::Action action_type,
784 const base::DictionaryValue* args) { 783 const base::DictionaryValue* args) {
785 if (action_type == IssueAction::TYPE_LEARN_MORE) { 784 if (action_type == IssueInfo::Action::LEARN_MORE) {
786 std::string learn_more_url = GetLearnMoreUrl(args); 785 std::string learn_more_url = GetLearnMoreUrl(args);
787 if (learn_more_url.empty()) 786 if (learn_more_url.empty())
788 return false; 787 return false;
789 std::unique_ptr<base::ListValue> open_args(new base::ListValue); 788 std::unique_ptr<base::ListValue> open_args(new base::ListValue);
790 open_args->AppendString(learn_more_url); 789 open_args->AppendString(learn_more_url);
791 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args); 790 web_ui()->CallJavascriptFunctionUnsafe(kWindowOpen, *open_args);
792 return true; 791 return true;
793 } else { 792 } else {
794 // Do nothing; no other issue action types require any other action. 793 // Do nothing; no other issue action types require any other action.
795 return true; 794 return true;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } 889 }
891 890
892 return value; 891 return value;
893 } 892 }
894 893
895 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 894 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
896 set_web_ui(web_ui); 895 set_web_ui(web_ui);
897 } 896 }
898 897
899 } // namespace media_router 898 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698