OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ntp/new_tab_sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/prefs/pref_notifier.h" | 8 #include "chrome/browser/prefs/pref_notifier.h" |
9 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // into sync already. | 26 // into sync already. |
27 return false; | 27 return false; |
28 #endif | 28 #endif |
29 | 29 |
30 // Temporarily hide this feature behind a command line flag. | 30 // Temporarily hide this feature behind a command line flag. |
31 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 31 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
32 return command_line->HasSwitch(switches::kSyncShowPromo); | 32 return command_line->HasSwitch(switches::kSyncShowPromo); |
33 } | 33 } |
34 | 34 |
35 WebUIMessageHandler* NewTabSyncSetupHandler::Attach(WebUI* web_ui) { | 35 WebUIMessageHandler* NewTabSyncSetupHandler::Attach(WebUI* web_ui) { |
36 PrefService* pref_service = web_ui->GetProfile()->GetPrefs(); | 36 PrefService* pref_service = Profile::FromWebUI(web_ui)->GetPrefs(); |
37 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); | 37 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); |
38 | 38 |
39 return SyncSetupHandler::Attach(web_ui); | 39 return SyncSetupHandler::Attach(web_ui); |
40 } | 40 } |
41 | 41 |
42 void NewTabSyncSetupHandler::RegisterMessages() { | 42 void NewTabSyncSetupHandler::RegisterMessages() { |
43 web_ui_->RegisterMessageCallback("InitializeSyncPromo", | 43 web_ui_->RegisterMessageCallback("InitializeSyncPromo", |
44 NewCallback(this, &NewTabSyncSetupHandler::HandleInitializeSyncPromo)); | 44 NewCallback(this, &NewTabSyncSetupHandler::HandleInitializeSyncPromo)); |
45 web_ui_->RegisterMessageCallback("CollapseSyncPromo", | 45 web_ui_->RegisterMessageCallback("CollapseSyncPromo", |
46 NewCallback(this, &NewTabSyncSetupHandler::HandleCollapseSyncPromo)); | 46 NewCallback(this, &NewTabSyncSetupHandler::HandleCollapseSyncPromo)); |
(...skipping 10 matching lines...) Expand all Loading... |
57 std::string* name = Details<std::string>(details).ptr(); | 57 std::string* name = Details<std::string>(details).ptr(); |
58 if (prefs::kGoogleServicesUsername == *name) { | 58 if (prefs::kGoogleServicesUsername == *name) { |
59 UpdateLogin(); | 59 UpdateLogin(); |
60 return; | 60 return; |
61 } | 61 } |
62 } | 62 } |
63 SyncSetupHandler::Observe(type, source, details); | 63 SyncSetupHandler::Observe(type, source, details); |
64 } | 64 } |
65 | 65 |
66 void NewTabSyncSetupHandler::ShowSetupUI() { | 66 void NewTabSyncSetupHandler::ShowSetupUI() { |
67 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | 67 ProfileSyncService* service = |
| 68 Profile::FromWebUI(web_ui_)->GetProfileSyncService(); |
68 service->get_wizard().Step(SyncSetupWizard::GetLoginState()); | 69 service->get_wizard().Step(SyncSetupWizard::GetLoginState()); |
69 } | 70 } |
70 | 71 |
71 void NewTabSyncSetupHandler::HandleInitializeSyncPromo(const ListValue* args) { | 72 void NewTabSyncSetupHandler::HandleInitializeSyncPromo(const ListValue* args) { |
72 if (!ShouldShowSyncPromo()) | 73 if (!ShouldShowSyncPromo()) |
73 return; | 74 return; |
74 | 75 |
75 // Make sure the sync promo is visible. | 76 // Make sure the sync promo is visible. |
76 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.showSyncPromo"); | 77 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.showSyncPromo"); |
77 | 78 |
78 UpdateLogin(); | 79 UpdateLogin(); |
79 | 80 |
80 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | 81 Profile* profile = Profile::FromWebUI(web_ui_); |
| 82 ProfileSyncService* service = profile->GetProfileSyncService(); |
81 DCHECK(service); | 83 DCHECK(service); |
82 | 84 |
83 // If the user has not signed into sync then expand the sync promo. | 85 // If the user has not signed into sync then expand the sync promo. |
84 // TODO(sail): Need to throttle this behind a server side flag. | 86 // TODO(sail): Need to throttle this behind a server side flag. |
85 if (!service->HasSyncSetupCompleted() && | 87 if (!service->HasSyncSetupCompleted() && |
86 web_ui_->GetProfile()->GetPrefs()->GetBoolean( | 88 profile->GetPrefs()->GetBoolean(prefs::kSyncPromoExpanded)) { |
87 prefs::kSyncPromoExpanded)) { | |
88 OpenSyncSetup(); | 89 OpenSyncSetup(); |
89 SaveExpandedPreference(true); | 90 SaveExpandedPreference(true); |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 void NewTabSyncSetupHandler::HandleCollapseSyncPromo(const ListValue* args) { | 94 void NewTabSyncSetupHandler::HandleCollapseSyncPromo(const ListValue* args) { |
94 CloseSyncSetup(); | 95 CloseSyncSetup(); |
95 SaveExpandedPreference(false); | 96 SaveExpandedPreference(false); |
96 } | 97 } |
97 | 98 |
98 | 99 |
99 void NewTabSyncSetupHandler::HandleExpandSyncPromo(const ListValue* args) { | 100 void NewTabSyncSetupHandler::HandleExpandSyncPromo(const ListValue* args) { |
100 OpenSyncSetup(); | 101 OpenSyncSetup(); |
101 SaveExpandedPreference(true); | 102 SaveExpandedPreference(true); |
102 } | 103 } |
103 | 104 |
104 void NewTabSyncSetupHandler::UpdateLogin() { | 105 void NewTabSyncSetupHandler::UpdateLogin() { |
105 std::string username = web_ui_->GetProfile()->GetPrefs()->GetString( | 106 std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString( |
106 prefs::kGoogleServicesUsername); | 107 prefs::kGoogleServicesUsername); |
107 StringValue string_value(username); | 108 StringValue string_value(username); |
108 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.updateLogin", | 109 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.updateLogin", |
109 string_value); | 110 string_value); |
110 } | 111 } |
111 | 112 |
112 void NewTabSyncSetupHandler::SaveExpandedPreference(bool is_expanded) { | 113 void NewTabSyncSetupHandler::SaveExpandedPreference(bool is_expanded) { |
113 web_ui_->GetProfile()->GetPrefs()->SetBoolean(prefs::kSyncPromoExpanded, | 114 Profile* profile = Profile::FromWebUI(web_ui_); |
114 is_expanded); | 115 profile->GetPrefs()->SetBoolean(prefs::kSyncPromoExpanded, is_expanded); |
115 web_ui_->GetProfile()->GetPrefs()->ScheduleSavePersistentPrefs(); | 116 profile->GetPrefs()->ScheduleSavePersistentPrefs(); |
116 } | 117 } |
OLD | NEW |