Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML); | 208 source->SetDefaultResource(IDR_MD_HISTORY_HISTORY_HTML); |
| 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) |
| 219 : WebUIController(web_ui), weak_ptr_factory_(this) { | |
| 219 Profile* profile = Profile::FromWebUI(web_ui); | 220 Profile* profile = Profile::FromWebUI(web_ui); |
| 220 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); | 221 web_ui->AddMessageHandler(new BrowsingHistoryHandler()); |
| 221 web_ui->AddMessageHandler(new MetricsHandler()); | 222 web_ui->AddMessageHandler(new MetricsHandler()); |
| 222 | 223 |
| 223 if (search::IsInstantExtendedAPIEnabled()) { | 224 if (search::IsInstantExtendedAPIEnabled()) { |
| 224 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); | 225 web_ui->AddMessageHandler(new browser_sync::ForeignSessionHandler()); |
| 225 web_ui->AddMessageHandler(new HistoryLoginHandler()); | 226 web_ui->AddMessageHandler(new HistoryLoginHandler(base::Bind( |
| 227 &MdHistoryUI::SignInChanged, weak_ptr_factory_.GetWeakPtr()))); | |
|
Dan Beam
2016/09/29 18:13:33
you can use weakptr, but now that we're not depend
lshang
2016/09/30 00:33:19
Done.
| |
| 226 } | 228 } |
| 227 | 229 |
| 228 data_source_ = CreateMdHistoryUIHTMLSource(profile, use_test_title_); | 230 data_source_ = CreateMdHistoryUIHTMLSource(profile, use_test_title_); |
|
Dan Beam
2016/09/29 18:13:33
don't keep this pointer around, as it's potentiall
lshang
2016/09/30 00:33:19
Done. Added a Get() method to create the data sour
| |
| 229 content::WebUIDataSource::Add(profile, data_source_); | 231 content::WebUIDataSource::Add(profile, data_source_); |
| 230 | 232 |
| 231 web_ui->RegisterMessageCallback("menuPromoShown", | 233 web_ui->RegisterMessageCallback("menuPromoShown", |
| 232 base::Bind(&MdHistoryUI::HandleMenuPromoShown, base::Unretained(this))); | 234 base::Bind(&MdHistoryUI::HandleMenuPromoShown, base::Unretained(this))); |
| 233 } | 235 } |
| 234 | 236 |
| 235 MdHistoryUI::~MdHistoryUI() {} | 237 MdHistoryUI::~MdHistoryUI() {} |
| 236 | 238 |
| 237 // static | 239 // static |
| 238 bool MdHistoryUI::IsEnabled(Profile* profile) { | 240 bool MdHistoryUI::IsEnabled(Profile* profile) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 262 | 264 |
| 263 void MdHistoryUI::RegisterProfilePrefs( | 265 void MdHistoryUI::RegisterProfilePrefs( |
| 264 user_prefs::PrefRegistrySyncable* registry) { | 266 user_prefs::PrefRegistrySyncable* registry) { |
| 265 registry->RegisterBooleanPref(prefs::kMdHistoryMenuPromoShown, false, | 267 registry->RegisterBooleanPref(prefs::kMdHistoryMenuPromoShown, false, |
| 266 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 268 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 267 } | 269 } |
| 268 | 270 |
| 269 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) { | 271 void MdHistoryUI::HandleMenuPromoShown(const base::ListValue* args) { |
| 270 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 272 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( |
| 271 prefs::kMdHistoryMenuPromoShown, true); | 273 prefs::kMdHistoryMenuPromoShown, true); |
| 274 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 275 data_source_ = CreateMdHistoryUIHTMLSource(profile, use_test_title_); | |
| 276 content::WebUIDataSource::Add(profile, data_source_); | |
|
lshang
2016/09/29 08:06:48
I also modified here due to the same reason as bel
| |
| 272 data_source_->AddBoolean(kShowMenuPromoKey, false); | 277 data_source_->AddBoolean(kShowMenuPromoKey, false); |
| 273 } | 278 } |
| 279 | |
| 280 void MdHistoryUI::SignInChanged(bool signed_in) { | |
| 281 // Recreate the data source so sign in state get updated in there. | |
| 282 Profile* profile = Profile::FromWebUI(web_ui()); | |
| 283 data_source_ = CreateMdHistoryUIHTMLSource(profile, use_test_title_); | |
| 284 content::WebUIDataSource::Add(profile, data_source_); | |
|
lshang
2016/09/29 08:06:48
I found that purely AddBoolean() here will cause b
Dan Beam
2016/09/29 18:13:33
wow, that's crazy sauce. we should just make hand
lshang
2016/09/30 00:33:19
Done.
| |
| 285 } | |
| OLD | NEW |