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

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: fix promo crash 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 source->AddResourcePath(kOtherDevicesJsFile, IDR_OTHER_DEVICES_JS); 165 source->AddResourcePath(kOtherDevicesJsFile, IDR_OTHER_DEVICES_JS);
166 source->SetDefaultResource(IDR_HISTORY_HTML); 166 source->SetDefaultResource(IDR_HISTORY_HTML);
167 source->DisableDenyXFrameOptions(); 167 source->DisableDenyXFrameOptions();
168 source->DisableI18nAndUseGzipForAllPaths(); 168 source->DisableI18nAndUseGzipForAllPaths();
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)
176 : WebUIController(web_ui), weak_ptr_factory_(this) {
176 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 177 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
177 web_ui->AddMessageHandler(new MetricsHandler()); 178 web_ui->AddMessageHandler(new MetricsHandler());
178 179
180 Profile* profile = Profile::FromWebUI(web_ui);
181 data_source_ = CreateHistoryUIHTMLSource(profile);
182 // Set up the chrome://history-frame/ source.
183 content::WebUIDataSource::Add(profile, data_source_);
184
179 // On mobile we deal with foreign sessions differently. 185 // On mobile we deal with foreign sessions differently.
180 #if !defined(OS_ANDROID) 186 #if !defined(OS_ANDROID)
181 if (search::IsInstantExtendedAPIEnabled()) { 187 if (search::IsInstantExtendedAPIEnabled()) {
182 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 188 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
183 web_ui->AddMessageHandler(new HistoryLoginHandler()); 189 web_ui->AddMessageHandler(new HistoryLoginHandler(
190 base::Bind(&HistoryUI::SignInChanged, weak_ptr_factory_.GetWeakPtr())));
184 } 191 }
185 #endif 192 #endif
186 193
187 // TODO(crbug.com/595332): Since the API to query other forms of browsing 194 // 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 195 // 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 196 // 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 197 // 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. 198 // 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. 199 // This code should be removed as soon as the API is ready.
193 GURL url = web_ui->GetWebContents()->GetVisibleURL(); 200 GURL url = web_ui->GetWebContents()->GetVisibleURL();
194 if (url.has_query() && url.query() == "reset_ofbh") { 201 if (url.has_query() && url.query() == "reset_ofbh") {
195 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger( 202 Profile::FromWebUI(web_ui)->GetPrefs()->SetInteger(
196 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0); 203 browsing_data::prefs::kClearBrowsingDataHistoryNoticeShownTimes, 0);
197 browsing_data::testing:: 204 browsing_data::testing::
198 g_override_other_forms_of_browsing_history_query = true; 205 g_override_other_forms_of_browsing_history_query = true;
199 } 206 }
200
201 // Set up the chrome://history-frame/ source.
202 Profile* profile = Profile::FromWebUI(web_ui);
203 content::WebUIDataSource::Add(profile, CreateHistoryUIHTMLSource(profile));
204 } 207 }
205 208
206 HistoryUI::~HistoryUI() {} 209 HistoryUI::~HistoryUI() {}
207 210
208 // static 211 // static
209 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes( 212 base::RefCountedMemory* HistoryUI::GetFaviconResourceBytes(
210 ui::ScaleFactor scale_factor) { 213 ui::ScaleFactor scale_factor) {
211 return ResourceBundle::GetSharedInstance(). 214 return ResourceBundle::GetSharedInstance().
212 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor); 215 LoadDataResourceBytesForScale(IDR_HISTORY_FAVICON, scale_factor);
213 } 216 }
217
218 void HistoryUI::SignInChanged(bool signed_in) {
219 // Recreate the data source so sign in state get updated in there.
220 Profile* profile = Profile::FromWebUI(web_ui());
221 data_source_ = CreateHistoryUIHTMLSource(profile);
222 content::WebUIDataSource::Add(profile, data_source_);
223 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698