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

Side by Side Diff: chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.cc

Issue 12088040: Add a SigninAllowed policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits and rebase to ToT. Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_page_sync_handler.h" 5 #include "chrome/browser/ui/webui/ntp/new_tab_page_sync_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 default: 62 default:
63 return HIDE; 63 return HIDE;
64 } 64 }
65 } 65 }
66 66
67 void NewTabPageSyncHandler::RegisterMessages() { 67 void NewTabPageSyncHandler::RegisterMessages() {
68 sync_service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile( 68 sync_service_ = ProfileSyncServiceFactory::GetInstance()->GetForProfile(
69 Profile::FromWebUI(web_ui())); 69 Profile::FromWebUI(web_ui()));
70 if (sync_service_) 70 if (sync_service_)
71 sync_service_->AddObserver(this); 71 sync_service_->AddObserver(this);
72 profile_pref_registrar_.Init(Profile::FromWebUI(web_ui())->GetPrefs());
73 profile_pref_registrar_.Add(
74 prefs::kSigninAllowed,
75 base::Bind(&NewTabPageSyncHandler::OnSigninAllowedPrefChange,
76 base::Unretained(this)));
72 77
73 web_ui()->RegisterMessageCallback("GetSyncMessage", 78 web_ui()->RegisterMessageCallback("GetSyncMessage",
74 base::Bind(&NewTabPageSyncHandler::HandleGetSyncMessage, 79 base::Bind(&NewTabPageSyncHandler::HandleGetSyncMessage,
75 base::Unretained(this))); 80 base::Unretained(this)));
76 web_ui()->RegisterMessageCallback("SyncLinkClicked", 81 web_ui()->RegisterMessageCallback("SyncLinkClicked",
77 base::Bind(&NewTabPageSyncHandler::HandleSyncLinkClicked, 82 base::Bind(&NewTabPageSyncHandler::HandleSyncLinkClicked,
78 base::Unretained(this))); 83 base::Unretained(this)));
79 } 84 }
80 85
81 void NewTabPageSyncHandler::HandleGetSyncMessage(const ListValue* args) { 86 void NewTabPageSyncHandler::HandleGetSyncMessage(const ListValue* args) {
82 waiting_for_initial_page_load_ = false; 87 waiting_for_initial_page_load_ = false;
83 BuildAndSendSyncStatus(); 88 BuildAndSendSyncStatus();
84 } 89 }
85 90
86 void NewTabPageSyncHandler::HideSyncStatusSection() { 91 void NewTabPageSyncHandler::HideSyncStatusSection() {
87 SendSyncMessageToPage(HIDE, std::string(), std::string()); 92 SendSyncMessageToPage(HIDE, std::string(), std::string());
88 } 93 }
89 94
90 void NewTabPageSyncHandler::BuildAndSendSyncStatus() { 95 void NewTabPageSyncHandler::BuildAndSendSyncStatus() {
91 DCHECK(!waiting_for_initial_page_load_); 96 DCHECK(!waiting_for_initial_page_load_);
97 SigninManager* signin = SigninManagerFactory::GetForProfile(
98 Profile::FromWebUI(web_ui()));
92 99
93 // Hide the sync status section if sync is managed or disabled entirely. 100 // Hide the sync status section if sync is managed or disabled entirely.
94 if (!sync_service_ || sync_service_->IsManaged()) { 101 if (!sync_service_ ||
102 sync_service_->IsManaged() ||
103 !signin ||
104 !signin->IsSigninAllowed()) {
95 HideSyncStatusSection(); 105 HideSyncStatusSection();
96 return; 106 return;
97 } 107 }
98 108
99 // Don't show sync status if setup is not complete. 109 // Don't show sync status if setup is not complete.
100 if (!sync_service_->HasSyncSetupCompleted()) { 110 if (!sync_service_->HasSyncSetupCompleted()) {
101 return; 111 return;
102 } 112 }
103 113
104 // Once sync has been enabled, the supported "sync statuses" for the NNTP 114 // Once sync has been enabled, the supported "sync statuses" for the NNTP
105 // from the user's perspective are: 115 // from the user's perspective are:
106 // 116 //
107 // "Sync error", when we can't authenticate or establish a connection with 117 // "Sync error", when we can't authenticate or establish a connection with
108 // the sync server (appropriate information appended to 118 // the sync server (appropriate information appended to
109 // message). 119 // message).
110 string16 status_msg; 120 string16 status_msg;
111 string16 link_text; 121 string16 link_text;
112 SigninManager* signin = SigninManagerFactory::GetForProfile(
113 Profile::FromWebUI(web_ui()));
114 122
115 sync_ui_util::MessageType type = 123 sync_ui_util::MessageType type =
116 sync_ui_util::GetStatusLabelsForNewTabPage(sync_service_, 124 sync_ui_util::GetStatusLabelsForNewTabPage(sync_service_,
117 *signin, 125 *signin,
118 &status_msg, 126 &status_msg,
119 &link_text); 127 &link_text);
120 SendSyncMessageToPage(FromSyncStatusMessageType(type), 128 SendSyncMessageToPage(FromSyncStatusMessageType(type),
121 UTF16ToUTF8(status_msg), UTF16ToUTF8(link_text)); 129 UTF16ToUTF8(status_msg), UTF16ToUTF8(link_text));
122 } 130 }
123 131
(...skipping 20 matching lines...) Expand all
144 } 152 }
145 } 153 }
146 154
147 void NewTabPageSyncHandler::OnStateChanged() { 155 void NewTabPageSyncHandler::OnStateChanged() {
148 // Don't do anything if the page has not yet loaded. 156 // Don't do anything if the page has not yet loaded.
149 if (waiting_for_initial_page_load_) 157 if (waiting_for_initial_page_load_)
150 return; 158 return;
151 BuildAndSendSyncStatus(); 159 BuildAndSendSyncStatus();
152 } 160 }
153 161
162 void NewTabPageSyncHandler::OnSigninAllowedPrefChange() {
163 // Don't do anything if the page has not yet loaded.
164 if (waiting_for_initial_page_load_)
165 return;
166 BuildAndSendSyncStatus();
167 }
168
154 void NewTabPageSyncHandler::SendSyncMessageToPage( 169 void NewTabPageSyncHandler::SendSyncMessageToPage(
155 MessageType type, std::string msg, 170 MessageType type, std::string msg,
156 std::string linktext) { 171 std::string linktext) {
157 DictionaryValue value; 172 DictionaryValue value;
158 std::string user; 173 std::string user;
159 std::string title; 174 std::string title;
160 std::string linkurl; 175 std::string linkurl;
161 176
162 // If there is nothing to show, we should hide the sync section altogether. 177 // If there is nothing to show, we should hide the sync section altogether.
163 if (type == HIDE || (msg.empty() && linktext.empty())) { 178 if (type == HIDE || (msg.empty() && linktext.empty())) {
(...skipping 22 matching lines...) Expand all
186 if (linkurl.empty()) { 201 if (linkurl.empty()) {
187 value.SetBoolean("linkurlisset", false); 202 value.SetBoolean("linkurlisset", false);
188 } else { 203 } else {
189 value.SetBoolean("linkurlisset", true); 204 value.SetBoolean("linkurlisset", true);
190 value.SetString("linkurl", linkurl); 205 value.SetString("linkurl", linkurl);
191 } 206 }
192 } 207 }
193 } 208 }
194 web_ui()->CallJavascriptFunction("ntp.syncMessageChanged", value); 209 web_ui()->CallJavascriptFunction("ntp.syncMessageChanged", value);
195 } 210 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698