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

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

Issue 1309363007: [sessions] Remove most knowledge of //chrome from core tab restore code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tab_restore_service_client
Patch Set: Make OnTabRestored() optional 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
OLDNEW
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/sessions/persistent_tab_restore_service.h" 5 #include "chrome/browser/sessions/persistent_tab_restore_service.h"
6 6
7 #include <cstring> // memcpy 7 #include <cstring> // memcpy
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/task/cancelable_task_tracker.h" 18 #include "base/task/cancelable_task_tracker.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sessions/base_session_service_delegate_impl.h" 20 #include "chrome/browser/sessions/base_session_service_delegate_impl.h"
22 #include "components/sessions/base_session_service.h" 21 #include "components/sessions/base_session_service.h"
23 #include "components/sessions/base_session_service_commands.h" 22 #include "components/sessions/base_session_service_commands.h"
24 #include "components/sessions/core/session_constants.h" 23 #include "components/sessions/core/session_constants.h"
25 #include "components/sessions/session_command.h" 24 #include "components/sessions/session_command.h"
26 #include "content/public/browser/session_storage_namespace.h" 25 #include "content/public/browser/session_storage_namespace.h"
27 26
28 namespace { 27 namespace {
29 28
30 // Only written if the tab is pinned. 29 // Only written if the tab is pinned.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } // namespace 110 } // namespace
112 111
113 // PersistentTabRestoreService::Delegate --------------------------------------- 112 // PersistentTabRestoreService::Delegate ---------------------------------------
114 113
115 // This restore service will create and own a BaseSessionService and implement 114 // This restore service will create and own a BaseSessionService and implement
116 // the required BaseSessionServiceDelegateImpl. 115 // the required BaseSessionServiceDelegateImpl.
117 class PersistentTabRestoreService::Delegate 116 class PersistentTabRestoreService::Delegate
118 : public BaseSessionServiceDelegateImpl, 117 : public BaseSessionServiceDelegateImpl,
119 public TabRestoreServiceHelper::Observer { 118 public TabRestoreServiceHelper::Observer {
120 public: 119 public:
121 Delegate(Profile* profile, sessions::TabRestoreServiceClient* client); 120 explicit Delegate(sessions::TabRestoreServiceClient* client);
122 121
123 ~Delegate() override; 122 ~Delegate() override;
124 123
125 // BaseSessionServiceDelegateImpl: 124 // BaseSessionServiceDelegateImpl:
126 void OnWillSaveCommands() override; 125 void OnWillSaveCommands() override;
127 126
128 // TabRestoreServiceHelper::Observer: 127 // TabRestoreServiceHelper::Observer:
129 void OnClearEntries() override; 128 void OnClearEntries() override;
130 void OnRestoreEntryById(SessionID::id_type id, 129 void OnRestoreEntryById(SessionID::id_type id,
131 Entries::const_iterator entry_iterator) override; 130 Entries::const_iterator entry_iterator) override;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 // If |id_to_entry| contains an entry for |id| the corresponding entry is 215 // If |id_to_entry| contains an entry for |id| the corresponding entry is
217 // deleted and removed from both |id_to_entry| and |entries|. This is used 216 // deleted and removed from both |id_to_entry| and |entries|. This is used
218 // when creating entries from the backend file. 217 // when creating entries from the backend file.
219 void RemoveEntryByID(SessionID::id_type id, 218 void RemoveEntryByID(SessionID::id_type id,
220 IDToEntry* id_to_entry, 219 IDToEntry* id_to_entry,
221 std::vector<TabRestoreService::Entry*>* entries); 220 std::vector<TabRestoreService::Entry*>* entries);
222 221
223 private: 222 private:
224 scoped_ptr<sessions::BaseSessionService> base_session_service_; 223 scoped_ptr<sessions::BaseSessionService> base_session_service_;
225 224
226 // The associated profile.
227 Profile* profile_;
228
229 // The associated client. 225 // The associated client.
230 sessions::TabRestoreServiceClient* client_; 226 sessions::TabRestoreServiceClient* client_;
231 227
232 TabRestoreServiceHelper* tab_restore_service_helper_; 228 TabRestoreServiceHelper* tab_restore_service_helper_;
233 229
234 // The number of entries to write. 230 // The number of entries to write.
235 int entries_to_write_; 231 int entries_to_write_;
236 232
237 // Number of entries we've written. 233 // Number of entries we've written.
238 int entries_written_; 234 int entries_written_;
239 235
240 // Whether we've loaded the last session. 236 // Whether we've loaded the last session.
241 int load_state_; 237 int load_state_;
242 238
243 // Results from previously closed tabs/sessions is first added here. When the 239 // Results from previously closed tabs/sessions is first added here. When the
244 // results from both us and the session restore service have finished loading 240 // results from both us and the session restore service have finished loading
245 // LoadStateChanged is invoked, which adds these entries to entries_. 241 // LoadStateChanged is invoked, which adds these entries to entries_.
246 ScopedVector<Entry> staging_entries_; 242 ScopedVector<Entry> staging_entries_;
247 243
248 // Used when loading previous tabs/session and open tabs/session. 244 // Used when loading previous tabs/session and open tabs/session.
249 base::CancelableTaskTracker cancelable_task_tracker_; 245 base::CancelableTaskTracker cancelable_task_tracker_;
250 246
251 DISALLOW_COPY_AND_ASSIGN(Delegate); 247 DISALLOW_COPY_AND_ASSIGN(Delegate);
252 }; 248 };
253 249
254 PersistentTabRestoreService::Delegate::Delegate( 250 PersistentTabRestoreService::Delegate::Delegate(
255 Profile* profile,
256 sessions::TabRestoreServiceClient* client) 251 sessions::TabRestoreServiceClient* client)
257 : BaseSessionServiceDelegateImpl(true), 252 : BaseSessionServiceDelegateImpl(true),
258 base_session_service_(new sessions::BaseSessionService( 253 base_session_service_(new sessions::BaseSessionService(
259 sessions::BaseSessionService::TAB_RESTORE, 254 sessions::BaseSessionService::TAB_RESTORE,
260 profile->GetPath(), 255 client->GetPathToSaveTo(),
261 this)), 256 this)),
262 profile_(profile),
263 client_(client), 257 client_(client),
264 tab_restore_service_helper_(NULL), 258 tab_restore_service_helper_(NULL),
265 entries_to_write_(0), 259 entries_to_write_(0),
266 entries_written_(0), 260 entries_written_(0),
267 load_state_(NOT_LOADED) { 261 load_state_(NOT_LOADED) {}
268 // We should never be created when incognito.
269 DCHECK(!profile->IsOffTheRecord());
270 }
271 262
272 PersistentTabRestoreService::Delegate::~Delegate() {} 263 PersistentTabRestoreService::Delegate::~Delegate() {}
273 264
274 void PersistentTabRestoreService::Delegate::OnWillSaveCommands() { 265 void PersistentTabRestoreService::Delegate::OnWillSaveCommands() {
275 const Entries& entries = tab_restore_service_helper_->entries(); 266 const Entries& entries = tab_restore_service_helper_->entries();
276 int to_write_count = std::min(entries_to_write_, 267 int to_write_count = std::min(entries_to_write_,
277 static_cast<int>(entries.size())); 268 static_cast<int>(entries.size()));
278 entries_to_write_ = 0; 269 entries_to_write_ = 0;
279 if (entries_written_ + to_write_count > kEntriesPerReset) { 270 if (entries_written_ + to_write_count > kEntriesPerReset) {
280 to_write_count = entries.size(); 271 to_write_count = entries.size();
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 } 911 }
921 } 912 }
922 913
923 // PersistentTabRestoreService ------------------------------------------------- 914 // PersistentTabRestoreService -------------------------------------------------
924 915
925 PersistentTabRestoreService::PersistentTabRestoreService( 916 PersistentTabRestoreService::PersistentTabRestoreService(
926 Profile* profile, 917 Profile* profile,
927 scoped_ptr<sessions::TabRestoreServiceClient> client, 918 scoped_ptr<sessions::TabRestoreServiceClient> client,
928 TimeFactory* time_factory) 919 TimeFactory* time_factory)
929 : client_(client.Pass()), 920 : client_(client.Pass()),
930 delegate_(new Delegate(profile, client_.get())), 921 delegate_(new Delegate(client_.get())),
931 helper_(this, delegate_.get(), profile, time_factory) { 922 helper_(this, delegate_.get(), profile, client_.get(), time_factory) {
932 delegate_->set_tab_restore_service_helper(&helper_); 923 delegate_->set_tab_restore_service_helper(&helper_);
933 } 924 }
934 925
935 PersistentTabRestoreService::~PersistentTabRestoreService() {} 926 PersistentTabRestoreService::~PersistentTabRestoreService() {}
936 927
937 void PersistentTabRestoreService::AddObserver( 928 void PersistentTabRestoreService::AddObserver(
938 TabRestoreServiceObserver* observer) { 929 TabRestoreServiceObserver* observer) {
939 helper_.AddObserver(observer); 930 helper_.AddObserver(observer);
940 } 931 }
941 932
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 delegate_->LoadTabsFromLastSession(); 996 delegate_->LoadTabsFromLastSession();
1006 } 997 }
1007 998
1008 TabRestoreService::Entries* PersistentTabRestoreService::mutable_entries() { 999 TabRestoreService::Entries* PersistentTabRestoreService::mutable_entries() {
1009 return &helper_.entries_; 1000 return &helper_.entries_;
1010 } 1001 }
1011 1002
1012 void PersistentTabRestoreService::PruneEntries() { 1003 void PersistentTabRestoreService::PruneEntries() {
1013 helper_.PruneEntries(); 1004 helper_.PruneEntries();
1014 } 1005 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/in_memory_tab_restore_service.cc ('k') | chrome/browser/sessions/tab_restore_service_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698