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

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

Issue 694813003: Changing SessionService to have a BaseSessionService, not being one. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed non ChromeOS builds Created 6 years, 1 month 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 (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 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 5 #ifndef CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 6 #define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/memory/scoped_vector.h" 13 #include "base/memory/scoped_vector.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/task/cancelable_task_tracker.h" 15 #include "base/task/cancelable_task_tracker.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/defaults.h" 17 #include "chrome/browser/defaults.h"
18 #include "chrome/browser/sessions/base_session_service.h" 18 #include "chrome/browser/sessions/base_session_service_delegate_impl.h"
19 #include "chrome/browser/sessions/session_service_commands.h" 19 #include "chrome/browser/sessions/session_service_commands.h"
20 #include "chrome/browser/sessions/session_service_utils.h" 20 #include "chrome/browser/sessions/session_service_utils.h"
21 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/browser_finder.h" 22 #include "chrome/browser/ui/browser_finder.h"
23 #include "chrome/browser/ui/browser_list_observer.h" 23 #include "chrome/browser/ui/browser_list_observer.h"
24 #include "components/keyed_service/core/keyed_service.h" 24 #include "components/keyed_service/core/keyed_service.h"
25 #include "content/public/browser/notification_observer.h" 25 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h" 26 #include "content/public/browser/notification_registrar.h"
27 #include "ui/base/ui_base_types.h" 27 #include "ui/base/ui_base_types.h"
28 28
(...skipping 20 matching lines...) Expand all
49 // the last session and the current session reset. This is done to provide the 49 // the last session and the current session reset. This is done to provide the
50 // illusion that app windows run in separate processes. Similar behavior occurs 50 // illusion that app windows run in separate processes. Similar behavior occurs
51 // with incognito windows. 51 // with incognito windows.
52 // 52 //
53 // SessionService itself uses functions from session_service_commands to store 53 // SessionService itself uses functions from session_service_commands to store
54 // commands which can rebuild the open state of the browser (as |SessionWindow|, 54 // commands which can rebuild the open state of the browser (as |SessionWindow|,
55 // |SessionTab| and |SerializedNavigationEntry|). The commands are periodically 55 // |SessionTab| and |SerializedNavigationEntry|). The commands are periodically
56 // flushed to |SessionBackend| and written to a file. Every so often 56 // flushed to |SessionBackend| and written to a file. Every so often
57 // |SessionService| rebuilds the contents of the file from the open state of the 57 // |SessionService| rebuilds the contents of the file from the open state of the
58 // browser. 58 // browser.
59 class SessionService : public BaseSessionService, 59 class SessionService : public BaseSessionServiceDelegateImpl,
60 public KeyedService, 60 public KeyedService,
61 public content::NotificationObserver, 61 public content::NotificationObserver,
62 public chrome::BrowserListObserver { 62 public chrome::BrowserListObserver {
63 friend class SessionServiceTestHelper; 63 friend class SessionServiceTestHelper;
64 public: 64 public:
65 // Used to distinguish an application from a ordinary content window. 65 // Used to distinguish an application from a ordinary content window.
66 enum AppType { 66 enum AppType {
67 TYPE_APP, 67 TYPE_APP,
68 TYPE_NORMAL 68 TYPE_NORMAL
69 }; 69 };
(...skipping 23 matching lines...) Expand all
93 93
94 // Resets the contents of the file from the current state of all open 94 // Resets the contents of the file from the current state of all open
95 // browsers whose profile matches our profile. 95 // browsers whose profile matches our profile.
96 void ResetFromCurrentBrowsers(); 96 void ResetFromCurrentBrowsers();
97 97
98 // Moves the current session to the last session. This is useful when a 98 // Moves the current session to the last session. This is useful when a
99 // checkpoint occurs, such as when the user launches the app and no tabbed 99 // checkpoint occurs, such as when the user launches the app and no tabbed
100 // browsers are running. 100 // browsers are running.
101 void MoveCurrentSessionToLastSession(); 101 void MoveCurrentSessionToLastSession();
102 102
103 // Deletes the last session.
104 void DeleteLastSession();
105
103 // Associates a tab with a window. 106 // Associates a tab with a window.
104 void SetTabWindow(const SessionID& window_id, 107 void SetTabWindow(const SessionID& window_id,
105 const SessionID& tab_id); 108 const SessionID& tab_id);
106 109
107 // Sets the bounds of a window. 110 // Sets the bounds of a window.
108 void SetWindowBounds(const SessionID& window_id, 111 void SetWindowBounds(const SessionID& window_id,
109 const gfx::Rect& bounds, 112 const gfx::Rect& bounds,
110 ui::WindowShowState show_state); 113 ui::WindowShowState show_state);
111 114
112 // Sets the visual index of the tab in its parent window. 115 // Sets the visual index of the tab in its parent window.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)> 203 typedef base::Callback<void(ScopedVector<SessionWindow>, SessionID::id_type)>
201 SessionCallback; 204 SessionCallback;
202 205
203 // Fetches the contents of the last session, notifying the callback when 206 // Fetches the contents of the last session, notifying the callback when
204 // done. If the callback is supplied an empty vector of SessionWindows 207 // done. If the callback is supplied an empty vector of SessionWindows
205 // it means the session could not be restored. 208 // it means the session could not be restored.
206 base::CancelableTaskTracker::TaskId GetLastSession( 209 base::CancelableTaskTracker::TaskId GetLastSession(
207 const SessionCallback& callback, 210 const SessionCallback& callback,
208 base::CancelableTaskTracker* tracker); 211 base::CancelableTaskTracker* tracker);
209 212
210 // Overridden from BaseSessionService because we want some UMA reporting on 213 // BaseSessionServiceDelegateImpl:
211 // session update activities. 214 void OnSavedCommands() override;
212 void Save() override; 215
216 // Unit test accessors.
217 BaseSessionService* GetBaseSessionServiceForTest();
sky 2014/10/31 22:36:17 Same comment about preferring friend here.
Mr4D (OOO till 08-26) 2014/11/01 01:28:24 Done.
213 218
214 private: 219 private:
215 // Allow tests to access our innards for testing purposes. 220 // Allow tests to access our innards for testing purposes.
216 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1); 221 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation1);
217 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2); 222 FRIEND_TEST_ALL_PREFIXES(SessionServiceTest, RestoreActivation2);
218 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps); 223 FRIEND_TEST_ALL_PREFIXES(NoStartupWindowTest, DontInitSessionServiceForApps);
219 224
220 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; 225 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange;
221 226
222 void Init(); 227 void Init();
223 228
224 // Returns true if a window of given |window_type| and |app_type| should get 229 // Returns true if a window of given |window_type| and |app_type| should get
225 // restored upon session restore. 230 // restored upon session restore.
226 bool ShouldRestoreWindowOfType(SessionWindow::WindowType type, 231 bool ShouldRestoreWindowOfType(SessionWindow::WindowType type,
227 AppType app_type) const; 232 AppType app_type) const;
228 233
229 // Removes unrestorable windows from the previous windows list. 234 // Removes unrestorable windows from the previous windows list.
230 void RemoveUnusedRestoreWindows(std::vector<SessionWindow*>* window_list); 235 void RemoveUnusedRestoreWindows(std::vector<SessionWindow*>* window_list);
231 236
232 // Returns true if we have scheduled any commands, or any scheduled commands
233 // have been saved.
234 bool processed_any_commands();
235
236 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need 237 // Implementation of RestoreIfNecessary. If |browser| is non-null and we need
237 // to restore, the tabs are added to it, otherwise a new browser is created. 238 // to restore, the tabs are added to it, otherwise a new browser is created.
238 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open, 239 bool RestoreIfNecessary(const std::vector<GURL>& urls_to_open,
239 Browser* browser); 240 Browser* browser);
240 241
241 void Observe(int type, 242 void Observe(int type,
242 const content::NotificationSource& source, 243 const content::NotificationSource& source,
243 const content::NotificationDetails& details) override; 244 const content::NotificationDetails& details) override;
244 245
245 // chrome::BrowserListObserver 246 // chrome::BrowserListObserver
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 void BuildCommandsFromBrowsers( 281 void BuildCommandsFromBrowsers(
281 ScopedVector<SessionCommand>* commands, 282 ScopedVector<SessionCommand>* commands,
282 IdToRange* tab_to_available_range, 283 IdToRange* tab_to_available_range,
283 std::set<SessionID::id_type>* windows_to_track); 284 std::set<SessionID::id_type>* windows_to_track);
284 285
285 // Schedules a reset of the existing commands. A reset means the contents 286 // Schedules a reset of the existing commands. A reset means the contents
286 // of the file are recreated from the state of the browser. 287 // of the file are recreated from the state of the browser.
287 void ScheduleResetCommands(); 288 void ScheduleResetCommands();
288 289
289 // Schedules the specified command. 290 // Schedules the specified command.
290 void ScheduleCommand(scoped_ptr<SessionCommand> command) override; 291 void ScheduleCommand(scoped_ptr<SessionCommand> command);
291 292
292 // Converts all pending tab/window closes to commands and schedules them. 293 // Converts all pending tab/window closes to commands and schedules them.
293 void CommitPendingCloses(); 294 void CommitPendingCloses();
294 295
295 // Returns true if there is only one window open with a single tab that shares 296 // Returns true if there is only one window open with a single tab that shares
296 // our profile. 297 // our profile.
297 bool IsOnlyOneTabLeft() const; 298 bool IsOnlyOneTabLeft() const;
298 299
299 // Returns true if there are open trackable browser windows whose ids do 300 // Returns true if there are open trackable browser windows whose ids do
300 // match |window_id| with our profile. A trackable window is a window from 301 // match |window_id| with our profile. A trackable window is a window from
(...skipping 22 matching lines...) Expand all
323 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); 324 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period);
324 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, 325 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta,
325 bool use_long_period); 326 bool use_long_period);
326 327
327 // Deletes session data if no windows are open for the current profile. 328 // Deletes session data if no windows are open for the current profile.
328 void MaybeDeleteSessionOnlyData(); 329 void MaybeDeleteSessionOnlyData();
329 330
330 // The profile. This may be null during testing. 331 // The profile. This may be null during testing.
331 Profile* profile_; 332 Profile* profile_;
332 333
334 // The owned BaseSessionService.
335 scoped_ptr<BaseSessionService> base_session_service_;
336
333 content::NotificationRegistrar registrar_; 337 content::NotificationRegistrar registrar_;
334 338
335 // Maps from session tab id to the range of navigation entries that has 339 // Maps from session tab id to the range of navigation entries that has
336 // been written to disk. 340 // been written to disk.
337 // 341 //
338 // This is only used if not all the navigation entries have been 342 // This is only used if not all the navigation entries have been
339 // written. 343 // written.
340 IdToRange tab_to_available_range_; 344 IdToRange tab_to_available_range_;
341 345
342 // When the user closes the last window, where the last window is the 346 // When the user closes the last window, where the last window is the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // For browser_tests, since we want to simulate the browser shutting down 388 // For browser_tests, since we want to simulate the browser shutting down
385 // without quitting. 389 // without quitting.
386 bool force_browser_not_alive_with_no_windows_; 390 bool force_browser_not_alive_with_no_windows_;
387 391
388 base::WeakPtrFactory<SessionService> weak_factory_; 392 base::WeakPtrFactory<SessionService> weak_factory_;
389 393
390 DISALLOW_COPY_AND_ASSIGN(SessionService); 394 DISALLOW_COPY_AND_ASSIGN(SessionService);
391 }; 395 };
392 396
393 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ 397 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698