OLD | NEW |
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 waiting_for_initial_page_load_ = false; | 82 waiting_for_initial_page_load_ = false; |
83 BuildAndSendSyncStatus(); | 83 BuildAndSendSyncStatus(); |
84 } | 84 } |
85 | 85 |
86 void NewTabPageSyncHandler::HideSyncStatusSection() { | 86 void NewTabPageSyncHandler::HideSyncStatusSection() { |
87 SendSyncMessageToPage(HIDE, std::string(), std::string()); | 87 SendSyncMessageToPage(HIDE, std::string(), std::string()); |
88 } | 88 } |
89 | 89 |
90 void NewTabPageSyncHandler::BuildAndSendSyncStatus() { | 90 void NewTabPageSyncHandler::BuildAndSendSyncStatus() { |
91 DCHECK(!waiting_for_initial_page_load_); | 91 DCHECK(!waiting_for_initial_page_load_); |
| 92 SigninManager* signin = SigninManagerFactory::GetForProfile( |
| 93 Profile::FromWebUI(web_ui())); |
92 | 94 |
93 // Hide the sync status section if sync is managed or disabled entirely. | 95 // Hide the sync status section if sync is managed or disabled entirely. |
94 if (!sync_service_ || sync_service_->IsManaged()) { | 96 if (!sync_service_ || |
| 97 sync_service_->IsManaged() || |
| 98 !signin || |
| 99 !signin->IsSigninAllowed()) { |
95 HideSyncStatusSection(); | 100 HideSyncStatusSection(); |
96 return; | 101 return; |
97 } | 102 } |
98 | 103 |
99 // Don't show sync status if setup is not complete. | 104 // Don't show sync status if setup is not complete. |
100 if (!sync_service_->HasSyncSetupCompleted()) { | 105 if (!sync_service_->HasSyncSetupCompleted()) { |
101 return; | 106 return; |
102 } | 107 } |
103 | 108 |
104 // Once sync has been enabled, the supported "sync statuses" for the NNTP | 109 // Once sync has been enabled, the supported "sync statuses" for the NNTP |
105 // from the user's perspective are: | 110 // from the user's perspective are: |
106 // | 111 // |
107 // "Sync error", when we can't authenticate or establish a connection with | 112 // "Sync error", when we can't authenticate or establish a connection with |
108 // the sync server (appropriate information appended to | 113 // the sync server (appropriate information appended to |
109 // message). | 114 // message). |
110 string16 status_msg; | 115 string16 status_msg; |
111 string16 link_text; | 116 string16 link_text; |
112 SigninManager* signin = SigninManagerFactory::GetForProfile( | |
113 Profile::FromWebUI(web_ui())); | |
114 | 117 |
115 sync_ui_util::MessageType type = | 118 sync_ui_util::MessageType type = |
116 sync_ui_util::GetStatusLabelsForNewTabPage(sync_service_, | 119 sync_ui_util::GetStatusLabelsForNewTabPage(sync_service_, |
117 *signin, | 120 *signin, |
118 &status_msg, | 121 &status_msg, |
119 &link_text); | 122 &link_text); |
120 SendSyncMessageToPage(FromSyncStatusMessageType(type), | 123 SendSyncMessageToPage(FromSyncStatusMessageType(type), |
121 UTF16ToUTF8(status_msg), UTF16ToUTF8(link_text)); | 124 UTF16ToUTF8(status_msg), UTF16ToUTF8(link_text)); |
122 } | 125 } |
123 | 126 |
(...skipping 21 matching lines...) Expand all Loading... |
145 } | 148 } |
146 } | 149 } |
147 | 150 |
148 void NewTabPageSyncHandler::OnStateChanged() { | 151 void NewTabPageSyncHandler::OnStateChanged() { |
149 // Don't do anything if the page has not yet loaded. | 152 // Don't do anything if the page has not yet loaded. |
150 if (waiting_for_initial_page_load_) | 153 if (waiting_for_initial_page_load_) |
151 return; | 154 return; |
152 BuildAndSendSyncStatus(); | 155 BuildAndSendSyncStatus(); |
153 } | 156 } |
154 | 157 |
| 158 void NewTabPageSyncHandler::OnSigninAllowedPrefChange(bool signin_allowed) { |
| 159 // Don't do anything if the page has not yet loaded. |
| 160 if (waiting_for_initial_page_load_) |
| 161 return; |
| 162 BuildAndSendSyncStatus(); |
| 163 } |
| 164 |
155 void NewTabPageSyncHandler::SendSyncMessageToPage( | 165 void NewTabPageSyncHandler::SendSyncMessageToPage( |
156 MessageType type, std::string msg, | 166 MessageType type, std::string msg, |
157 std::string linktext) { | 167 std::string linktext) { |
158 DictionaryValue value; | 168 DictionaryValue value; |
159 std::string user; | 169 std::string user; |
160 std::string title; | 170 std::string title; |
161 std::string linkurl; | 171 std::string linkurl; |
162 | 172 |
163 // If there is nothing to show, we should hide the sync section altogether. | 173 // If there is nothing to show, we should hide the sync section altogether. |
164 if (type == HIDE || (msg.empty() && linktext.empty())) { | 174 if (type == HIDE || (msg.empty() && linktext.empty())) { |
(...skipping 22 matching lines...) Expand all Loading... |
187 if (linkurl.empty()) { | 197 if (linkurl.empty()) { |
188 value.SetBoolean("linkurlisset", false); | 198 value.SetBoolean("linkurlisset", false); |
189 } else { | 199 } else { |
190 value.SetBoolean("linkurlisset", true); | 200 value.SetBoolean("linkurlisset", true); |
191 value.SetString("linkurl", linkurl); | 201 value.SetString("linkurl", linkurl); |
192 } | 202 } |
193 } | 203 } |
194 } | 204 } |
195 web_ui()->CallJavascriptFunction("ntp.syncMessageChanged", value); | 205 web_ui()->CallJavascriptFunction("ntp.syncMessageChanged", value); |
196 } | 206 } |
OLD | NEW |