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

Unified Diff: chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc

Issue 7399015: Sync Promo: Add a way to collapse the sync promo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Promo: Add a way to collapse the sync promo Created 9 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h ('k') | chrome/browser/ui/webui/ntp/new_tab_ui.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
===================================================================
--- chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc (revision 93571)
+++ chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc (working copy)
@@ -5,22 +5,94 @@
#include "chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h"
#include "base/command_line.h"
+#include "chrome/browser/prefs/pref_notifier.h"
+#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/profile_sync_service.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "content/common/notification_details.h"
-void NewTabSyncSetupHandler::ShowSetupUI() {
+bool NewTabSyncSetupHandler::ShouldShowSyncPromo() {
+#if defined(OS_CHROMEOS)
+ // There's no need to show the sync promo on cros since cros users are logged
+ // into sync already.
+ return false;
+#endif
+
// Temporarily hide this feature behind a command line flag.
CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (!command_line->HasSwitch(switches::kSyncShowPromo))
+ return command_line->HasSwitch(switches::kSyncShowPromo);
+}
+
+WebUIMessageHandler* NewTabSyncSetupHandler::Attach(WebUI* web_ui) {
+ PrefService* pref_service = web_ui->GetProfile()->GetPrefs();
+ username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this);
+
+ return SyncSetupHandler::Attach(web_ui);
+}
+
+void NewTabSyncSetupHandler::RegisterMessages() {
+ web_ui_->RegisterMessageCallback("InitializeSyncPromo",
+ NewCallback(this, &NewTabSyncSetupHandler::HandleInitializeSyncPromo));
+ web_ui_->RegisterMessageCallback("CollapseSyncPromo",
+ NewCallback(this, &NewTabSyncSetupHandler::HandleCollapseSyncPromo));
+ web_ui_->RegisterMessageCallback("ExpandSyncPromo",
+ NewCallback(this, &NewTabSyncSetupHandler::HandleExpandSyncPromo));
+
+ SyncSetupHandler::RegisterMessages();
+}
+
+void NewTabSyncSetupHandler::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == chrome::NOTIFICATION_PREF_CHANGED) {
+ std::string* name = Details<std::string>(details).ptr();
+ if (prefs::kGoogleServicesUsername == *name) {
+ UpdateLogin();
+ return;
+ }
+ }
+ SyncSetupHandler::Observe(type, source, details);
+}
+
+void NewTabSyncSetupHandler::ShowSetupUI() {
+ ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService();
+ service->get_wizard().Step(SyncSetupWizard::GAIA_LOGIN);
+}
+
+void NewTabSyncSetupHandler::HandleInitializeSyncPromo(const ListValue* args) {
+ if (!ShouldShowSyncPromo())
return;
+ // Make sure the sync promo is visible.
+ web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.showSyncPromo");
+
+ UpdateLogin();
+
ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService();
DCHECK(service);
- // If they user has already synced then don't show anything.
- if (service->HasSyncSetupCompleted())
- return;
+ // If the user has not signed into sync then expand the sync promo.
+ // TODO(sail): Need to throttle this behind a server side flag.
+ if (!service->HasSyncSetupCompleted())
+ OpenSyncSetup();
+}
- service->get_wizard().Step(SyncSetupWizard::GAIA_LOGIN);
+void NewTabSyncSetupHandler::HandleCollapseSyncPromo(const ListValue* args) {
+ CloseSyncSetup();
}
+
+
+void NewTabSyncSetupHandler::HandleExpandSyncPromo(const ListValue* args) {
+ OpenSyncSetup();
+}
+
+void NewTabSyncSetupHandler::UpdateLogin() {
+ std::string username = web_ui_->GetProfile()->GetPrefs()->GetString(
+ prefs::kGoogleServicesUsername);
+ StringValue string_value(username);
+ web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.updateLogin",
+ string_value);
+}
« no previous file with comments | « chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.h ('k') | chrome/browser/ui/webui/ntp/new_tab_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698