| OLD | NEW |
| 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" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/prefs/pref_change_registrar.h" | 13 #include "base/prefs/pref_change_registrar.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/favicon/favicon_service.h" | 19 #include "chrome/browser/favicon/favicon_service.h" |
| 20 #include "chrome/browser/favicon/favicon_service_factory.h" | 20 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 21 #include "chrome/browser/history/history_service.h" | 21 #include "chrome/browser/history/history_service.h" |
| 22 #include "chrome/browser/history/top_sites.h" | 22 #include "chrome/browser/history/top_sites.h" |
| 23 #include "chrome/browser/history/top_sites_factory.h" |
| 23 #include "chrome/browser/metrics/jumplist_metrics_win.h" | 24 #include "chrome/browser/metrics/jumplist_metrics_win.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/profiles/profile_info_cache.h" | 26 #include "chrome/browser/profiles/profile_info_cache.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/sessions/tab_restore_service.h" | 28 #include "chrome/browser/sessions/tab_restore_service.h" |
| 28 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 29 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 29 #include "chrome/browser/shell_integration.h" | 30 #include "chrome/browser/shell_integration.h" |
| 30 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 // from the observer list. | 243 // from the observer list. |
| 243 TabRestoreService* tab_restore_service = | 244 TabRestoreService* tab_restore_service = |
| 244 TabRestoreServiceFactory::GetForProfile(profile_); | 245 TabRestoreServiceFactory::GetForProfile(profile_); |
| 245 if (!tab_restore_service) | 246 if (!tab_restore_service) |
| 246 return; | 247 return; |
| 247 | 248 |
| 248 app_id_ = ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()); | 249 app_id_ = ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()); |
| 249 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); | 250 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); |
| 250 use_profiles_category_ = HasProfilesJumplistExperiment(); | 251 use_profiles_category_ = HasProfilesJumplistExperiment(); |
| 251 | 252 |
| 252 history::TopSites* top_sites = profile_->GetTopSites(); | 253 scoped_refptr<history::TopSites> top_sites = |
| 254 TopSitesFactory::GetForProfile(profile_); |
| 253 if (top_sites) { | 255 if (top_sites) { |
| 254 // TopSites updates itself after a delay. This is especially noticable when | 256 // TopSites updates itself after a delay. This is especially noticable when |
| 255 // your profile is empty. Ask TopSites to update itself when jumplist is | 257 // your profile is empty. Ask TopSites to update itself when jumplist is |
| 256 // initialized. | 258 // initialized. |
| 257 top_sites->SyncWithHistory(); | 259 top_sites->SyncWithHistory(); |
| 258 registrar_.reset(new content::NotificationRegistrar); | 260 registrar_.reset(new content::NotificationRegistrar); |
| 259 // Register for notification when TopSites changes so that we can update | 261 // Register for notification when TopSites changes so that we can update |
| 260 // ourself. | 262 // ourself. |
| 261 registrar_->Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, | 263 registrar_->Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, |
| 262 content::Source<history::TopSites>(top_sites)); | 264 content::Source<history::TopSites>(top_sites.get())); |
| 263 // Register for notification when profile is destroyed to ensure that all | 265 // Register for notification when profile is destroyed to ensure that all |
| 264 // observers are detatched at that time. | 266 // observers are detatched at that time. |
| 265 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 267 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 266 content::Source<Profile>(profile_)); | 268 content::Source<Profile>(profile_)); |
| 267 } | 269 } |
| 268 tab_restore_service->AddObserver(this); | 270 tab_restore_service->AddObserver(this); |
| 269 pref_change_registrar_.reset(new PrefChangeRegistrar); | 271 pref_change_registrar_.reset(new PrefChangeRegistrar); |
| 270 pref_change_registrar_->Init(profile_->GetPrefs()); | 272 pref_change_registrar_->Init(profile_->GetPrefs()); |
| 271 pref_change_registrar_->Add( | 273 pref_change_registrar_->Add( |
| 272 prefs::kIncognitoModeAvailability, | 274 prefs::kIncognitoModeAvailability, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 289 bool JumpList::Enabled() { | 291 bool JumpList::Enabled() { |
| 290 return JumpListUpdater::IsEnabled(); | 292 return JumpListUpdater::IsEnabled(); |
| 291 } | 293 } |
| 292 | 294 |
| 293 void JumpList::Observe(int type, | 295 void JumpList::Observe(int type, |
| 294 const content::NotificationSource& source, | 296 const content::NotificationSource& source, |
| 295 const content::NotificationDetails& details) { | 297 const content::NotificationDetails& details) { |
| 296 switch (type) { | 298 switch (type) { |
| 297 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { | 299 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { |
| 298 // Most visited urls changed, query again. | 300 // Most visited urls changed, query again. |
| 299 history::TopSites* top_sites = profile_->GetTopSites(); | 301 scoped_refptr<history::TopSites> top_sites = |
| 302 TopSitesFactory::GetForProfile(profile_); |
| 300 if (top_sites) { | 303 if (top_sites) { |
| 301 top_sites->GetMostVisitedURLs( | 304 top_sites->GetMostVisitedURLs( |
| 302 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 305 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
| 303 weak_ptr_factory_.GetWeakPtr()), false); | 306 weak_ptr_factory_.GetWeakPtr()), false); |
| 304 } | 307 } |
| 305 break; | 308 break; |
| 306 } | 309 } |
| 307 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 310 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
| 308 // Profile was destroyed, do clean-up. | 311 // Profile was destroyed, do clean-up. |
| 309 Terminate(); | 312 Terminate(); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 link->set_icon_data(avatar.AsBitmap()); | 611 link->set_icon_data(avatar.AsBitmap()); |
| 609 new_profile_switcher.push_back(link); | 612 new_profile_switcher.push_back(link); |
| 610 } | 613 } |
| 611 } | 614 } |
| 612 | 615 |
| 613 { | 616 { |
| 614 base::AutoLock auto_lock(list_lock_); | 617 base::AutoLock auto_lock(list_lock_); |
| 615 new_profile_switcher.swap(profile_switcher_); | 618 new_profile_switcher.swap(profile_switcher_); |
| 616 } | 619 } |
| 617 } | 620 } |
| OLD | NEW |