1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/webui/welcome_handler_android.h"
8 #include "base/values.h"
9 #include "chrome/browser/android/chromium_application.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/sync/profile_sync_service_factory.h"
12 #include "content/public/browser/web_ui.h"
14 WelcomeHandler::WelcomeHandler()
15 : sync_service_(NULL
),
16 observer_manager_(this),
17 is_sync_footer_visible_(false) {}
19 WelcomeHandler::~WelcomeHandler() {}
21 void WelcomeHandler::RegisterMessages() {
22 web_ui()->RegisterMessageCallback(
23 "updateSyncFooterVisibility",
24 base::Bind(&WelcomeHandler::HandleUpdateSyncFooterVisibility
,
25 base::Unretained(this)));
27 web_ui()->RegisterMessageCallback(
29 base::Bind(&WelcomeHandler::HandleShowSyncSettings
,
30 base::Unretained(this)));
32 web_ui()->RegisterMessageCallback(
34 base::Bind(&WelcomeHandler::HandleShowTermsOfService
,
35 base::Unretained(this)));
37 // Register for callbacks
38 sync_service_
= ProfileSyncServiceFactory::GetInstance()->GetForProfile(
39 Profile::FromWebUI(web_ui()));
41 observer_manager_
.Add(sync_service_
);
44 void WelcomeHandler::HandleUpdateSyncFooterVisibility(
45 const base::ListValue
* args
) {
46 UpdateSyncFooterVisibility(true);
49 void WelcomeHandler::HandleShowSyncSettings(const base::ListValue
* args
) {
50 chrome::android::ChromiumApplication::ShowSyncSettings();
53 void WelcomeHandler::HandleShowTermsOfService(const base::ListValue
* args
) {
54 chrome::android::ChromiumApplication::ShowTermsOfServiceDialog();
57 void WelcomeHandler::OnStateChanged() {
58 UpdateSyncFooterVisibility(false);
61 void WelcomeHandler::UpdateSyncFooterVisibility(bool forced
) {
62 bool is_sync_enabled
=
63 sync_service_
&& sync_service_
->IsSyncEnabledAndLoggedIn();
65 if (forced
|| is_sync_footer_visible_
!= is_sync_enabled
) {
66 is_sync_footer_visible_
= is_sync_enabled
;
67 web_ui()->CallJavascriptFunction("welcome.setSyncFooterVisible",
68 base::FundamentalValue(is_sync_enabled
));