summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/sessions/session_service.cc166
-rw-r--r--chrome/browser/sessions/session_service.h47
2 files changed, 179 insertions, 34 deletions
diff --git a/chrome/browser/sessions/session_service.cc b/chrome/browser/sessions/session_service.cc
index 1669218..cbd5dc0 100644
--- a/chrome/browser/sessions/session_service.cc
+++ b/chrome/browser/sessions/session_service.cc
@@ -130,14 +130,20 @@ struct PinnedStatePayload {
SessionService::SessionService(Profile* profile)
: BaseSessionService(SESSION_RESTORE, profile, FilePath()),
has_open_trackable_browsers_(false),
- move_on_new_browser_(false) {
+ move_on_new_browser_(false),
+ save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)),
+ save_delay_in_mins_(base::TimeDelta::FromMinutes(10)),
+ save_delay_in_hrs_(base::TimeDelta::FromHours(8)) {
Init();
}
SessionService::SessionService(const FilePath& save_path)
: BaseSessionService(SESSION_RESTORE, NULL, save_path),
has_open_trackable_browsers_(false),
- move_on_new_browser_(false) {
+ move_on_new_browser_(false),
+ save_delay_in_millis_(base::TimeDelta::FromMilliseconds(2500)),
+ save_delay_in_mins_(base::TimeDelta::FromMinutes(10)),
+ save_delay_in_hrs_(base::TimeDelta::FromHours(8)) {
Init();
}
@@ -432,7 +438,8 @@ void SessionService::Save() {
bool had_commands = !pending_commands().empty();
BaseSessionService::Save();
if (had_commands) {
- RecordSaveHistogramData();
+ RecordSessionUpdateHistogramData(NotificationType::SESSION_SERVICE_SAVED,
+ &last_updated_save_time_);
NotificationService::current()->Notify(
NotificationType::SESSION_SERVICE_SAVED,
NotificationService::AllSources(),
@@ -440,7 +447,6 @@ void SessionService::Save() {
}
}
-
void SessionService::Init() {
// Register for the notifications we're interested in.
registrar_.Add(this, NotificationType::TAB_PARENTED,
@@ -523,6 +529,8 @@ void SessionService::Observe(NotificationType type,
Source<NavigationController>(source).ptr();
TabClosed(controller->window_id(), controller->session_id(),
controller->tab_contents()->closed_by_user_gesture());
+ RecordSessionUpdateHistogramData(NotificationType::TAB_CLOSED,
+ &last_updated_tab_closed_time_);
break;
}
@@ -539,6 +547,8 @@ void SessionService::Observe(NotificationType type,
controller->session_id(),
controller->entry_count());
}
+ RecordSessionUpdateHistogramData(NotificationType::NAV_LIST_PRUNED,
+ &last_updated_nav_list_pruned_time_);
break;
}
@@ -561,6 +571,12 @@ void SessionService::Observe(NotificationType type,
UpdateTabNavigation(controller->window_id(), controller->session_id(),
current_entry_index,
*controller->GetEntryAtIndex(current_entry_index));
+ Details<NavigationController::LoadCommittedDetails> changed(details);
+ if (changed->type == NavigationType::NEW_PAGE ||
+ changed->type == NavigationType::EXISTING_PAGE) {
+ RecordSessionUpdateHistogramData(NotificationType::NAV_ENTRY_COMMITTED,
+ &last_updated_nav_entry_commit_time_);
+ }
break;
}
@@ -1323,27 +1339,133 @@ Browser::Type SessionService::BrowserTypeForWindowType(
}
}
-void SessionService::RecordSaveHistogramData() {
- if (!last_save_time_.is_null()) {
- base::TimeDelta delta = base::TimeTicks::Now() - last_save_time_;
- // We're interested in frequent updates, and group all periods longer than
- // 10 minutes together.
- UMA_HISTOGRAM_CUSTOM_TIMES("SessionRestore.SavePeriod",
+void SessionService::RecordSessionUpdateHistogramData(NotificationType type,
+ base::TimeTicks* last_updated_time) {
+ if (!last_updated_time->is_null()) {
+ base::TimeDelta delta = base::TimeTicks::Now() - *last_updated_time;
+ // We're interested in frequent updates periods longer than
+ // 10 minutes.
+ bool use_long_period = false;
+ if (delta >= save_delay_in_mins_) {
+ use_long_period = true;
+ }
+ switch (type.value) {
+ case NotificationType::SESSION_SERVICE_SAVED :
+ RecordUpdatedSaveTime(delta, use_long_period);
+ RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
+ break;
+ case NotificationType::TAB_CLOSED:
+ RecordUpdatedTabClosed(delta, use_long_period);
+ RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
+ break;
+ case NotificationType::NAV_LIST_PRUNED:
+ RecordUpdatedNavListPruned(delta, use_long_period);
+ RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
+ break;
+ case NotificationType::NAV_ENTRY_COMMITTED:
+ RecordUpdatedNavEntryCommit(delta, use_long_period);
+ RecordUpdatedSessionNavigationOrTab(delta, use_long_period);
+ break;
+ default:
+ NOTREACHED() << "Bad type sent to RecordSessionUpdateHistogramData";
+ break;
+ }
+ }
+ (*last_updated_time) = base::TimeTicks::Now();
+}
+
+void SessionService::RecordUpdatedTabClosed(base::TimeDelta delta,
+ bool use_long_period) {
+ std::string name("SessionRestore.TabClosedPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(name,
+ delta,
+ // 2500ms is the default save delay.
+ save_delay_in_millis_,
+ save_delay_in_mins_,
+ 50);
+ if (use_long_period) {
+ std::string long_name_("SessionRestore.TabClosedLongPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
delta,
- // 2500ms is the default save delay for coaelescing. This parameter
- // only impacts histogram creation, and not steady-state sampling.
- base::TimeDelta::FromMilliseconds(2500),
- base::TimeDelta::FromMinutes(10),
+ save_delay_in_mins_,
+ save_delay_in_hrs_,
50);
+ }
+}
- if (delta >= base::TimeDelta::FromMinutes(10)) {
- UMA_HISTOGRAM_CUSTOM_TIMES("SessionRestore.LongSavePeriod",
- delta,
- base::TimeDelta::FromMinutes(10),
- base::TimeDelta::FromHours(8),
- 50);
- }
+void SessionService::RecordUpdatedNavListPruned(base::TimeDelta delta,
+ bool use_long_period) {
+ std::string name("SessionRestore.NavigationListPrunedPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(name,
+ delta,
+ // 2500ms is the default save delay.
+ save_delay_in_millis_,
+ save_delay_in_mins_,
+ 50);
+ if (use_long_period) {
+ std::string long_name_("SessionRestore.NavigationListPrunedLongPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
+ delta,
+ save_delay_in_mins_,
+ save_delay_in_hrs_,
+ 50);
+ }
+}
+
+void SessionService::RecordUpdatedNavEntryCommit(base::TimeDelta delta,
+ bool use_long_period) {
+ std::string name("SessionRestore.NavEntryCommittedPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(name,
+ delta,
+ // 2500ms is the default save delay.
+ save_delay_in_millis_,
+ save_delay_in_mins_,
+ 50);
+ if (use_long_period) {
+ std::string long_name_("SessionRestore.NavEntryCommittedLongPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
+ delta,
+ save_delay_in_mins_,
+ save_delay_in_hrs_,
+ 50);
+ }
+}
+
+void SessionService::RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta,
+ bool use_long_period) {
+ std::string name("SessionRestore.NavOrTabUpdatePeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(name,
+ delta,
+ // 2500ms is the default save delay.
+ save_delay_in_millis_,
+ save_delay_in_mins_,
+ 50);
+ if (use_long_period) {
+ std::string long_name_("SessionRestore.NavOrTabUpdateLongPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
+ delta,
+ save_delay_in_mins_,
+ save_delay_in_hrs_,
+ 50);
}
+}
- last_save_time_ = base::TimeTicks::Now();
+void SessionService::RecordUpdatedSaveTime(base::TimeDelta delta,
+ bool use_long_period) {
+ std::string name("SessionRestore.SavePeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(name,
+ delta,
+ // 2500ms is the default save delay.
+ save_delay_in_millis_,
+ save_delay_in_mins_,
+ 50);
+ if (use_long_period) {
+ std::string long_name_("SessionRestore.SaveLongPeriod");
+ UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
+ delta,
+ save_delay_in_mins_,
+ save_delay_in_hrs_,
+ 50);
+ }
}
+
diff --git a/chrome/browser/sessions/session_service.h b/chrome/browser/sessions/session_service.h
index cfb3a8d..c8fa52f 100644
--- a/chrome/browser/sessions/session_service.h
+++ b/chrome/browser/sessions/session_service.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_SESSIONS_SESSION_SERVICE_H_
#include <map>
+#include <string>
#include "base/basictypes.h"
#include "base/callback.h"
@@ -175,9 +176,10 @@ class SessionService : public BaseSessionService,
virtual void Save();
private:
- typedef std::map<SessionID::id_type,std::pair<int,int> > IdToRange;
- typedef std::map<SessionID::id_type,SessionTab*> IdToSessionTab;
- typedef std::map<SessionID::id_type,SessionWindow*> IdToSessionWindow;
+ typedef std::map<SessionID::id_type, std::pair<int, int> > IdToRange;
+ typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab;
+ typedef std::map<SessionID::id_type, SessionWindow*> IdToSessionWindow;
+
virtual ~SessionService();
@@ -285,13 +287,13 @@ class SessionService : public BaseSessionService,
// . Sorts the tabs in windows with valid tabs based on the tabs
// visual order, and adds the valid windows to windows.
void SortTabsBasedOnVisualOrderAndPrune(
- std::map<int,SessionWindow*>* windows,
+ std::map<int, SessionWindow*>* windows,
std::vector<SessionWindow*>* valid_windows);
// Adds tabs to their parent window based on the tab's window_id. This
// ignores tabs with no navigations.
- void AddTabsToWindows(std::map<int,SessionTab*>* tabs,
- std::map<int,SessionWindow*>* windows);
+ void AddTabsToWindows(std::map<int, SessionTab*>* tabs,
+ std::map<int, SessionWindow*>* windows);
// Creates tabs and windows from the specified commands. The created tabs
// and windows are added to |tabs| and |windows| respectively. It is up to
@@ -300,8 +302,8 @@ class SessionService : public BaseSessionService,
// This does NOT add any created SessionTabs to SessionWindow.tabs, that is
// done by AddTabsToWindows.
bool CreateTabsAndWindows(const std::vector<SessionCommand*>& data,
- std::map<int,SessionTab*>* tabs,
- std::map<int,SessionWindow*>* windows);
+ std::map<int, SessionTab*>* tabs,
+ std::map<int, SessionWindow*>* windows);
// Adds commands to commands that will recreate the state of the specified
// NavigationController. This adds at most kMaxNavigationCountToPersist
@@ -381,8 +383,21 @@ class SessionService : public BaseSessionService,
BrowserList::size() > 1);
}
- // Call when a Save() occurs to record this in UMA stats.
- void RecordSaveHistogramData();
+ // Call when certain session relevant notifications
+ // (tab_closed, nav_list_pruned) occur. In addition, this is
+ // currently called when Save() is called to compare how often the
+ // session data is currently saved verses when we may want to save it.
+ // It records the data in UMA stats.
+ void RecordSessionUpdateHistogramData(NotificationType type,
+ base::TimeTicks* last_updated_time);
+
+ // Helper methods to record the histogram data
+ void RecordUpdatedTabClosed(base::TimeDelta delta, bool use_long_period);
+ void RecordUpdatedNavListPruned(base::TimeDelta delta, bool use_long_period);
+ void RecordUpdatedNavEntryCommit(base::TimeDelta delta, bool use_long_period);
+ void RecordUpdatedSaveTime(base::TimeDelta delta, bool use_long_period);
+ void RecordUpdatedSessionNavigationOrTab(base::TimeDelta delta,
+ bool use_long_period);
// Convert back/forward between the Browser and SessionService DB window
// types.
@@ -429,8 +444,16 @@ class SessionService : public BaseSessionService,
// current/previous session.
bool move_on_new_browser_;
- // Used for reporting frequency of Save() operations.
- base::TimeTicks last_save_time_;
+ // Used for reporting frequency of session alteriing operations.
+ base::TimeTicks last_updated_tab_closed_time_;
+ base::TimeTicks last_updated_nav_list_pruned_time_;
+ base::TimeTicks last_updated_nav_entry_commit_time_;
+ base::TimeTicks last_updated_save_time_;
+
+ // Constants used in calculating histogram data.
+ const base::TimeDelta save_delay_in_millis_;
+ const base::TimeDelta save_delay_in_mins_;
+ const base::TimeDelta save_delay_in_hrs_;
DISALLOW_COPY_AND_ASSIGN(SessionService);
};