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

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

Issue 6901031: Profile shouldn't own Session/TabRestore services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again and hope upload works this time Created 9 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <windows.h> 7 #include <windows.h>
8 #include <shobjidl.h> 8 #include <shobjidl.h>
9 #include <propkey.h> 9 #include <propkey.h>
10 #include <propvarutil.h> 10 #include <propvarutil.h>
11 11
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/command_line.h" 16 #include "base/command_line.h"
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "base/path_service.h" 18 #include "base/path_service.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "base/win/scoped_comptr.h" 22 #include "base/win/scoped_comptr.h"
23 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
24 #include "chrome/browser/favicon_service.h" 24 #include "chrome/browser/favicon_service.h"
25 #include "chrome/browser/history/history.h" 25 #include "chrome/browser/history/history.h"
26 #include "chrome/browser/history/page_usage_data.h" 26 #include "chrome/browser/history/page_usage_data.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/sessions/session_types.h" 28 #include "chrome/browser/sessions/session_types.h"
29 #include "chrome/browser/sessions/tab_restore_service.h" 29 #include "chrome/browser/sessions/tab_restore_service.h"
30 #include "chrome/browser/sessions/tab_restore_service_factory.h"
30 #include "chrome/browser/shell_integration.h" 31 #include "chrome/browser/shell_integration.h"
31 #include "chrome/common/chrome_constants.h" 32 #include "chrome/common/chrome_constants.h"
32 #include "chrome/common/chrome_switches.h" 33 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
34 #include "content/browser/browser_thread.h" 35 #include "content/browser/browser_thread.h"
35 #include "googleurl/src/gurl.h" 36 #include "googleurl/src/gurl.h"
36 #include "grit/chromium_strings.h" 37 #include "grit/chromium_strings.h"
37 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
38 #include "third_party/skia/include/core/SkBitmap.h" 39 #include "third_party/skia/include/core/SkBitmap.h"
39 #include "ui/base/l10n/l10n_util.h" 40 #include "ui/base/l10n/l10n_util.h"
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 590
590 bool JumpList::AddObserver(Profile* profile) { 591 bool JumpList::AddObserver(Profile* profile) {
591 // To update JumpList when a tab is added or removed, we add this object to 592 // To update JumpList when a tab is added or removed, we add this object to
592 // the observer list of the TabRestoreService class. 593 // the observer list of the TabRestoreService class.
593 // When we add this object to the observer list, we save the pointer to this 594 // When we add this object to the observer list, we save the pointer to this
594 // TabRestoreService object. This pointer is used when we remove this object 595 // TabRestoreService object. This pointer is used when we remove this object
595 // from the observer list. 596 // from the observer list.
596 if (base::win::GetVersion() < base::win::VERSION_WIN7 || !profile) 597 if (base::win::GetVersion() < base::win::VERSION_WIN7 || !profile)
597 return false; 598 return false;
598 599
599 TabRestoreService* tab_restore_service = profile->GetTabRestoreService(); 600 TabRestoreService* tab_restore_service =
601 TabRestoreServiceFactory::GetForProfile(profile);
600 if (!tab_restore_service) 602 if (!tab_restore_service)
601 return false; 603 return false;
602 604
603 app_id_ = ShellIntegration::GetChromiumAppId(profile->GetPath()); 605 app_id_ = ShellIntegration::GetChromiumAppId(profile->GetPath());
604 icon_dir_ = profile->GetPath().Append(chrome::kJumpListIconDirname); 606 icon_dir_ = profile->GetPath().Append(chrome::kJumpListIconDirname);
605 profile_ = profile; 607 profile_ = profile;
606 tab_restore_service->AddObserver(this); 608 tab_restore_service->AddObserver(this);
607 return true; 609 return true;
608 } 610 }
609 611
610 void JumpList::RemoveObserver() { 612 void JumpList::RemoveObserver() {
611 if (profile_ && profile_->GetTabRestoreService()) 613 if (profile_) {
612 profile_->GetTabRestoreService()->RemoveObserver(this); 614 TabRestoreService* tab_restore_service =
615 TabRestoreServiceFactory::GetForProfile(profile_);
616 if (tab_restore_service)
617 tab_restore_service->RemoveObserver(this);
618 }
613 profile_ = NULL; 619 profile_ = NULL;
614 } 620 }
615 621
616 void JumpList::TabRestoreServiceChanged(TabRestoreService* service) { 622 void JumpList::TabRestoreServiceChanged(TabRestoreService* service) {
617 // Added or removed a tab. 623 // Added or removed a tab.
618 // Exit if we are updating the application JumpList. 624 // Exit if we are updating the application JumpList.
619 if (!icon_urls_.empty()) 625 if (!icon_urls_.empty())
620 return; 626 return;
621 627
622 // Send a query to HistoryService and retrieve the "Most Visited" pages. 628 // Send a query to HistoryService and retrieve the "Most Visited" pages.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 // * arguments 732 // * arguments
727 // The last URL of the tab object. 733 // The last URL of the tab object.
728 // * title 734 // * title
729 // The title of the last URL. 735 // The title of the last URL.
730 // * icon 736 // * icon
731 // An empty string. This value is to be updated in OnFaviconDataAvailable(). 737 // An empty string. This value is to be updated in OnFaviconDataAvailable().
732 // This code is copied from 738 // This code is copied from
733 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it. 739 // RecentlyClosedTabsHandler::TabRestoreServiceChanged() to emulate it.
734 const int kRecentlyClosedCount = 4; 740 const int kRecentlyClosedCount = 4;
735 recently_closed_pages_.clear(); 741 recently_closed_pages_.clear();
736 TabRestoreService* tab_restore_service = profile_->GetTabRestoreService(); 742 TabRestoreService* tab_restore_service =
743 TabRestoreServiceFactory::GetForProfile(profile_);
737 const TabRestoreService::Entries& entries = tab_restore_service->entries(); 744 const TabRestoreService::Entries& entries = tab_restore_service->entries();
738 for (TabRestoreService::Entries::const_iterator it = entries.begin(); 745 for (TabRestoreService::Entries::const_iterator it = entries.begin();
739 it != entries.end(); ++it) { 746 it != entries.end(); ++it) {
740 const TabRestoreService::Entry* entry = *it; 747 const TabRestoreService::Entry* entry = *it;
741 if (entry->type == TabRestoreService::TAB) { 748 if (entry->type == TabRestoreService::TAB) {
742 AddTab(static_cast<const TabRestoreService::Tab*>(entry), 749 AddTab(static_cast<const TabRestoreService::Tab*>(entry),
743 &recently_closed_pages_, kRecentlyClosedCount); 750 &recently_closed_pages_, kRecentlyClosedCount);
744 } else if (entry->type == TabRestoreService::WINDOW) { 751 } else if (entry->type == TabRestoreService::WINDOW) {
745 AddWindow(static_cast<const TabRestoreService::Window*>(entry), 752 AddWindow(static_cast<const TabRestoreService::Window*>(entry),
746 &recently_closed_pages_, kRecentlyClosedCount); 753 &recently_closed_pages_, kRecentlyClosedCount);
(...skipping 25 matching lines...) Expand all
772 // the file thread. 779 // the file thread.
773 BrowserThread::PostTask( 780 BrowserThread::PostTask(
774 BrowserThread::FILE, FROM_HERE, 781 BrowserThread::FILE, FROM_HERE,
775 new JumpListUpdateTask(app_id_.c_str(), icon_dir_, most_visited_pages_, 782 new JumpListUpdateTask(app_id_.c_str(), icon_dir_, most_visited_pages_,
776 recently_closed_pages_)); 783 recently_closed_pages_));
777 784
778 // Delete all items in these lists since we don't need these lists any longer. 785 // Delete all items in these lists since we don't need these lists any longer.
779 most_visited_pages_.clear(); 786 most_visited_pages_.clear();
780 recently_closed_pages_.clear(); 787 recently_closed_pages_.clear();
781 } 788 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data_remover.cc ('k') | chrome/browser/profiles/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698