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

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: remove extra changes 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
Index: chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc b/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
index 38fa6d8e6a8daa0d83c74465dec975723bf9321a..3c20e21784640448b3091c71edee700985ef4ef4 100644
--- a/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
+++ b/chrome/browser/ui/webui/ntp/new_tab_sync_setup_handler.cc
@@ -5,22 +5,92 @@
#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"
+
+WebUIMessageHandler* NewTabSyncSetupHandler::Attach(WebUI* web_ui) {
James Hawkins 2011/07/18 02:37:36 Ordering in implementation should match the orderi
sail 2011/07/20 01:30:46 Done.
+ 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);
+}
+
+bool NewTabSyncSetupHandler::ShouldShowSyncPromo() {
+#if defined(OS_CHROMEOS)
James Hawkins 2011/07/18 02:37:36 Document why this is ifdef'ed out on cros.
sail 2011/07/20 01:30:46 Done.
+ 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);
+}
+
+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);
+}
+
+void NewTabSyncSetupHandler::HandleInitializeSyncPromo(const ListValue* args) {
+ if (!ShouldShowSyncPromo())
return;
+ // Make sure the sync promo is visible.
+ web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.showSynPromo");
+
+ 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();
}

Powered by Google App Engine
This is Rietveld 408576698