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" | |
9 #include "chrome/browser/prefs/pref_service.h" | |
8 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/sync/profile_sync_service.h" | 11 #include "chrome/browser/sync/profile_sync_service.h" |
12 #include "chrome/common/chrome_notification_types.h" | |
10 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/pref_names.h" | |
15 #include "content/common/notification_details.h" | |
16 | |
17 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.
| |
18 PrefService* pref_service = web_ui->GetProfile()->GetPrefs(); | |
19 username_pref_.Init(prefs::kGoogleServicesUsername, pref_service, this); | |
20 | |
21 return SyncSetupHandler::Attach(web_ui); | |
22 } | |
23 | |
24 void NewTabSyncSetupHandler::RegisterMessages() { | |
25 web_ui_->RegisterMessageCallback("InitializeSyncPromo", | |
26 NewCallback(this, &NewTabSyncSetupHandler::HandleInitializeSyncPromo)); | |
27 web_ui_->RegisterMessageCallback("CollapseSyncPromo", | |
28 NewCallback(this, &NewTabSyncSetupHandler::HandleCollapseSyncPromo)); | |
29 web_ui_->RegisterMessageCallback("ExpandSyncPromo", | |
30 NewCallback(this, &NewTabSyncSetupHandler::HandleExpandSyncPromo)); | |
31 | |
32 SyncSetupHandler::RegisterMessages(); | |
33 } | |
34 | |
35 void NewTabSyncSetupHandler::Observe(int type, | |
36 const NotificationSource& source, | |
37 const NotificationDetails& details) { | |
38 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | |
39 std::string* name = Details<std::string>(details).ptr(); | |
40 if (prefs::kGoogleServicesUsername == *name) { | |
41 UpdateLogin(); | |
42 return; | |
43 } | |
44 } | |
45 SyncSetupHandler::Observe(type, source, details); | |
46 } | |
11 | 47 |
12 void NewTabSyncSetupHandler::ShowSetupUI() { | 48 void NewTabSyncSetupHandler::ShowSetupUI() { |
49 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | |
50 service->get_wizard().Step(SyncSetupWizard::GAIA_LOGIN); | |
51 } | |
52 | |
53 bool NewTabSyncSetupHandler::ShouldShowSyncPromo() { | |
54 #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.
| |
55 return false; | |
56 #endif | |
57 | |
13 // Temporarily hide this feature behind a command line flag. | 58 // Temporarily hide this feature behind a command line flag. |
14 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 59 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
15 if (!command_line->HasSwitch(switches::kSyncShowPromo)) | 60 return command_line->HasSwitch(switches::kSyncShowPromo); |
61 } | |
62 | |
63 void NewTabSyncSetupHandler::UpdateLogin() { | |
64 std::string username = web_ui_->GetProfile()->GetPrefs()->GetString( | |
65 prefs::kGoogleServicesUsername); | |
66 StringValue string_value(username); | |
67 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.updateLogin", | |
68 string_value); | |
69 } | |
70 | |
71 void NewTabSyncSetupHandler::HandleInitializeSyncPromo(const ListValue* args) { | |
72 if (!ShouldShowSyncPromo()) | |
16 return; | 73 return; |
17 | 74 |
75 // Make sure the sync promo is visible. | |
76 web_ui_->CallJavascriptFunction("new_tab.NewTabSyncPromo.showSynPromo"); | |
77 | |
78 UpdateLogin(); | |
79 | |
18 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); | 80 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); |
19 DCHECK(service); | 81 DCHECK(service); |
20 | 82 |
21 // If they user has already synced then don't show anything. | 83 // If the user has not signed into sync then expand the sync promo. |
22 if (service->HasSyncSetupCompleted()) | 84 // TODO(sail): Need to throttle this behind a server side flag. |
23 return; | 85 if (!service->HasSyncSetupCompleted()) |
86 OpenSyncSetup(); | |
87 } | |
24 | 88 |
25 service->get_wizard().Step(SyncSetupWizard::GAIA_LOGIN); | 89 void NewTabSyncSetupHandler::HandleCollapseSyncPromo(const ListValue* args) { |
90 CloseSyncSetup(); | |
26 } | 91 } |
92 | |
93 | |
94 void NewTabSyncSetupHandler::HandleExpandSyncPromo(const ListValue* args) { | |
95 OpenSyncSetup(); | |
96 } | |
OLD | NEW |