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

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

Issue 2361513003: MD History: Update sign in state in data source (Closed)
Patch Set: move 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
« no previous file with comments | « chrome/browser/ui/webui/md_history_ui.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/md_history_ui.h" 5 #include "chrome/browser/ui/webui/md_history_ui.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 source->SetJsonPath("strings.js"); 209 source->SetJsonPath("strings.js");
210 210
211 return source; 211 return source;
212 } 212 }
213 213
214 } // namespace 214 } // namespace
215 215
216 bool MdHistoryUI::use_test_title_ = false; 216 bool MdHistoryUI::use_test_title_ = false;
217 217
218 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) { 218 MdHistoryUI::MdHistoryUI(content::WebUI* web_ui) : WebUIController(web_ui) {
219 Profile* profile = Profile::FromWebUI(web_ui);
220 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); 219 web_ui->AddMessageHandler(new BrowsingHistoryHandler());
221 web_ui->AddMessageHandler(new MetricsHandler()); 220 web_ui->AddMessageHandler(new MetricsHandler());
222 221
223 if (search::IsInstantExtendedAPIEnabled()) { 222 if (search::IsInstantExtendedAPIEnabled()) {
224 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); 223 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler());
225 web_ui->AddMessageHandler(new HistoryLoginHandler()); 224 web_ui->AddMessageHandler(new HistoryLoginHandler(
225 base::Bind(&MdHistoryUI::CreateDataSource, base::Unretained(this))));
226 } 226 }
227 227
228 data_source_ = CreateMdHistoryUIHTMLSource(profile, use_test_title_); 228 CreateDataSource();
229 content::WebUIDataSource::Add(profile, data_source_);
230 229
231 web_ui->RegisterMessageCallback("menuPromoShown", 230 web_ui->RegisterMessageCallback("menuPromoShown",
232 base::Bind(&MdHistoryUI::HandleMenuPromoShown, base::Unretained(this))); 231 base::Bind(&MdHistoryUI::HandleMenuPromoShown, base::Unretained(this)));
233 } 232 }
234 233
235 MdHistoryUI::~MdHistoryUI() {} 234 MdHistoryUI::~MdHistoryUI() {}
236 235
237 // static 236 // static
238 bool MdHistoryUI::IsEnabled(Profile* profile) { 237 bool MdHistoryUI::IsEnabled(Profile* profile) {
239 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) && 238 return base::FeatureList::IsEnabled(features::kMaterialDesignHistory) &&
(...skipping 19 matching lines...) Expand all
259 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 258 return ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
260 IDR_HISTORY_FAVICON, scale_factor); 259 IDR_HISTORY_FAVICON, scale_factor);
261 } 260 }
262 261
263 void MdHistoryUI::RegisterProfilePrefs( 262 void MdHistoryUI::RegisterProfilePrefs(
264 user_prefs::PrefRegistrySyncable* registry) { 263 user_prefs::PrefRegistrySyncable* registry) {
265 registry->RegisterBooleanPref(prefs::kMdHistoryMenuPromoShown, false, 264 registry->RegisterBooleanPref(prefs::kMdHistoryMenuPromoShown, false,
266 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 265 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
267 } 266 }
268 267
268 // TODO(lshang): Change to not re-create data source every time after we use
269 // unique_ptr instead of raw pointers for data source.
270 void MdHistoryUI::CreateDataSource() {
271 Profile* profile = Profile::FromWebUI(web_ui());
272 content::WebUIDataSource* data_source =
273 CreateMdHistoryUIHTMLSource(profile, use_test_title_);
274 content::WebUIDataSource::Add(profile, data_source);
275 }
276
269 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) { 277 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) {
270 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( 278 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean(
271 prefs::kMdHistoryMenuPromoShown, true); 279 prefs::kMdHistoryMenuPromoShown, true);
272 data_source_->AddBoolean(kShowMenuPromoKey, false); 280 CreateDataSource();
273 } 281 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/md_history_ui.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698