| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/media/router/issue.h" | 17 #include "chrome/browser/media/router/issue.h" |
| 18 #include "chrome/browser/media/router/media_router_metrics.h" | 18 #include "chrome/browser/media/router/media_router_metrics.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | 22 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 21 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 22 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "components/browser_sync/profile_sync_service.h" |
| 23 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "components/signin/core/browser/signin_manager.h" |
| 24 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
| 25 #include "extensions/common/constants.h" | 29 #include "extensions/common/constants.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 27 | 31 |
| 28 #if defined(GOOGLE_CHROME_BUILD) | |
| 29 #include "chrome/browser/signin/signin_manager_factory.h" | |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 31 #include "components/browser_sync/profile_sync_service.h" | |
| 32 #include "components/signin/core/browser/signin_manager.h" | |
| 33 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 34 | 32 |
| 35 namespace media_router { | 33 namespace media_router { |
| 36 | 34 |
| 37 namespace { | 35 namespace { |
| 38 | 36 |
| 39 const char kCastLearnMorePageUrl[] = | 37 const char kCastLearnMorePageUrl[] = |
| 40 "https://www.google.com/chrome/devices/chromecast/learn.html"; | 38 "https://www.google.com/chrome/devices/chromecast/learn.html"; |
| 41 const char kHelpPageUrlPrefix[] = | 39 const char kHelpPageUrlPrefix[] = |
| 42 "https://support.google.com/chromecast/answer/%d"; | 40 "https://support.google.com/chromecast/answer/%d"; |
| 43 | 41 |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 DVLOG(1) << "Error initiating route request."; | 471 DVLOG(1) << "Error initiating route request."; |
| 474 } | 472 } |
| 475 } | 473 } |
| 476 | 474 |
| 477 void MediaRouterWebUIMessageHandler::OnAcknowledgeFirstRunFlow( | 475 void MediaRouterWebUIMessageHandler::OnAcknowledgeFirstRunFlow( |
| 478 const base::ListValue* args) { | 476 const base::ListValue* args) { |
| 479 DVLOG(1) << "OnAcknowledgeFirstRunFlow"; | 477 DVLOG(1) << "OnAcknowledgeFirstRunFlow"; |
| 480 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 478 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( |
| 481 prefs::kMediaRouterFirstRunFlowAcknowledged, true); | 479 prefs::kMediaRouterFirstRunFlowAcknowledged, true); |
| 482 | 480 |
| 483 #if defined(GOOGLE_CHROME_BUILD) | |
| 484 bool enabled_cloud_services = false; | 481 bool enabled_cloud_services = false; |
| 485 // Do not set the relevant cloud services prefs if the user was not shown | 482 // Do not set the relevant cloud services prefs if the user was not shown |
| 486 // the cloud services prompt. | 483 // the cloud services prompt. |
| 487 if (!args->GetBoolean(0, &enabled_cloud_services)) { | 484 if (!args->GetBoolean(0, &enabled_cloud_services)) { |
| 488 DVLOG(1) << "User was not shown the enable cloud services prompt."; | 485 DVLOG(1) << "User was not shown the enable cloud services prompt."; |
| 489 return; | 486 return; |
| 490 } | 487 } |
| 491 | 488 |
| 492 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 489 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 493 pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices, | 490 pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices, |
| 494 enabled_cloud_services); | 491 enabled_cloud_services); |
| 495 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true); | 492 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true); |
| 496 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 497 } | 493 } |
| 498 | 494 |
| 499 void MediaRouterWebUIMessageHandler::OnActOnIssue( | 495 void MediaRouterWebUIMessageHandler::OnActOnIssue( |
| 500 const base::ListValue* args) { | 496 const base::ListValue* args) { |
| 501 DVLOG(1) << "OnActOnIssue"; | 497 DVLOG(1) << "OnActOnIssue"; |
| 502 const base::DictionaryValue* args_dict = nullptr; | 498 const base::DictionaryValue* args_dict = nullptr; |
| 503 Issue::Id issue_id; | 499 Issue::Id issue_id; |
| 504 int action_type_num = -1; | 500 int action_type_num = -1; |
| 505 if (!args->GetDictionary(0, &args_dict) || | 501 if (!args->GetDictionary(0, &args_dict) || |
| 506 !args_dict->GetString("issueId", &issue_id) || | 502 !args_dict->GetString("issueId", &issue_id) || |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 | 794 |
| 799 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { | 795 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { |
| 800 base::DictionaryValue first_run_flow_data; | 796 base::DictionaryValue first_run_flow_data; |
| 801 | 797 |
| 802 Profile* profile = Profile::FromWebUI(web_ui()); | 798 Profile* profile = Profile::FromWebUI(web_ui()); |
| 803 PrefService* pref_service = profile->GetPrefs(); | 799 PrefService* pref_service = profile->GetPrefs(); |
| 804 | 800 |
| 805 bool first_run_flow_acknowledged = | 801 bool first_run_flow_acknowledged = |
| 806 pref_service->GetBoolean(prefs::kMediaRouterFirstRunFlowAcknowledged); | 802 pref_service->GetBoolean(prefs::kMediaRouterFirstRunFlowAcknowledged); |
| 807 bool show_cloud_pref = false; | 803 bool show_cloud_pref = false; |
| 808 #if defined(GOOGLE_CHROME_BUILD) | |
| 809 // Cloud services preference is shown if user is logged in. If the user | 804 // Cloud services preference is shown if user is logged in. If the user |
| 810 // enables sync after acknowledging the first run flow, this is treated as | 805 // enables sync after acknowledging the first run flow, this is treated as |
| 811 // the user opting into Google services, including cloud services, if the | 806 // the user opting into Google services, including cloud services, if the |
| 812 // browser is a Chrome branded build. | 807 // browser is a Chrome branded build. |
| 813 if (!pref_service->GetBoolean(prefs::kMediaRouterCloudServicesPrefSet)) { | 808 if (!pref_service->GetBoolean(prefs::kMediaRouterCloudServicesPrefSet)) { |
| 814 SigninManagerBase* signin_manager = | 809 SigninManagerBase* signin_manager = |
| 815 SigninManagerFactory::GetForProfile(profile); | 810 SigninManagerFactory::GetForProfile(profile); |
| 816 if (signin_manager && signin_manager->IsAuthenticated()) { | 811 if (signin_manager && signin_manager->IsAuthenticated()) { |
| 817 // If the user had previously acknowledged the first run flow without | 812 // If the user had previously acknowledged the first run flow without |
| 818 // being shown the cloud services option, and is now logged in with sync | 813 // being shown the cloud services option, and is now logged in with sync |
| 819 // enabled, turn on cloud services. | 814 // enabled, turn on cloud services. |
| 820 if (first_run_flow_acknowledged && | 815 if (first_run_flow_acknowledged && |
| 821 ProfileSyncServiceFactory::GetForProfile(profile)->IsSyncActive()) { | 816 ProfileSyncServiceFactory::GetForProfile(profile)->IsSyncActive()) { |
| 822 pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices, true); | 817 pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices, true); |
| 823 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, | 818 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, |
| 824 true); | 819 true); |
| 825 // Return early since the first run flow won't be surfaced. | 820 // Return early since the first run flow won't be surfaced. |
| 826 return; | 821 return; |
| 827 } | 822 } |
| 828 | 823 |
| 829 show_cloud_pref = true; | 824 show_cloud_pref = true; |
| 830 // "Casting to a Hangout from Chrome" Chromecast help center page. | 825 // "Casting to a Hangout from Chrome" Chromecast help center page. |
| 831 first_run_flow_data.SetString("firstRunFlowCloudPrefLearnMoreUrl", | 826 first_run_flow_data.SetString("firstRunFlowCloudPrefLearnMoreUrl", |
| 832 base::StringPrintf(kHelpPageUrlPrefix, 6320939)); | 827 base::StringPrintf(kHelpPageUrlPrefix, 6320939)); |
| 833 } | 828 } |
| 834 } | 829 } |
| 835 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 836 | 830 |
| 837 // Return early if the first run flow won't be surfaced. | 831 // Return early if the first run flow won't be surfaced. |
| 838 if (first_run_flow_acknowledged && !show_cloud_pref) | 832 if (first_run_flow_acknowledged && !show_cloud_pref) |
| 839 return; | 833 return; |
| 840 | 834 |
| 841 // General Chromecast learn more page. | 835 // General Chromecast learn more page. |
| 842 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", | 836 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", |
| 843 kCastLearnMorePageUrl); | 837 kCastLearnMorePageUrl); |
| 844 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", | 838 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", |
| 845 first_run_flow_acknowledged); | 839 first_run_flow_acknowledged); |
| 846 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); | 840 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); |
| 847 web_ui()->CallJavascriptFunctionUnsafe(kSetFirstRunFlowData, | 841 web_ui()->CallJavascriptFunctionUnsafe(kSetFirstRunFlowData, |
| 848 first_run_flow_data); | 842 first_run_flow_data); |
| 849 } | 843 } |
| 850 | 844 |
| 851 AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { | 845 AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { |
| 852 #if defined(GOOGLE_CHROME_BUILD) | |
| 853 SigninManagerBase* signin_manager = | 846 SigninManagerBase* signin_manager = |
| 854 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 847 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 855 if (signin_manager) | 848 return signin_manager ? signin_manager->GetAuthenticatedAccountInfo() |
| 856 return signin_manager->GetAuthenticatedAccountInfo(); | 849 : AccountInfo(); |
| 857 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 858 | |
| 859 return AccountInfo(); | |
| 860 } | 850 } |
| 861 | 851 |
| 862 int MediaRouterWebUIMessageHandler::CurrentCastModeForRouteId( | 852 int MediaRouterWebUIMessageHandler::CurrentCastModeForRouteId( |
| 863 const MediaRoute::Id& route_id, | 853 const MediaRoute::Id& route_id, |
| 864 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes) | 854 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes) |
| 865 const { | 855 const { |
| 866 auto current_cast_mode_entry = current_cast_modes.find(route_id); | 856 auto current_cast_mode_entry = current_cast_modes.find(route_id); |
| 867 int current_cast_mode = current_cast_mode_entry != current_cast_modes.end() | 857 int current_cast_mode = current_cast_mode_entry != current_cast_modes.end() |
| 868 ? current_cast_mode_entry->second | 858 ? current_cast_mode_entry->second |
| 869 : -1; | 859 : -1; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 890 } | 880 } |
| 891 | 881 |
| 892 return value; | 882 return value; |
| 893 } | 883 } |
| 894 | 884 |
| 895 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 885 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 896 set_web_ui(web_ui); | 886 set_web_ui(web_ui); |
| 897 } | 887 } |
| 898 | 888 |
| 899 } // namespace media_router | 889 } // namespace media_router |
| OLD | NEW |