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

Side by Side Diff: chrome/browser/sessions/session_service.cc

Issue 1331173002: Eliminate BaseSessionServiceDelegateImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@persistent_tab_restore_service_client
Patch Set: Response to reviewv Created 5 years, 3 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
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/chrome_browser.gypi » ('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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/sessions/session_service.h" 5 #include "chrome/browser/sessions/session_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/pickle.h" 17 #include "base/pickle.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "chrome/browser/background/background_mode_manager.h" 19 #include "chrome/browser/background/background_mode_manager.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/defaults.h" 22 #include "chrome/browser/defaults.h"
23 #include "chrome/browser/extensions/tab_helper.h" 23 #include "chrome/browser/extensions/tab_helper.h"
24 #include "chrome/browser/prefs/session_startup_pref.h" 24 #include "chrome/browser/prefs/session_startup_pref.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_manager.h" 26 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/sessions/base_session_service_delegate_impl.h" 27 #include "chrome/browser/sessions/session_common_utils.h"
28 #include "chrome/browser/sessions/session_data_deleter.h" 28 #include "chrome/browser/sessions/session_data_deleter.h"
29 #include "chrome/browser/sessions/session_restore.h" 29 #include "chrome/browser/sessions/session_restore.h"
30 #include "chrome/browser/sessions/session_service_utils.h" 30 #include "chrome/browser/sessions/session_service_utils.h"
31 #include "chrome/browser/sessions/session_tab_helper.h" 31 #include "chrome/browser/sessions/session_tab_helper.h"
32 #include "chrome/browser/ui/browser_iterator.h" 32 #include "chrome/browser/ui/browser_iterator.h"
33 #include "chrome/browser/ui/browser_list.h" 33 #include "chrome/browser/ui/browser_list.h"
34 #include "chrome/browser/ui/browser_tabstrip.h" 34 #include "chrome/browser/ui/browser_tabstrip.h"
35 #include "chrome/browser/ui/browser_window.h" 35 #include "chrome/browser/ui/browser_window.h"
36 #include "chrome/browser/ui/host_desktop.h" 36 #include "chrome/browser/ui/host_desktop.h"
37 #include "chrome/browser/ui/startup/startup_browser_creator.h" 37 #include "chrome/browser/ui/startup/startup_browser_creator.h"
(...skipping 19 matching lines...) Expand all
57 using content::WebContents; 57 using content::WebContents;
58 using sessions::ContentSerializedNavigationBuilder; 58 using sessions::ContentSerializedNavigationBuilder;
59 using sessions::SerializedNavigationEntry; 59 using sessions::SerializedNavigationEntry;
60 60
61 // Every kWritesPerReset commands triggers recreating the file. 61 // Every kWritesPerReset commands triggers recreating the file.
62 static const int kWritesPerReset = 250; 62 static const int kWritesPerReset = 250;
63 63
64 // SessionService ------------------------------------------------------------- 64 // SessionService -------------------------------------------------------------
65 65
66 SessionService::SessionService(Profile* profile) 66 SessionService::SessionService(Profile* profile)
67 : BaseSessionServiceDelegateImpl(true), 67 : profile_(profile),
68 profile_(profile), 68 should_use_delayed_save_(true),
69 base_session_service_( 69 base_session_service_(new sessions::BaseSessionService(
70 new sessions::BaseSessionService( 70 sessions::BaseSessionService::SESSION_RESTORE,
71 sessions::BaseSessionService::SESSION_RESTORE, 71 profile->GetPath(),
72 profile->GetPath(), 72 this)),
73 this)),
74 has_open_trackable_browsers_(false), 73 has_open_trackable_browsers_(false),
75 move_on_new_browser_(false), 74 move_on_new_browser_(false),
76 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), 75 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)),
77 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), 76 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)),
78 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), 77 save_delay_in_hrs_(base::TimeDelta::FromHours(8)),
79 force_browser_not_alive_with_no_windows_(false), 78 force_browser_not_alive_with_no_windows_(false),
80 weak_factory_(this) { 79 weak_factory_(this) {
81 // We should never be created when incognito. 80 // We should never be created when incognito.
82 DCHECK(!profile->IsOffTheRecord()); 81 DCHECK(!profile->IsOffTheRecord());
83 Init(); 82 Init();
84 } 83 }
85 84
86 SessionService::SessionService(const base::FilePath& save_path) 85 SessionService::SessionService(const base::FilePath& save_path)
87 : BaseSessionServiceDelegateImpl(false), 86 : profile_(NULL),
88 profile_(NULL), 87 should_use_delayed_save_(false),
89 base_session_service_( 88 base_session_service_(new sessions::BaseSessionService(
90 new sessions::BaseSessionService( 89 sessions::BaseSessionService::SESSION_RESTORE,
91 sessions::BaseSessionService::SESSION_RESTORE, 90 save_path,
92 save_path, 91 this)),
93 this)),
94 has_open_trackable_browsers_(false), 92 has_open_trackable_browsers_(false),
95 move_on_new_browser_(false), 93 move_on_new_browser_(false),
96 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)), 94 save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)),
97 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)), 95 save_delay_in_mins_(base::TimeDelta::FromMinutes(10)),
98 save_delay_in_hrs_(base::TimeDelta::FromHours(8)), 96 save_delay_in_hrs_(base::TimeDelta::FromHours(8)),
99 force_browser_not_alive_with_no_windows_(false), 97 force_browser_not_alive_with_no_windows_(false),
100 weak_factory_(this) { 98 weak_factory_(this) {
101 Init(); 99 Init();
102 } 100 }
103 101
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 404 }
407 405
408 ScheduleCommand(sessions::CreateTabNavigationPathPrunedFromFrontCommand( 406 ScheduleCommand(sessions::CreateTabNavigationPathPrunedFromFrontCommand(
409 tab_id, count).Pass()); 407 tab_id, count).Pass());
410 } 408 }
411 409
412 void SessionService::UpdateTabNavigation( 410 void SessionService::UpdateTabNavigation(
413 const SessionID& window_id, 411 const SessionID& window_id,
414 const SessionID& tab_id, 412 const SessionID& tab_id,
415 const SerializedNavigationEntry& navigation) { 413 const SerializedNavigationEntry& navigation) {
416 if (!ShouldTrackEntry(navigation.virtual_url()) || 414 if (!ShouldTrackURLForRestore(navigation.virtual_url()) ||
417 !ShouldTrackChangesToWindow(window_id)) { 415 !ShouldTrackChangesToWindow(window_id)) {
418 return; 416 return;
419 } 417 }
420 418
421 if (tab_to_available_range_.find(tab_id.id()) != 419 if (tab_to_available_range_.find(tab_id.id()) !=
422 tab_to_available_range_.end()) { 420 tab_to_available_range_.end()) {
423 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()]; 421 std::pair<int, int>& range = tab_to_available_range_[tab_id.id()];
424 range.first = std::min(navigation.index(), range.first); 422 range.first = std::min(navigation.index(), range.first);
425 range.second = std::max(navigation.index(), range.second); 423 range.second = std::max(navigation.index(), range.second);
426 } 424 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 base::CancelableTaskTracker* tracker) { 500 base::CancelableTaskTracker* tracker) {
503 // OnGotSessionCommands maps the SessionCommands to browser state, then run 501 // OnGotSessionCommands maps the SessionCommands to browser state, then run
504 // the callback. 502 // the callback.
505 return base_session_service_->ScheduleGetLastSessionCommands( 503 return base_session_service_->ScheduleGetLastSessionCommands(
506 base::Bind(&SessionService::OnGotSessionCommands, 504 base::Bind(&SessionService::OnGotSessionCommands,
507 weak_factory_.GetWeakPtr(), 505 weak_factory_.GetWeakPtr(),
508 callback), 506 callback),
509 tracker); 507 tracker);
510 } 508 }
511 509
510 base::SequencedWorkerPool* SessionService::GetBlockingPool() {
511 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
512 return content::BrowserThread::GetBlockingPool();
513 }
514
515 bool SessionService::ShouldUseDelayedSave() {
516 return should_use_delayed_save_;
517 }
518
512 void SessionService::OnSavedCommands() { 519 void SessionService::OnSavedCommands() {
513 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_SESSION_SERVICE_SAVED, 520 RecordSessionUpdateHistogramData(chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
514 &last_updated_save_time_); 521 &last_updated_save_time_);
515 content::NotificationService::current()->Notify( 522 content::NotificationService::current()->Notify(
516 chrome::NOTIFICATION_SESSION_SERVICE_SAVED, 523 chrome::NOTIFICATION_SESSION_SERVICE_SAVED,
517 content::Source<Profile>(profile()), 524 content::Source<Profile>(profile()),
518 content::NotificationService::NoDetails()); 525 content::NotificationService::NoDetails());
519 } 526 }
520 527
521 void SessionService::Init() { 528 void SessionService::Init() {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 base_session_service_->AppendRebuildCommand( 764 base_session_service_->AppendRebuildCommand(
758 sessions::CreateSetTabUserAgentOverrideCommand(session_id, 765 sessions::CreateSetTabUserAgentOverrideCommand(session_id,
759 ua_override)); 766 ua_override));
760 } 767 }
761 768
762 for (int i = min_index; i < max_index; ++i) { 769 for (int i = min_index; i < max_index; ++i) {
763 const NavigationEntry* entry = (i == pending_index) ? 770 const NavigationEntry* entry = (i == pending_index) ?
764 tab->GetController().GetPendingEntry() : 771 tab->GetController().GetPendingEntry() :
765 tab->GetController().GetEntryAtIndex(i); 772 tab->GetController().GetEntryAtIndex(i);
766 DCHECK(entry); 773 DCHECK(entry);
767 if (ShouldTrackEntry(entry->GetVirtualURL())) { 774 if (ShouldTrackURLForRestore(entry->GetVirtualURL())) {
768 const SerializedNavigationEntry navigation = 775 const SerializedNavigationEntry navigation =
769 ContentSerializedNavigationBuilder::FromNavigationEntry(i, *entry); 776 ContentSerializedNavigationBuilder::FromNavigationEntry(i, *entry);
770 base_session_service_->AppendRebuildCommand( 777 base_session_service_->AppendRebuildCommand(
771 CreateUpdateTabNavigationCommand(session_id, navigation)); 778 CreateUpdateTabNavigationCommand(session_id, navigation));
772 } 779 }
773 } 780 }
774 base_session_service_->AppendRebuildCommand( 781 base_session_service_->AppendRebuildCommand(
775 sessions::CreateSetSelectedNavigationIndexCommand(session_id, 782 sessions::CreateSetSelectedNavigationIndexCommand(session_id,
776 current_index)); 783 current_index));
777 784
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 for (chrome::BrowserIterator it; !it.done(); it.Next()) { 1116 for (chrome::BrowserIterator it; !it.done(); it.Next()) {
1110 if ((*it)->profile() == profile()) 1117 if ((*it)->profile() == profile())
1111 return; 1118 return;
1112 } 1119 }
1113 DeleteSessionOnlyData(profile()); 1120 DeleteSessionOnlyData(profile());
1114 } 1121 }
1115 1122
1116 sessions::BaseSessionService* SessionService::GetBaseSessionServiceForTest() { 1123 sessions::BaseSessionService* SessionService::GetBaseSessionServiceForTest() {
1117 return base_session_service_.get(); 1124 return base_session_service_.get();
1118 } 1125 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698