OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/time.h" | 13 #include "base/time.h" |
13 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
14 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
15 #include "chrome/browser/defaults.h" | 16 #include "chrome/browser/defaults.h" |
16 #include "chrome/browser/sessions/base_session_service.h" | 17 #include "chrome/browser/sessions/base_session_service.h" |
17 #include "chrome/browser/sessions/session_id.h" | 18 #include "chrome/browser/sessions/session_id.h" |
18 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 // callback invokes OnGotSessionCommands from which we map the | 169 // callback invokes OnGotSessionCommands from which we map the |
169 // SessionCommands to browser state, then notify the callback. | 170 // SessionCommands to browser state, then notify the callback. |
170 Handle GetCurrentSession(CancelableRequestConsumerBase* consumer, | 171 Handle GetCurrentSession(CancelableRequestConsumerBase* consumer, |
171 SessionCallback* callback); | 172 SessionCallback* callback); |
172 | 173 |
173 // Overridden from BaseSessionService because we want some UMA reporting on | 174 // Overridden from BaseSessionService because we want some UMA reporting on |
174 // session update activities. | 175 // session update activities. |
175 virtual void Save(); | 176 virtual void Save(); |
176 | 177 |
177 private: | 178 private: |
178 typedef std::map<SessionID::id_type,std::pair<int,int> > IdToRange; | 179 typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange; |
179 typedef std::map<SessionID::id_type,SessionTab*> IdToSessionTab; | 180 typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab; |
180 typedef std::map<SessionID::id_type,SessionWindow*> IdToSessionWindow; | 181 typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow; |
| 182 |
181 | 183 |
182 virtual ~SessionService(); | 184 virtual ~SessionService(); |
183 | 185 |
184 // These types mirror Browser::Type, but are re-defined here because these | 186 // These types mirror Browser::Type, but are re-defined here because these |
185 // specific enumeration _values_ are written into the session database and | 187 // specific enumeration _values_ are written into the session database and |
186 // are needed to maintain forward compatibility. | 188 // are needed to maintain forward compatibility. |
187 enum WindowType { | 189 enum WindowType { |
188 TYPE_NORMAL = 0, | 190 TYPE_NORMAL = 0, |
189 TYPE_POPUP = 1, | 191 TYPE_POPUP = 1, |
190 TYPE_APP = 2, | 192 TYPE_APP = 2, |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 int index); | 280 int index); |
279 | 281 |
280 // Does the following: | 282 // Does the following: |
281 // . Deletes and removes any windows with no tabs or windows with types other | 283 // . Deletes and removes any windows with no tabs or windows with types other |
282 // than tabbed_browser or browser. NOTE: constrained windows that have | 284 // than tabbed_browser or browser. NOTE: constrained windows that have |
283 // been dragged out are of type browser. As such, this preserves any dragged | 285 // been dragged out are of type browser. As such, this preserves any dragged |
284 // out constrained windows (aka popups that have been dragged out). | 286 // out constrained windows (aka popups that have been dragged out). |
285 // . Sorts the tabs in windows with valid tabs based on the tabs | 287 // . Sorts the tabs in windows with valid tabs based on the tabs |
286 // visual order, and adds the valid windows to windows. | 288 // visual order, and adds the valid windows to windows. |
287 void SortTabsBasedOnVisualOrderAndPrune( | 289 void SortTabsBasedOnVisualOrderAndPrune( |
288 std::map<int,SessionWindow*>* windows, | 290 std::map<int, SessionWindow*>* windows, |
289 std::vector<SessionWindow*>* valid_windows); | 291 std::vector<SessionWindow*>* valid_windows); |
290 | 292 |
291 // Adds tabs to their parent window based on the tab's window_id. This | 293 // Adds tabs to their parent window based on the tab's window_id. This |
292 // ignores tabs with no navigations. | 294 // ignores tabs with no navigations. |
293 void AddTabsToWindows(std::map<int,SessionTab*>* tabs, | 295 void AddTabsToWindows(std::map<int, SessionTab*>* tabs, |
294 std::map<int,SessionWindow*>* windows); | 296 std::map<int, SessionWindow*>* windows); |
295 | 297 |
296 // Creates tabs and windows from the specified commands. The created tabs | 298 // Creates tabs and windows from the specified commands. The created tabs |
297 // and windows are added to |tabs| and |windows| respectively. It is up to | 299 // and windows are added to |tabs| and |windows| respectively. It is up to |
298 // the caller to delete the tabs and windows added to |tabs| and |windows|. | 300 // the caller to delete the tabs and windows added to |tabs| and |windows|. |
299 // | 301 // |
300 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is | 302 // This does NOT add any created SessionTabs to SessionWindow.tabs, that is |
301 // done by AddTabsToWindows. | 303 // done by AddTabsToWindows. |
302 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data, | 304 bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data, |
303 std::map<int,SessionTab*>* tabs, | 305 std::map<int, SessionTab*>* tabs, |
304 std::map<int,SessionWindow*>* windows); | 306 std::map<int, SessionWindow*>* windows); |
305 | 307 |
306 // Adds commands to commands that will recreate the state of the specified | 308 // Adds commands to commands that will recreate the state of the specified |
307 // NavigationController. This adds at most kMaxNavigationCountToPersist | 309 // NavigationController. This adds at most kMaxNavigationCountToPersist |
308 // navigations (in each direction from the current navigation index). | 310 // navigations (in each direction from the current navigation index). |
309 // A pair is added to tab_to_available_range indicating the range of | 311 // A pair is added to tab_to_available_range indicating the range of |
310 // indices that were written. | 312 // indices that were written. |
311 void BuildCommandsForTab( | 313 void BuildCommandsForTab( |
312 const SessionID& window_id, | 314 const SessionID& window_id, |
313 NavigationController* controller, | 315 NavigationController* controller, |
314 int index_in_window, | 316 int index_in_window, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 bool should_record_close_as_pending() const { | 376 bool should_record_close_as_pending() const { |
375 // When this is called, the browser window being closed is still open, hence | 377 // When this is called, the browser window being closed is still open, hence |
376 // still in the browser list. If there is a browser window other than the | 378 // still in the browser list. If there is a browser window other than the |
377 // one being closed but no trackable windows, then the others must be App | 379 // one being closed but no trackable windows, then the others must be App |
378 // windows or similar. In this case, we record the close as pending. | 380 // windows or similar. In this case, we record the close as pending. |
379 return !has_open_trackable_browsers_ && | 381 return !has_open_trackable_browsers_ && |
380 (!browser_defaults::kBrowserAliveWithNoWindows || | 382 (!browser_defaults::kBrowserAliveWithNoWindows || |
381 BrowserList::size() > 1); | 383 BrowserList::size() > 1); |
382 } | 384 } |
383 | 385 |
384 // Call when a Save() occurs to record this in UMA stats. | 386 // Call when certain session relevant notifications |
385 void RecordSaveHistogramData(); | 387 // (tab_closed, nav_list_pruned) occur. In addition, this is |
| 388 // currently called when Save() is called to compare how often the |
| 389 // session data is currently saved verses when we may want to save it. |
| 390 // It records the data in UMA stats. |
| 391 void RecordSessionUpdateHistogramData(NotificationType type, |
| 392 base::TimeTicks* last_updated_time); |
| 393 |
| 394 // Helper methods to record the histogram data |
| 395 void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period); |
| 396 void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period); |
| 397 void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period); |
| 398 void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period); |
| 399 void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta, |
| 400 bool use_long_period); |
386 | 401 |
387 // Convert back/forward between the Browser and SessionService DB window | 402 // Convert back/forward between the Browser and SessionService DB window |
388 // types. | 403 // types. |
389 static WindowType WindowTypeForBrowserType(Browser::Type type); | 404 static WindowType WindowTypeForBrowserType(Browser::Type type); |
390 static Browser::Type BrowserTypeForWindowType(WindowType type); | 405 static Browser::Type BrowserTypeForWindowType(WindowType type); |
391 | 406 |
392 NotificationRegistrar registrar_; | 407 NotificationRegistrar registrar_; |
393 | 408 |
394 // Maps from session tab id to the range of navigation entries that has | 409 // Maps from session tab id to the range of navigation entries that has |
395 // been written to disk. | 410 // been written to disk. |
(...skipping 26 matching lines...) Expand all Loading... |
422 | 437 |
423 // Are there any open trackable browsers? | 438 // Are there any open trackable browsers? |
424 bool has_open_trackable_browsers_; | 439 bool has_open_trackable_browsers_; |
425 | 440 |
426 // If true and a new tabbed browser is created and there are no opened tabbed | 441 // If true and a new tabbed browser is created and there are no opened tabbed |
427 // browser (has_open_trackable_browsers_ is false), then the current session | 442 // browser (has_open_trackable_browsers_ is false), then the current session |
428 // is made the previous session. See description above class for details on | 443 // is made the previous session. See description above class for details on |
429 // current/previous session. | 444 // current/previous session. |
430 bool move_on_new_browser_; | 445 bool move_on_new_browser_; |
431 | 446 |
432 // Used for reporting frequency of Save() operations. | 447 // Used for reporting frequency of session alteriing operations. |
433 base::TimeTicks last_save_time_; | 448 base::TimeTicks last_updated_tab_closed_time_; |
| 449 base::TimeTicks last_updated_nav_list_pruned_time_; |
| 450 base::TimeTicks last_updated_nav_entry_commit_time_; |
| 451 base::TimeTicks last_updated_save_time_; |
| 452 |
| 453 // Constants used in calculating histogram data. |
| 454 const base::TimeDelta save_delay_in_millis_; |
| 455 const base::TimeDelta save_delay_in_mins_; |
| 456 const base::TimeDelta save_delay_in_hrs_; |
434 | 457 |
435 DISALLOW_COPY_AND_ASSIGN(SessionService); | 458 DISALLOW_COPY_AND_ASSIGN(SessionService); |
436 }; | 459 }; |
437 | 460 |
438 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ | 461 #endif // CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_ |
OLD | NEW |