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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 // from the observer list. | 242 // from the observer list. |
242 TabRestoreService* tab_restore_service = | 243 TabRestoreService* tab_restore_service = |
243 TabRestoreServiceFactory::GetForProfile(profile_); | 244 TabRestoreServiceFactory::GetForProfile(profile_); |
244 if (!tab_restore_service) | 245 if (!tab_restore_service) |
245 return; | 246 return; |
246 | 247 |
247 app_id_ = ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()); | 248 app_id_ = ShellIntegration::GetChromiumModelIdForProfile(profile_->GetPath()); |
248 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); | 249 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); |
249 use_profiles_category_ = HasProfilesJumplistExperiment(); | 250 use_profiles_category_ = HasProfilesJumplistExperiment(); |
250 | 251 |
251 history::TopSites* top_sites = profile_->GetTopSites(); | 252 scoped_refptr<history::TopSites> top_sites = |
252 if (top_sites) { | 253 TopSitesFactory::GetForProfile(profile_); |
| 254 if (top_sites.get()) { |
253 // TopSites updates itself after a delay. This is especially noticable when | 255 // TopSites updates itself after a delay. This is especially noticable when |
254 // your profile is empty. Ask TopSites to update itself when jumplist is | 256 // your profile is empty. Ask TopSites to update itself when jumplist is |
255 // initialized. | 257 // initialized. |
256 top_sites->SyncWithHistory(); | 258 top_sites->SyncWithHistory(); |
257 registrar_.reset(new content::NotificationRegistrar); | 259 registrar_.reset(new content::NotificationRegistrar); |
258 // Register for notification when TopSites changes so that we can update | 260 // Register for notification when TopSites changes so that we can update |
259 // ourself. | 261 // ourself. |
260 registrar_->Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, | 262 registrar_->Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED, |
261 content::Source<history::TopSites>(top_sites)); | 263 content::Source<history::TopSites>(top_sites.get())); |
262 // Register for notification when profile is destroyed to ensure that all | 264 // Register for notification when profile is destroyed to ensure that all |
263 // observers are detatched at that time. | 265 // observers are detatched at that time. |
264 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 266 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
265 content::Source<Profile>(profile_)); | 267 content::Source<Profile>(profile_)); |
266 } | 268 } |
267 tab_restore_service->AddObserver(this); | 269 tab_restore_service->AddObserver(this); |
268 pref_change_registrar_.reset(new PrefChangeRegistrar); | 270 pref_change_registrar_.reset(new PrefChangeRegistrar); |
269 pref_change_registrar_->Init(profile_->GetPrefs()); | 271 pref_change_registrar_->Init(profile_->GetPrefs()); |
270 pref_change_registrar_->Add( | 272 pref_change_registrar_->Add( |
271 prefs::kIncognitoModeAvailability, | 273 prefs::kIncognitoModeAvailability, |
(...skipping 14 matching lines...) Expand all Loading... |
286 bool JumpList::Enabled() { | 288 bool JumpList::Enabled() { |
287 return JumpListUpdater::IsEnabled(); | 289 return JumpListUpdater::IsEnabled(); |
288 } | 290 } |
289 | 291 |
290 void JumpList::Observe(int type, | 292 void JumpList::Observe(int type, |
291 const content::NotificationSource& source, | 293 const content::NotificationSource& source, |
292 const content::NotificationDetails& details) { | 294 const content::NotificationDetails& details) { |
293 switch (type) { | 295 switch (type) { |
294 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { | 296 case chrome::NOTIFICATION_TOP_SITES_CHANGED: { |
295 // Most visited urls changed, query again. | 297 // Most visited urls changed, query again. |
296 history::TopSites* top_sites = profile_->GetTopSites(); | 298 scoped_refptr<history::TopSites> top_sites = |
297 if (top_sites) { | 299 TopSitesFactory::GetForProfile(profile_); |
| 300 if (top_sites.get()) { |
298 top_sites->GetMostVisitedURLs( | 301 top_sites->GetMostVisitedURLs( |
299 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 302 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
300 weak_ptr_factory_.GetWeakPtr()), false); | 303 weak_ptr_factory_.GetWeakPtr()), false); |
301 } | 304 } |
302 break; | 305 break; |
303 } | 306 } |
304 case chrome::NOTIFICATION_PROFILE_DESTROYED: { | 307 case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
305 // Profile was destroyed, do clean-up. | 308 // Profile was destroyed, do clean-up. |
306 Terminate(); | 309 Terminate(); |
307 break; | 310 break; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 link->set_icon_data(avatar.AsBitmap()); | 603 link->set_icon_data(avatar.AsBitmap()); |
601 new_profile_switcher.push_back(link); | 604 new_profile_switcher.push_back(link); |
602 } | 605 } |
603 } | 606 } |
604 | 607 |
605 { | 608 { |
606 base::AutoLock auto_lock(list_lock_); | 609 base::AutoLock auto_lock(list_lock_); |
607 new_profile_switcher.swap(profile_switcher_); | 610 new_profile_switcher.swap(profile_switcher_); |
608 } | 611 } |
609 } | 612 } |
OLD | NEW |