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

Side by Side Diff: chrome/browser/jumplist_win.cc

Issue 845013002: Remove TopSites notification in favor of Observers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing typo causing compilation issues on win Created 5 years, 11 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/jumplist_win.h" 5 #include "chrome/browser/jumplist_win.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 "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); 249 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname);
250 use_profiles_category_ = HasProfilesJumplistExperiment(); 250 use_profiles_category_ = HasProfilesJumplistExperiment();
251 251
252 history::TopSites* top_sites = profile_->GetTopSites(); 252 history::TopSites* top_sites = profile_->GetTopSites();
253 if (top_sites) { 253 if (top_sites) {
254 // TopSites updates itself after a delay. This is especially noticable when 254 // TopSites updates itself after a delay. This is especially noticable when
255 // your profile is empty. Ask TopSites to update itself when jumplist is 255 // your profile is empty. Ask TopSites to update itself when jumplist is
256 // initialized. 256 // initialized.
257 top_sites->SyncWithHistory(); 257 top_sites->SyncWithHistory();
258 registrar_.reset(new content::NotificationRegistrar); 258 registrar_.reset(new content::NotificationRegistrar);
259 // Register for notification when TopSites changes so that we can update 259 // Register as TopSitesObserver so that we can update ourselves when the
260 // ourself. 260 // TopSites changes.
261 registrar_->Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, 261 top_sites->AddObserver(this);
262 content::Source<history::TopSites>(top_sites));
263 // Register for notification when profile is destroyed to ensure that all 262 // Register for notification when profile is destroyed to ensure that all
264 // observers are detatched at that time. 263 // observers are detatched at that time.
265 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 264 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
266 content::Source<Profile>(profile_)); 265 content::Source<Profile>(profile_));
267 } 266 }
268 tab_restore_service->AddObserver(this); 267 tab_restore_service->AddObserver(this);
269 pref_change_registrar_.reset(new PrefChangeRegistrar); 268 pref_change_registrar_.reset(new PrefChangeRegistrar);
270 pref_change_registrar_->Init(profile_->GetPrefs()); 269 pref_change_registrar_->Init(profile_->GetPrefs());
271 pref_change_registrar_->Add( 270 pref_change_registrar_->Add(
272 prefs::kIncognitoModeAvailability, 271 prefs::kIncognitoModeAvailability,
(...skipping 13 matching lines...) Expand all
286 } 285 }
287 286
288 // static 287 // static
289 bool JumpList::Enabled() { 288 bool JumpList::Enabled() {
290 return JumpListUpdater::IsEnabled(); 289 return JumpListUpdater::IsEnabled();
291 } 290 }
292 291
293 void JumpList::Observe(int type, 292 void JumpList::Observe(int type,
294 const content::NotificationSource& source, 293 const content::NotificationSource& source,
295 const content::NotificationDetails& details) { 294 const content::NotificationDetails& details) {
296 switch (type) { 295 DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED);
297 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { 296 // Profile was destroyed, do clean-up.
298 // Most visited urls changed, query again. 297 Terminate();
299 history::TopSites* top_sites = profile_->GetTopSites();
300 if (top_sites) {
301 top_sites->GetMostVisitedURLs(
302 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
303 weak_ptr_factory_.GetWeakPtr()), false);
304 }
305 break;
306 }
307 case chrome::NOTIFICATION_PROFILE_DESTROYED: {
308 // Profile was destroyed, do clean-up.
309 Terminate();
310 break;
311 }
312 default:
313 NOTREACHED() << "Unexpected notification type.";
314 }
315 } 298 }
316 299
317 void JumpList::CancelPendingUpdate() { 300 void JumpList::CancelPendingUpdate() {
318 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { 301 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) {
319 cancelable_task_tracker_.TryCancel(task_id_); 302 cancelable_task_tracker_.TryCancel(task_id_);
320 task_id_ = base::CancelableTaskTracker::kBadTaskId; 303 task_id_ = base::CancelableTaskTracker::kBadTaskId;
321 } 304 }
322 } 305 }
323 306
324 void JumpList::Terminate() { 307 void JumpList::Terminate() {
325 CancelPendingUpdate(); 308 CancelPendingUpdate();
326 if (profile_) { 309 if (profile_) {
327 TabRestoreService* tab_restore_service = 310 TabRestoreService* tab_restore_service =
328 TabRestoreServiceFactory::GetForProfile(profile_); 311 TabRestoreServiceFactory::GetForProfile(profile_);
329 if (tab_restore_service) 312 if (tab_restore_service)
330 tab_restore_service->RemoveObserver(this); 313 tab_restore_service->RemoveObserver(this);
314 history::TopSites* top_sites = profile_->GetTopSites();
315 if (top_sites)
316 top_sites->RemoveObserver(this);
331 registrar_.reset(); 317 registrar_.reset();
332 pref_change_registrar_.reset(); 318 pref_change_registrar_.reset();
333 } 319 }
334 profile_ = NULL; 320 profile_ = NULL;
335 } 321 }
336 322
337 void JumpList::OnMostVisitedURLsAvailable( 323 void JumpList::OnMostVisitedURLsAvailable(
338 const history::MostVisitedURLList& data) { 324 const history::MostVisitedURLList& data) {
339 // If we have a pending favicon request, cancel it here (it is out of date). 325 // If we have a pending favicon request, cancel it here (it is out of date).
340 CancelPendingUpdate(); 326 CancelPendingUpdate();
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 link->set_icon_data(avatar.AsBitmap()); 594 link->set_icon_data(avatar.AsBitmap());
609 new_profile_switcher.push_back(link); 595 new_profile_switcher.push_back(link);
610 } 596 }
611 } 597 }
612 598
613 { 599 {
614 base::AutoLock auto_lock(list_lock_); 600 base::AutoLock auto_lock(list_lock_);
615 new_profile_switcher.swap(profile_switcher_); 601 new_profile_switcher.swap(profile_switcher_);
616 } 602 }
617 } 603 }
604
605 void JumpList::TopSitesLoaded(history::TopSites* top_sites) {
606 }
607
608 void JumpList::TopSitesChanged(history::TopSites* top_sites) {
609 // Most visited urls changed, query again.
610 history::TopSites* top_sites = profile_->GetTopSites();
611 if (top_sites) {
612 top_sites->GetMostVisitedURLs(
613 base::Bind(&JumpList::OnMostVisitedURLsAvailable,
614 weak_ptr_factory_.GetWeakPtr()),
615 false);
616 }
617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698