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

Side by Side Diff: chrome/browser/ui/webui/history_ui.cc

Issue 2361513003: MD History: Update sign in state in data source (Closed)
Patch Set: remove unused forward declare Created 4 years, 2 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
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/history_ui.h" 5 #include "chrome/browser/ui/webui/history_ui.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 return source; 170 return source;
171 } 171 }
172 172
173 } // namespace 173 } // namespace
174 174
175 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 175 HistoryUI::HistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
176 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 176 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
177 web_ui->AddMessageHandler(new MetricsHandler()); 177 web_ui->AddMessageHandler(new MetricsHandler());
178 178
179 // Set up the chrome://history-frame/ source.
180 CreateDataSource();
181
179 // On mobile we deal with foreign sessions differently. 182 // On mobile we deal with foreign sessions differently.
180 #if !defined(OS_ANDROID) 183 #if !defined(OS_ANDROID)
181 if (search::IsInstantExtendedAPIEnabled()) { 184 if (search::IsInstantExtendedAPIEnabled()) {
182 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 185 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
183 web_ui->AddMessageHandler(new HistoryLoginHandler()); 186 web_ui->AddMessageHandler(new HistoryLoginHandler(
187 base::Bind(&HistoryUI::SignInChanged, base::Unretained(this))));
Dan Beam 2016/09/30 02:55:40 why not just bind to CreateDataSource directly?
lshang 2016/09/30 03:21:13 Done.
184 } 188 }
185 #endif 189 #endif
186 190
187 // TODO(crbug.com/595332): Since the API to query other forms of browsing 191 // TODO(crbug.com/595332): Since the API to query other forms of browsing
188 // history is not ready yet, make it possible to test the history UI as if 192 // history is not ready yet, make it possible to test the history UI as if
189 // it were. If the user opens chrome://history/?reset_ofbh, we will assume 193 // it were. If the user opens chrome://history/?reset_ofbh, we will assume
190 // that other forms of browsing history exist (for all accounts), and we will 194 // that other forms of browsing history exist (for all accounts), and we will
191 // also reset the one-time notice shown in the Clear Browsing Data dialog. 195 // also reset the one-time notice shown in the Clear Browsing Data dialog.
192 // This code should be removed as soon as the API is ready. 196 // This code should be removed as soon as the API is ready.
193 GURL url = web_ui->GetWebContents()->GetVisibleURL(); 197 GURL url = web_ui->GetWebContents()->GetVisibleURL();
194 if (url.has_query() && url.query() == "reset_ofbh") { 198 if (url.has_query() && url.query() == "reset_ofbh") {
195 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger( 199 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger(
196 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0); 200 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0);
197 browsing_data::testing:: 201 browsing_data::testing::
198 g_override_other_forms_of_browsing_history_query = true; 202 g_override_other_forms_of_browsing_history_query = true;
199 } 203 }
200
201 // Set up the chrome://history-frame/ source.
202 Profile* profile = Profile::FromWebUI(web_ui);
203 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile));
204 } 204 }
205 205
206 HistoryUI::~HistoryUI() {} 206 HistoryUI::~HistoryUI() {}
207 207
208 // static 208 // static
209 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( 209 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
210 ui::ScaleFactor scale_factor) { 210 ui::ScaleFactor scale_factor) {
211 return ResourceBundle::GetSharedInstance(). 211 return ResourceBundle::GetSharedInstance().
212 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); 212 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor);
213 } 213 }
214
215 void HistoryUI::CreateDataSource() {
216 Profile* profile = Profile::FromWebUI(web_ui());
217 content::WebUIDataSource* data_source = CreateHistoryUIHTMLSource(profile);
218 content::WebUIDataSource::Add(profile, data_source);
219 }
220
221 void HistoryUI::SignInChanged() {
222 // Recreate the data source so sign in state get updated in there.
223 CreateDataSource();
224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698