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/win/jumplist.h" | 5 #include "chrome/browser/win/jumplist.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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 } // namespace | 257 } // namespace |
258 | 258 |
259 JumpList::JumpListData::JumpListData() {} | 259 JumpList::JumpListData::JumpListData() {} |
260 | 260 |
261 JumpList::JumpListData::~JumpListData() {} | 261 JumpList::JumpListData::~JumpListData() {} |
262 | 262 |
263 JumpList::JumpList(Profile* profile) | 263 JumpList::JumpList(Profile* profile) |
264 : profile_(profile), | 264 : profile_(profile), |
265 jumplist_data_(new base::RefCountedData<JumpListData>), | 265 jumplist_data_(new base::RefCountedData<JumpListData>), |
266 task_id_(base::CancelableTaskTracker::kBadTaskId), | 266 task_id_(base::CancelableTaskTracker::kBadTaskId), |
267 RefcountedKeyedService(content::BrowserThread::GetTaskRunnerForThread( | |
268 content::BrowserThread::UI)), | |
267 weak_ptr_factory_(this) { | 269 weak_ptr_factory_(this) { |
268 DCHECK(Enabled()); | 270 DCHECK(Enabled()); |
269 // To update JumpList when a tab is added or removed, we add this object to | 271 // To update JumpList when a tab is added or removed, we add this object to |
270 // the observer list of the TabRestoreService class. | 272 // the observer list of the TabRestoreService class. |
271 // When we add this object to the observer list, we save the pointer to this | 273 // When we add this object to the observer list, we save the pointer to this |
272 // TabRestoreService object. This pointer is used when we remove this object | 274 // TabRestoreService object. This pointer is used when we remove this object |
273 // from the observer list. | 275 // from the observer list. |
274 sessions::TabRestoreService* tab_restore_service = | 276 sessions::TabRestoreService* tab_restore_service = |
gab
2016/09/09 19:02:30
Add dependency with TabRestoreService
Ilya Kulshin
2016/09/13 00:01:00
Done.
| |
275 TabRestoreServiceFactory::GetForProfile(profile_); | 277 TabRestoreServiceFactory::GetForProfile(profile_); |
276 if (!tab_restore_service) | 278 if (!tab_restore_service) |
277 return; | 279 return; |
278 | 280 |
279 app_id_ = | 281 app_id_ = |
280 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); | 282 shell_integration::win::GetChromiumModelIdForProfile(profile_->GetPath()); |
281 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); | 283 icon_dir_ = profile_->GetPath().Append(chrome::kJumpListIconDirname); |
282 | 284 |
283 scoped_refptr<history::TopSites> top_sites = | 285 scoped_refptr<history::TopSites> top_sites = |
284 TopSitesFactory::GetForProfile(profile_); | 286 TopSitesFactory::GetForProfile(profile_); |
gab
2016/09/09 19:02:30
Add dependency with TopSites service.
Ilya Kulshin
2016/09/13 00:01:00
Done.
| |
285 if (top_sites) { | 287 if (top_sites) { |
286 // TopSites updates itself after a delay. This is especially noticable when | 288 // TopSites updates itself after a delay. This is especially noticable when |
287 // your profile is empty. Ask TopSites to update itself when jumplist is | 289 // your profile is empty. Ask TopSites to update itself when jumplist is |
288 // initialized. | 290 // initialized. |
289 top_sites->SyncWithHistory(); | 291 top_sites->SyncWithHistory(); |
290 registrar_.reset(new content::NotificationRegistrar); | |
291 // Register as TopSitesObserver so that we can update ourselves when the | 292 // Register as TopSitesObserver so that we can update ourselves when the |
292 // TopSites changes. | 293 // TopSites changes. |
293 top_sites->AddObserver(this); | 294 top_sites->AddObserver(this); |
294 // Register for notification when profile is destroyed to ensure that all | |
295 // observers are detatched at that time. | |
296 registrar_->Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | |
297 content::Source<Profile>(profile_)); | |
298 } | 295 } |
299 tab_restore_service->AddObserver(this); | 296 tab_restore_service->AddObserver(this); |
300 pref_change_registrar_.reset(new PrefChangeRegistrar); | 297 pref_change_registrar_.reset(new PrefChangeRegistrar); |
301 pref_change_registrar_->Init(profile_->GetPrefs()); | 298 pref_change_registrar_->Init(profile_->GetPrefs()); |
302 pref_change_registrar_->Add( | 299 pref_change_registrar_->Add( |
303 prefs::kIncognitoModeAvailability, | 300 prefs::kIncognitoModeAvailability, |
304 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); | 301 base::Bind(&JumpList::OnIncognitoAvailabilityChanged, this)); |
305 } | 302 } |
306 | 303 |
307 JumpList::~JumpList() { | 304 JumpList::~JumpList() { |
308 DCHECK(CalledOnValidThread()); | 305 DCHECK(CalledOnValidThread()); |
309 Terminate(); | 306 Terminate(); |
310 } | 307 } |
311 | 308 |
312 // static | 309 // static |
313 bool JumpList::Enabled() { | 310 bool JumpList::Enabled() { |
314 return JumpListUpdater::IsEnabled(); | 311 return JumpListUpdater::IsEnabled(); |
315 } | 312 } |
316 | 313 |
317 void JumpList::Observe(int type, | |
318 const content::NotificationSource& source, | |
319 const content::NotificationDetails& details) { | |
320 DCHECK(CalledOnValidThread()); | |
321 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type); | |
322 // Profile was destroyed, do clean-up. | |
323 Terminate(); | |
324 } | |
325 | |
326 void JumpList::CancelPendingUpdate() { | 314 void JumpList::CancelPendingUpdate() { |
327 DCHECK(CalledOnValidThread()); | 315 DCHECK(CalledOnValidThread()); |
328 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { | 316 if (task_id_ != base::CancelableTaskTracker::kBadTaskId) { |
329 cancelable_task_tracker_.TryCancel(task_id_); | 317 cancelable_task_tracker_.TryCancel(task_id_); |
330 task_id_ = base::CancelableTaskTracker::kBadTaskId; | 318 task_id_ = base::CancelableTaskTracker::kBadTaskId; |
331 } | 319 } |
332 } | 320 } |
333 | 321 |
334 void JumpList::Terminate() { | 322 void JumpList::Terminate() { |
335 DCHECK(CalledOnValidThread()); | 323 DCHECK(CalledOnValidThread()); |
336 CancelPendingUpdate(); | 324 CancelPendingUpdate(); |
337 if (profile_) { | 325 if (profile_) { |
338 sessions::TabRestoreService* tab_restore_service = | 326 sessions::TabRestoreService* tab_restore_service = |
339 TabRestoreServiceFactory::GetForProfile(profile_); | 327 TabRestoreServiceFactory::GetForProfile(profile_); |
340 if (tab_restore_service) | 328 if (tab_restore_service) |
341 tab_restore_service->RemoveObserver(this); | 329 tab_restore_service->RemoveObserver(this); |
342 scoped_refptr<history::TopSites> top_sites = | 330 scoped_refptr<history::TopSites> top_sites = |
343 TopSitesFactory::GetForProfile(profile_); | 331 TopSitesFactory::GetForProfile(profile_); |
344 if (top_sites) | 332 if (top_sites) |
345 top_sites->RemoveObserver(this); | 333 top_sites->RemoveObserver(this); |
346 registrar_.reset(); | |
347 pref_change_registrar_.reset(); | 334 pref_change_registrar_.reset(); |
348 } | 335 } |
349 profile_ = NULL; | 336 profile_ = NULL; |
350 } | 337 } |
351 | 338 |
339 void JumpList::ShutdownOnUIThread() { | |
340 DCHECK(CalledOnValidThread()); | |
341 Terminate(); | |
342 } | |
343 | |
352 void JumpList::OnMostVisitedURLsAvailable( | 344 void JumpList::OnMostVisitedURLsAvailable( |
353 const history::MostVisitedURLList& urls) { | 345 const history::MostVisitedURLList& urls) { |
354 DCHECK(CalledOnValidThread()); | 346 DCHECK(CalledOnValidThread()); |
355 // If we have a pending favicon request, cancel it here (it is out of date). | 347 // If we have a pending favicon request, cancel it here (it is out of date). |
356 CancelPendingUpdate(); | 348 CancelPendingUpdate(); |
357 | 349 |
358 { | 350 { |
359 JumpListData* data = &jumplist_data_->data; | 351 JumpListData* data = &jumplist_data_->data; |
360 base::AutoLock auto_lock(data->list_lock_); | 352 base::AutoLock auto_lock(data->list_lock_); |
361 data->most_visited_pages_.clear(); | 353 data->most_visited_pages_.clear(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 } | 477 } |
486 | 478 |
487 if (!waiting_for_icons) { | 479 if (!waiting_for_icons) { |
488 // No more favicons are needed by the application JumpList. Schedule a | 480 // No more favicons are needed by the application JumpList. Schedule a |
489 // RunUpdateOnFileThread call. | 481 // RunUpdateOnFileThread call. |
490 PostRunUpdate(); | 482 PostRunUpdate(); |
491 return; | 483 return; |
492 } | 484 } |
493 | 485 |
494 favicon::FaviconService* favicon_service = | 486 favicon::FaviconService* favicon_service = |
495 FaviconServiceFactory::GetForProfile(profile_, | 487 FaviconServiceFactory::GetForProfile(profile_, |
gab
2016/09/09 19:02:30
Add dependency on FaviconService
Ilya Kulshin
2016/09/13 00:01:00
Done.
| |
496 ServiceAccessType::EXPLICIT_ACCESS); | 488 ServiceAccessType::EXPLICIT_ACCESS); |
497 task_id_ = favicon_service->GetFaviconImageForPageURL( | 489 task_id_ = favicon_service->GetFaviconImageForPageURL( |
498 url, | 490 url, |
499 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), | 491 base::Bind(&JumpList::OnFaviconDataAvailable, base::Unretained(this)), |
500 &cancelable_task_tracker_); | 492 &cancelable_task_tracker_); |
501 } | 493 } |
502 | 494 |
503 void JumpList::OnFaviconDataAvailable( | 495 void JumpList::OnFaviconDataAvailable( |
504 const favicon_base::FaviconImageResult& image_result) { | 496 const favicon_base::FaviconImageResult& image_result) { |
505 DCHECK(CalledOnValidThread()); | 497 DCHECK(CalledOnValidThread()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
580 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { | 572 void JumpList::TopSitesLoaded(history::TopSites* top_sites) { |
581 } | 573 } |
582 | 574 |
583 void JumpList::TopSitesChanged(history::TopSites* top_sites, | 575 void JumpList::TopSitesChanged(history::TopSites* top_sites, |
584 ChangeReason change_reason) { | 576 ChangeReason change_reason) { |
585 top_sites->GetMostVisitedURLs( | 577 top_sites->GetMostVisitedURLs( |
586 base::Bind(&JumpList::OnMostVisitedURLsAvailable, | 578 base::Bind(&JumpList::OnMostVisitedURLsAvailable, |
587 weak_ptr_factory_.GetWeakPtr()), | 579 weak_ptr_factory_.GetWeakPtr()), |
588 false); | 580 false); |
589 } | 581 } |
OLD | NEW |