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/ui/webui/media_router/media_router_ui.h" | 20 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
23 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
24 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
25 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
27 | 27 |
28 #if defined(GOOGLE_CHROME_BUILD) | 28 #if defined(GOOGLE_CHROME_BUILD) |
29 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 30 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 31 #include "components/browser_sync/browser/profile_sync_service.h" |
30 #include "components/signin/core/browser/signin_manager.h" | 32 #include "components/signin/core/browser/signin_manager.h" |
31 #endif // defined(GOOGLE_CHROME_BUILD) | 33 #endif // defined(GOOGLE_CHROME_BUILD) |
32 | 34 |
33 namespace media_router { | 35 namespace media_router { |
34 | 36 |
35 namespace { | 37 namespace { |
36 | 38 |
37 const char kCastLearnMorePageUrl[] = | 39 const char kCastLearnMorePageUrl[] = |
38 "https://www.google.com/chrome/devices/chromecast/learn.html"; | 40 "https://www.google.com/chrome/devices/chromecast/learn.html"; |
39 const char kHelpPageUrlPrefix[] = | 41 const char kHelpPageUrlPrefix[] = |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { | 799 void MediaRouterWebUIMessageHandler::MaybeUpdateFirstRunFlowData() { |
798 base::DictionaryValue first_run_flow_data; | 800 base::DictionaryValue first_run_flow_data; |
799 | 801 |
800 Profile* profile = Profile::FromWebUI(web_ui()); | 802 Profile* profile = Profile::FromWebUI(web_ui()); |
801 PrefService* pref_service = profile->GetPrefs(); | 803 PrefService* pref_service = profile->GetPrefs(); |
802 | 804 |
803 bool first_run_flow_acknowledged = | 805 bool first_run_flow_acknowledged = |
804 pref_service->GetBoolean(prefs::kMediaRouterFirstRunFlowAcknowledged); | 806 pref_service->GetBoolean(prefs::kMediaRouterFirstRunFlowAcknowledged); |
805 bool show_cloud_pref = false; | 807 bool show_cloud_pref = false; |
806 #if defined(GOOGLE_CHROME_BUILD) | 808 #if defined(GOOGLE_CHROME_BUILD) |
807 // Cloud services preference is shown if user is logged in. If the user | 809 // Cloud services preference is shown if user is logged in and has sync |
808 // enables sync after acknowledging the first run flow, this is treated as | 810 // enabled. If the user enables sync after acknowledging the first run flow, |
809 // the user opting into Google services, including cloud services, if the | 811 // this is treated as the user opting into Google services, including cloud |
810 // browser is a Chrome branded build. | 812 // services, if the browser is a Chrome branded build. |
811 if (!pref_service->GetBoolean(prefs::kMediaRouterCloudServicesPrefSet)) { | 813 if (!pref_service->GetBoolean(prefs::kMediaRouterCloudServicesPrefSet) && |
| 814 profile->IsSyncAllowed()) { |
812 SigninManagerBase* signin_manager = | 815 SigninManagerBase* signin_manager = |
813 SigninManagerFactory::GetForProfile(profile); | 816 SigninManagerFactory::GetForProfile(profile); |
814 if (signin_manager && signin_manager->IsAuthenticated()) { | 817 if (signin_manager && signin_manager->IsAuthenticated() && |
| 818 ProfileSyncServiceFactory::GetForProfile(profile)->IsSyncActive()) { |
815 // If the user had previously acknowledged the first run flow without | 819 // If the user had previously acknowledged the first run flow without |
816 // being shown the cloud services option, and is now logged in with sync | 820 // being shown the cloud services option, and is now logged in with sync |
817 // enabled, turn on cloud services. | 821 // enabled, turn on cloud services. |
818 if (first_run_flow_acknowledged && | 822 if (first_run_flow_acknowledged) { |
819 ProfileSyncServiceFactory::GetForProfile(profile)->IsSyncActive()) { | |
820 pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices, true); | 823 pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices, true); |
821 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, | 824 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, |
822 true); | 825 true); |
823 // Return early since the first run flow won't be surfaced. | 826 // Return early since the first run flow won't be surfaced. |
824 return; | 827 return; |
825 } | 828 } |
826 | 829 |
827 show_cloud_pref = true; | 830 show_cloud_pref = true; |
828 // "Casting to a Hangout from Chrome" Chromecast help center page. | 831 // "Casting to a Hangout from Chrome" Chromecast help center page. |
829 first_run_flow_data.SetString("firstRunFlowCloudPrefLearnMoreUrl", | 832 first_run_flow_data.SetString("firstRunFlowCloudPrefLearnMoreUrl", |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 } | 890 } |
888 | 891 |
889 return value; | 892 return value; |
890 } | 893 } |
891 | 894 |
892 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 895 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
893 set_web_ui(web_ui); | 896 set_web_ui(web_ui); |
894 } | 897 } |
895 | 898 |
896 } // namespace media_router | 899 } // namespace media_router |
OLD | NEW |