diff options
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/alternate_nav_url_fetcher.cc | 6 | ||||
-rw-r--r-- | chrome/browser/alternate_nav_url_fetcher.h | 7 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 2 | ||||
-rw-r--r-- | chrome/browser/browser.cc | 8 | ||||
-rw-r--r-- | chrome/browser/history/history_notifications.h | 12 | ||||
-rw-r--r-- | chrome/browser/jsmessage_box_handler.cc | 6 | ||||
-rw-r--r-- | chrome/browser/metrics_service.cc | 37 | ||||
-rw-r--r-- | chrome/browser/metrics_service.h | 3 | ||||
-rw-r--r-- | chrome/browser/native_ui_contents.cc | 4 | ||||
-rw-r--r-- | chrome/browser/navigation_controller.cc | 92 | ||||
-rw-r--r-- | chrome/browser/navigation_controller.h | 48 | ||||
-rw-r--r-- | chrome/browser/navigation_controller_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/session_service.cc | 59 | ||||
-rw-r--r-- | chrome/browser/session_service.h | 6 | ||||
-rw-r--r-- | chrome/browser/ssl_blocking_page.cc | 3 | ||||
-rw-r--r-- | chrome/browser/template_url_model.cc | 18 | ||||
-rw-r--r-- | chrome/browser/template_url_model.h | 2 | ||||
-rw-r--r-- | chrome/browser/web_contents.cc | 7 |
18 files changed, 155 insertions, 167 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc index 04495fb..a791106 100644 --- a/chrome/browser/alternate_nav_url_fetcher.cc +++ b/chrome/browser/alternate_nav_url_fetcher.cc @@ -41,14 +41,14 @@ AlternateNavURLFetcher::AlternateNavURLFetcher( state_(NOT_STARTED), navigated_to_entry_(false) { NotificationService::current()->AddObserver(this, - NOTIFY_NAVIGATION_STATE_CHANGED, NotificationService::AllSources()); + NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); } AlternateNavURLFetcher::~AlternateNavURLFetcher() { if (state_ == NOT_STARTED) { // Never caught the NavigationController notification. NotificationService::current()->RemoveObserver(this, - NOTIFY_NAVIGATION_STATE_CHANGED, NotificationService::AllSources()); + NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); } // Otherwise, Observe() removed the observer already. } @@ -69,7 +69,7 @@ void AlternateNavURLFetcher::Observe(NotificationType type, controller_->SetAlternateNavURLFetcher(this); NotificationService::current()->RemoveObserver(this, - NOTIFY_NAVIGATION_STATE_CHANGED, NotificationService::AllSources()); + NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); DCHECK_EQ(NOT_STARTED, state_); state_ = IN_PROGRESS; diff --git a/chrome/browser/alternate_nav_url_fetcher.h b/chrome/browser/alternate_nav_url_fetcher.h index b62aeee..fbef709 100644 --- a/chrome/browser/alternate_nav_url_fetcher.h +++ b/chrome/browser/alternate_nav_url_fetcher.h @@ -26,8 +26,6 @@ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// TODO describe this file #ifndef CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H__ #define CHROME_BROWSER_ALTERNATE_NAV_URL_FETCHER_H__ @@ -39,6 +37,11 @@ class NavigationController; +// Attempts to get the HEAD of a host name and displays an info bar if the +// request was successful. This is used for single-word queries where we can't +// tell if the entry was a search or an intranet hostname. The autocomplete bar +// assumes it's a query and issues an AlternateNavURLFetcher to display a "did +// you mean" infobar suggesting a navigation. class AlternateNavURLFetcher : public NotificationObserver, public URLFetcher::Delegate { public: diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index ae675bf..a634a38 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -344,7 +344,7 @@ class TabAppendedNotificationObserver : public TabStripNotificationObserver { public: TabAppendedNotificationObserver(Browser* parent, AutomationProvider* automation, int32 routing_id) - : TabStripNotificationObserver(parent, NOTIFY_TAB_APPENDED, automation, + : TabStripNotificationObserver(parent, NOTIFY_TAB_PARENTED, automation, routing_id) { } diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index b325d05..127312b 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -1355,14 +1355,6 @@ void Browser::TabInsertedAt(TabContents* contents, int index, bool foreground) { contents->set_delegate(this); - - NavigationController* controller = contents->controller(); - DCHECK(controller); - NotificationService::current()-> - Notify(NOTIFY_TAB_APPENDED, - Source<NavigationController>(controller), - Details<Browser>(this)); - contents->controller()->SetWindowID(session_id()); SyncHistoryWithTabs(tabstrip_model_.GetIndexOfTabContents(contents)); diff --git a/chrome/browser/history/history_notifications.h b/chrome/browser/history/history_notifications.h index 5cc0180..d5146ea 100644 --- a/chrome/browser/history/history_notifications.h +++ b/chrome/browser/history/history_notifications.h @@ -70,11 +70,6 @@ struct URLsDeletedDetails : public HistoryDetails { std::set<GURL> urls; }; -// Details for NOTIFY_HOST_DELETED_FROM_HISTORY. -struct HostDeletedDetails : public HistoryDetails { - std::string host_name; -}; - // Details for NOTIFY_URLS_STARRED. struct URLsStarredDetails : public HistoryDetails { @@ -97,13 +92,6 @@ struct StarredEntryDetails : public HistoryDetails { StarredEntry entry; }; -// Details for NOTIFY_PAGE_PRESENTATION_INDEX_CHANGED. -struct PresentationIndexDetails : public HistoryDetails { - GURL url; - URLID url_id; - int index; -}; - // Details for NOTIFY_STARRED_FAVICON_CHANGED. struct FavIconChangeDetails : public HistoryDetails { std::set<GURL> urls; diff --git a/chrome/browser/jsmessage_box_handler.cc b/chrome/browser/jsmessage_box_handler.cc index 1576a21..bed59dc 100644 --- a/chrome/browser/jsmessage_box_handler.cc +++ b/chrome/browser/jsmessage_box_handler.cc @@ -60,7 +60,7 @@ void JavascriptMessageBoxHandler::RunJavascriptMessageBox( JavascriptMessageBoxHandler::~JavascriptMessageBoxHandler() { NotificationService::current()-> - RemoveObserver(this, NOTIFY_NAVIGATION_STATE_CHANGED, + RemoveObserver(this, NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); NotificationService::current()-> RemoveObserver(this, NOTIFY_TAB_CONTENTS_DESTROYED, @@ -176,7 +176,7 @@ void JavascriptMessageBoxHandler::Observe(NotificationType type, if (!web_contents_) return; - if (type == NOTIFY_NAVIGATION_STATE_CHANGED && + if (type == NOTIFY_NAV_STATE_CHANGED && Source<NavigationController>(source).ptr() == web_contents_->controller()) web_contents_gone = true; @@ -218,7 +218,7 @@ JavascriptMessageBoxHandler::JavascriptMessageBoxHandler( // Make sure we get navigation notifications so we know when our parent // contents will disappear or navigate to a different page. NotificationService::current()-> - AddObserver(this, NOTIFY_NAVIGATION_STATE_CHANGED, + AddObserver(this, NOTIFY_NAV_STATE_CHANGED, NotificationService::AllSources()); NotificationService::current()-> AddObserver(this, NOTIFY_TAB_CONTENTS_DESTROYED, diff --git a/chrome/browser/metrics_service.cc b/chrome/browser/metrics_service.cc index 85690a8..524b4eb 100644 --- a/chrome/browser/metrics_service.cc +++ b/chrome/browser/metrics_service.cc @@ -429,7 +429,7 @@ void MetricsService::Observe(NotificationType type, LogWindowChange(type, source, details); break; - case NOTIFY_TAB_APPENDED: + case NOTIFY_TAB_PARENTED: case NOTIFY_TAB_CLOSING: LogWindowChange(type, source, details); break; @@ -678,7 +678,7 @@ void MetricsService::ListenerRegistration(bool start_listening) { AddOrRemoveObserver(this, NOTIFY_BROWSER_OPENED, start_listening); AddOrRemoveObserver(this, NOTIFY_BROWSER_CLOSED, start_listening); AddOrRemoveObserver(this, NOTIFY_USER_ACTION, start_listening); - AddOrRemoveObserver(this, NOTIFY_TAB_APPENDED, start_listening); + AddOrRemoveObserver(this, NOTIFY_TAB_PARENTED, start_listening); AddOrRemoveObserver(this, NOTIFY_TAB_CLOSING, start_listening); AddOrRemoveObserver(this, NOTIFY_LOAD_START, start_listening); AddOrRemoveObserver(this, NOTIFY_LOAD_STOP, start_listening); @@ -1176,36 +1176,30 @@ void MetricsService::GetSettingsFromConfigNode(xmlNodePtr config_node) { void MetricsService::LogWindowChange(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - int window_id = -1; - int parent_id = -1; - uintptr_t window_key = source.map_key(); + int controller_id = -1; + uintptr_t window_or_tab = source.map_key(); MetricsLog::WindowEventType window_type; // Note: since we stop all logging when a single OTR session is active, it is // possible that we start getting notifications about a window that we don't // know about. - if (window_map_.find(window_key) == window_map_.end()) { - window_id = next_window_id_++; - window_map_[window_key] = window_id; + if (window_map_.find(window_or_tab) == window_map_.end()) { + controller_id = next_window_id_++; + window_map_[window_or_tab] = controller_id; } else { - window_id = window_map_[window_key]; - } - - DCHECK(window_id != -1); - - if (type == NOTIFY_TAB_APPENDED) { - parent_id = window_map_[details.map_key()]; + controller_id = window_map_[window_or_tab]; } + DCHECK(controller_id != -1); switch (type) { - case NOTIFY_TAB_APPENDED: + case NOTIFY_TAB_PARENTED: case NOTIFY_BROWSER_OPENED: window_type = MetricsLog::WINDOW_CREATE; break; case NOTIFY_TAB_CLOSING: case NOTIFY_BROWSER_CLOSED: - window_map_.erase(window_map_.find(window_key)); + window_map_.erase(window_map_.find(window_or_tab)); window_type = MetricsLog::WINDOW_DESTROY; break; @@ -1214,7 +1208,8 @@ void MetricsService::LogWindowChange(NotificationType type, break; } - current_log_->RecordWindowEvent(window_type, window_id, parent_id); + // TODO(brettw) we should have some kind of ID for the parent. + current_log_->RecordWindowEvent(window_type, controller_id, 0); } void MetricsService::LogLoadComplete(NotificationType type, @@ -1224,10 +1219,8 @@ void MetricsService::LogLoadComplete(NotificationType type, return; const Details<LoadNotificationDetails> load_details(details); - - int window_id = - window_map_[reinterpret_cast<uintptr_t>(load_details->controller())]; - current_log_->RecordLoadEvent(window_id, + int controller_id = window_map_[details.map_key()]; + current_log_->RecordLoadEvent(controller_id, load_details->url(), load_details->origin(), load_details->session_index(), diff --git a/chrome/browser/metrics_service.h b/chrome/browser/metrics_service.h index 4524bc6..6ffb5f1 100644 --- a/chrome/browser/metrics_service.h +++ b/chrome/browser/metrics_service.h @@ -333,6 +333,9 @@ class MetricsService : public NotificationObserver, std::vector<std::string> unsent_initial_logs_; std::vector<std::string> unsent_ongoing_logs_; + // Maps NavigationControllers (corresponding to tabs) or Browser + // (corresponding to Windows) to a unique integer that we will use to identify + // it. |next_window_id_| is used to track which IDs we have used so far. typedef std::map<uintptr_t, int> WindowMap; WindowMap window_map_; int next_window_id_; diff --git a/chrome/browser/native_ui_contents.cc b/chrome/browser/native_ui_contents.cc index e9965dd..67b1186 100644 --- a/chrome/browser/native_ui_contents.cc +++ b/chrome/browser/native_ui_contents.cc @@ -241,7 +241,7 @@ void NativeUIContents::SetPageState(PageState* page_state) { state_->GetByteRepresentation(&rep); ne->SetContentState(rep); // This is not a WebContents, so we use a NULL SiteInstance. - ctrl->SyncSessionWithEntryByPageID(type(), NULL, ne->GetPageID()); + ctrl->NotifyEntryChangedByPageID(type(), NULL, ne->GetPageID()); } } } @@ -294,7 +294,7 @@ bool NativeUIContents::Navigate(const NavigationEntry& entry, bool reload) { const int32 page_id = new_entry->GetPageID(); DidNavigateToEntry(new_entry); // This is not a WebContents, so we use a NULL SiteInstance. - controller()->SyncSessionWithEntryByPageID(type(), NULL, page_id); + controller()->NotifyEntryChangedByPageID(type(), NULL, page_id); return true; } diff --git a/chrome/browser/navigation_controller.cc b/chrome/browser/navigation_controller.cc index d56d6b1..ef6e767 100644 --- a/chrome/browser/navigation_controller.cc +++ b/chrome/browser/navigation_controller.cc @@ -178,16 +178,10 @@ NavigationController::~NavigationController() { DCHECK(tab_contents_map_.empty()); DCHECK(tab_contents_collector_map_.empty()); - SessionService* session_service = GetSessionService(); - if (session_service) - session_service->TabClosed(window_id_, session_id()); - profile_->UnregisterNavigationController(this); - - NotificationService::current()->Notify( - NOTIFY_TAB_CLOSED, - Source<NavigationController>(this), - NotificationService::NoDetails()); + NotificationService::current()->Notify(NOTIFY_TAB_CLOSED, + Source<NavigationController>(this), + NotificationService::NoDetails()); } TabContents* NavigationController::GetTabContents(TabContentsType t) { @@ -438,23 +432,18 @@ void NavigationController::DiscardPendingEntry() { } void NavigationController::InsertEntry(NavigationEntry* entry) { - DCHECK(entry); - NavigationControllerBase::InsertEntry(entry); - - int index = GetIndexOfEntry(entry); - DCHECK(entries_.size() > 0 && index != -1); - SyncSessionWithSelectedIndex(index); - + NotificationService::current()->Notify(NOTIFY_NAV_INDEX_CHANGED, + Source<NavigationController>(this), + NotificationService::NoDetails()); active_contents_->NotifyDidNavigate(NAVIGATION_NEW, 0); } void NavigationController::SetWindowID(const SessionID& id) { window_id_ = id; - - SessionService* session_service = GetSessionService(); - if (session_service) - session_service->SetTabWindow(window_id_, session_id()); + NotificationService::current()->Notify(NOTIFY_TAB_PARENTED, + Source<NavigationController>(this), + NotificationService::NoDetails()); } void NavigationController::NavigateToPendingEntry(bool reload) { @@ -513,18 +502,15 @@ void NavigationController::NotifyNavigationStateChanged() { active_contents_->NotifyNavigationStateChanged( TabContents::INVALIDATE_EVERYTHING); - NotificationService::current()->Notify( - NOTIFY_NAVIGATION_STATE_CHANGED, - Source<NavigationController>(this), - NotificationService::NoDetails()); + NotificationService::current()->Notify(NOTIFY_NAV_STATE_CHANGED, + Source<NavigationController>(this), + NotificationService::NoDetails()); } void NavigationController::NotifyPrunedEntries() { - SessionService* session_service = GetSessionService(); - if (!session_service) - return; - session_service->TabNavigationPathPruned(window_id(), session_id(), - GetEntryCount()); + NotificationService::current()->Notify(NOTIFY_NAV_LIST_PRUNED, + Source<NavigationController>(this), + NotificationService::NoDetails()); } void NavigationController::IndexOfActiveEntryChanged( @@ -536,8 +522,12 @@ void NavigationController::IndexOfActiveEntryChanged( nav_type = NAVIGATION_REPLACE; } active_contents_->NotifyDidNavigate(nav_type, relative_navigation_offset); - if (GetCurrentEntryIndex() != -1) - SyncSessionWithSelectedIndex(GetCurrentEntryIndex()); + if (GetCurrentEntryIndex() != -1) { + NotificationService::current()->Notify( + NOTIFY_NAV_INDEX_CHANGED, + Source<NavigationController>(this), + NotificationService::NoDetails()); + } } TabContents* NavigationController::GetTabContentsCreateIfNecessary( @@ -587,20 +577,13 @@ void NavigationController::RegisterTabContents(TabContents* some_contents) { some_contents->AsDOMUIHost()->AttachMessageHandlers(); } -SessionService* NavigationController::GetSessionService() const { - if (profile_->HasSessionService()) - return profile_->GetSessionService(); - - return NULL; -} - -void NavigationController::SyncSessionWithEntryByPageID( +void NavigationController::NotifyEntryChangedByPageID( TabContentsType type, SiteInstance *instance, - int32 page_id) const { + int32 page_id) { int index = GetEntryIndexWithPageID(type, instance, page_id); if (index != -1) - SyncSessionWithEntry(entries_[index], index); + NotifyEntryChanged(entries_[index], index); } // static @@ -631,25 +614,14 @@ void NavigationController::LoadIfNecessary() { NavigateToPendingEntry(false); } -void NavigationController::SyncSessionWithEntry(const NavigationEntry* entry, - int index) const { - SessionService* session_service = GetSessionService(); - if (!session_service) - return; - - DCHECK(entry && index != -1); - if (entry->GetDisplayURL().is_valid()) - session_service->UpdateTabNavigation(window_id(), session_id(), index, - *entry); -} - -void NavigationController::SyncSessionWithSelectedIndex(int index) const { - DCHECK(index != -1); - SessionService* session_service = GetSessionService(); - if (!session_service) - return; - - session_service->SetSelectedNavigationIndex(window_id(), session_id(), index); +void NavigationController::NotifyEntryChanged(const NavigationEntry* entry, + int index) { + EntryChangedDetails det; + det.changed_entry = entry; + det.index = index; + NotificationService::current()->Notify(NOTIFY_NAV_ENTRY_CHANGED, + Source<NavigationController>(this), + Details<EntryChangedDetails>(&det)); } int NavigationController::GetMaxPageID() const { diff --git a/chrome/browser/navigation_controller.h b/chrome/browser/navigation_controller.h index 9b452c0..070abfa 100644 --- a/chrome/browser/navigation_controller.h +++ b/chrome/browser/navigation_controller.h @@ -27,8 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef CHROME_BROWSER_NAVIGATION_CONTROLLER_H__ -#define CHROME_BROWSER_NAVIGATION_CONTROLLER_H__ +#ifndef CHROME_BROWSER_NAVIGATION_CONTROLLER_H_ +#define CHROME_BROWSER_NAVIGATION_CONTROLLER_H_ #include <hash_map> @@ -41,7 +41,6 @@ class GURL; class Profile; -class SessionService; class TabContents; class WebContents; class TabContentsCollector; @@ -64,6 +63,15 @@ class PrintViewManager; //////////////////////////////////////////////////////////////////////////////// class NavigationController : public NavigationControllerBase { public: + // Provides the details for a NOTIFY_NAV_ENTRY_CHANGED notification. + struct EntryChangedDetails { + // The changed navigation entry after it has been updated. + const NavigationEntry* changed_entry; + + // Indicates the current index in the back/forward list of the entry. + int index; + }; + NavigationController(TabContents* initial_contents, Profile* profile); // Creates a NavigationController from the specified history. Processing // for this is asynchronous and handled via the RestoreHelper (in @@ -152,14 +160,12 @@ class NavigationController : public NavigationControllerBase { SSLManager* ssl_manager() { return &ssl_manager_; } - // Synchronizes the session saving database with the entry that has the same - // page id, instance, and contents type as the specified entry. - // NOTE: This is invoked by WebContents. Any custom TabContents that - // modify a NavigationEntries state/url/transition must explicitly invoke - // this. - void SyncSessionWithEntryByPageID(TabContentsType type, - SiteInstance* instance, - int32 page_id) const; + // Broadcasts the NOTIFY_NAV_ENTRY_CHANGED notification for the + // navigation corresponding to the given page. This will keep things in sync + // like saved session. + void NotifyEntryChangedByPageID(TabContentsType type, + SiteInstance* instance, + int32 page_id); void SetActive(bool is_active); @@ -216,19 +222,8 @@ class NavigationController : public NavigationControllerBase { // and deleted by this navigation controller void RegisterTabContents(TabContents* some_contents); - // Returns the session service for the profile. This returns NULL if the - // profile doesn't have a session service. - SessionService* GetSessionService() const; - - // If the active entry is valid, the session database is updated accordingly. - void SyncSessionWithActiveEntry() const; - - // Updates the session database with the specified entry and index. - void SyncSessionWithEntry(const NavigationEntry* entry, int index) const; - - // Lets the history database know index is the selected index for this - // navigation controller. - void SyncSessionWithSelectedIndex(int index) const; + // Broadcasts a notification that the given entry changed. + void NotifyEntryChanged(const NavigationEntry* entry, int index); // Sets the max restored page ID this NavigationController has seen, if it // was restored from a previous session. @@ -298,6 +293,7 @@ class NavigationController : public NavigationControllerBase { // when testing. static bool check_for_repost_; - DISALLOW_EVIL_CONSTRUCTORS(NavigationController); + DISALLOW_COPY_AND_ASSIGN(NavigationController); }; -#endif // CHROME_BROWSER_NAVIGATION_CONTROLLER_H__ + +#endif // CHROME_BROWSER_NAVIGATION_CONTROLLER_H_ diff --git a/chrome/browser/navigation_controller_unittest.cc b/chrome/browser/navigation_controller_unittest.cc index 5986b31..51eeb67 100644 --- a/chrome/browser/navigation_controller_unittest.cc +++ b/chrome/browser/navigation_controller_unittest.cc @@ -74,7 +74,7 @@ class TestContents : public TabContents { DCHECK(pending_entry_.get()); pending_entry_->SetPageID(page_id); DidNavigateToEntry(pending_entry_.get()); - controller()->SyncSessionWithEntryByPageID(type(), NULL, page_id); + controller()->NotifyEntryChangedByPageID(type(), NULL, page_id); pending_entry_.release(); } diff --git a/chrome/browser/session_service.cc b/chrome/browser/session_service.cc index e90f8b8..6e78f9c 100644 --- a/chrome/browser/session_service.cc +++ b/chrome/browser/session_service.cc @@ -149,6 +149,18 @@ SessionService::~SessionService() { // deleted. Otherwise the backend is deleted after all pending requests on // the file thread complete, which is done before the process exits. backend_ = NULL; + + // Unregister our notifications. + NotificationService::current()->RemoveObserver( + this, NOTIFY_TAB_PARENTED, NotificationService::AllSources()); + NotificationService::current()->RemoveObserver( + this, NOTIFY_TAB_CLOSED, NotificationService::AllSources()); + NotificationService::current()->RemoveObserver( + this, NOTIFY_NAV_LIST_PRUNED, NotificationService::AllSources()); + NotificationService::current()->RemoveObserver( + this, NOTIFY_NAV_ENTRY_CHANGED, NotificationService::AllSources()); + NotificationService::current()->RemoveObserver( + this, NOTIFY_NAV_INDEX_CHANGED, NotificationService::AllSources()); } void SessionService::ResetFromCurrentBrowsers() { @@ -303,7 +315,8 @@ void SessionService::UpdateTabNavigation(const SessionID& window_id, const SessionID& tab_id, int index, const NavigationEntry& entry) { - if (!ShouldTrackChangesToWindow(window_id)) + if (!entry.GetDisplayURL().is_valid() || + !ShouldTrackChangesToWindow(window_id)) return; if (tab_to_available_range_.find(tab_id.id()) != @@ -394,6 +407,18 @@ void SessionService::CopyLastSessionToSavedSession() { } void SessionService::Init(const std::wstring& path) { + // Register for the notifications we're interested in. + NotificationService::current()->AddObserver( + this, NOTIFY_TAB_PARENTED, NotificationService::AllSources()); + NotificationService::current()->AddObserver( + this, NOTIFY_TAB_CLOSED, NotificationService::AllSources()); + NotificationService::current()->AddObserver( + this, NOTIFY_NAV_LIST_PRUNED, NotificationService::AllSources()); + NotificationService::current()->AddObserver( + this, NOTIFY_NAV_ENTRY_CHANGED, NotificationService::AllSources()); + NotificationService::current()->AddObserver( + this, NOTIFY_NAV_INDEX_CHANGED, NotificationService::AllSources()); + DCHECK(!path.empty()); commands_since_reset_ = 0; backend_ = new SessionBackend(path); @@ -403,6 +428,38 @@ void SessionService::Init(const std::wstring& path) { // If backend_thread, backend will init itself as appropriate. } +void SessionService::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + // All of our messages have the NavigationController as the source. + NavigationController* controller = Source<NavigationController>(source).ptr(); + switch (type) { + case NOTIFY_TAB_PARENTED: + SetTabWindow(controller->window_id(), controller->session_id()); + break; + case NOTIFY_TAB_CLOSED: + TabClosed(controller->window_id(), controller->session_id()); + break; + case NOTIFY_NAV_LIST_PRUNED: + TabNavigationPathPruned(controller->window_id(), controller->session_id(), + controller->GetEntryCount()); + break; + case NOTIFY_NAV_ENTRY_CHANGED: { + Details<NavigationController::EntryChangedDetails> changed(details); + UpdateTabNavigation(controller->window_id(), controller->session_id(), + changed->index, *changed->changed_entry); + break; + } + case NOTIFY_NAV_INDEX_CHANGED: + SetSelectedNavigationIndex(controller->window_id(), + controller->session_id(), + controller->GetCurrentEntryIndex()); + break; + default: + NOTREACHED(); + } +} + SessionService::Handle SessionService::GetSessionImpl( CancelableRequestConsumerBase* consumer, SavedSessionCallback* callback, diff --git a/chrome/browser/session_service.h b/chrome/browser/session_service.h index 3877701..df932f9 100644 --- a/chrome/browser/session_service.h +++ b/chrome/browser/session_service.h @@ -38,6 +38,7 @@ #include "base/time.h" #include "chrome/browser/browser_type.h" #include "chrome/browser/cancelable_request.h" +#include "chrome/common/notification_service.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/stl_util-inl.h" #include "googleurl/src/gurl.h" @@ -220,6 +221,7 @@ struct SessionWindow { // of the browser. class SessionService : public CancelableRequestProvider, + public NotificationObserver, public base::RefCountedThreadSafe<SessionService> { friend class SessionServiceTestHelper; public: @@ -373,6 +375,10 @@ class SessionService : public CancelableRequestProvider, // Various initialization; called from the constructor. void Init(const std::wstring& path); + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + // Get*Session call into this to schedule the request. The request // does NOT directly invoke the callback, rather the callback invokes // OnGotSessionCommands from which we map the SessionCommands to browser diff --git a/chrome/browser/ssl_blocking_page.cc b/chrome/browser/ssl_blocking_page.cc index 220328a..bd99b30 100644 --- a/chrome/browser/ssl_blocking_page.cc +++ b/chrome/browser/ssl_blocking_page.cc @@ -179,9 +179,6 @@ void SSLBlockingPage::Show() { // The controller will own the entry. int page_id = nav_entry->GetPageID(); tab_->controller()->DidNavigateToEntry(nav_entry); - tab_->controller()->SyncSessionWithEntryByPageID(TAB_CONTENTS_WEB, - NULL, - page_id); tab->ShowInterstitialPage(html_text, NULL); } diff --git a/chrome/browser/template_url_model.cc b/chrome/browser/template_url_model.cc index ee1e885..aa3884b 100644 --- a/chrome/browser/template_url_model.cc +++ b/chrome/browser/template_url_model.cc @@ -90,8 +90,6 @@ TemplateURLModel::TemplateURLModel(Profile* profile) next_id_(1) { DCHECK(profile_); NotificationService* ns = NotificationService::current(); - ns->AddObserver(this, NOTIFY_HOST_DELETED_FROM_HISTORY, - Source<Profile>(profile_->GetOriginalProfile())); // TODO(sky): bug 1166191. The keywords should be moved into the history // db, which will mean we no longer need this notification and the history // backend can handle automatically adding the search terms as the user @@ -123,8 +121,6 @@ TemplateURLModel::~TemplateURLModel() { if (profile_) { NotificationService* ns = NotificationService::current(); - ns->RemoveObserver(this, NOTIFY_HOST_DELETED_FROM_HISTORY, - Source<Profile>(profile_->GetOriginalProfile())); ns->RemoveObserver(this, NOTIFY_HISTORY_URL_VISITED, Source<Profile>(profile_->GetOriginalProfile())); ns->RemoveObserver(this, NOTIFY_GOOGLE_URL_UPDATED, @@ -661,19 +657,7 @@ void TemplateURLModel::OnWebDataServiceRequestDone( void TemplateURLModel::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (type == NOTIFY_HOST_DELETED_FROM_HISTORY) { - Details<std::string> utf8_host(details); - std::wstring host(UTF8ToWide(*(utf8_host.ptr()))); - if (!loaded()) { - // We're not loaded, so that we can't delete the url. Save the host to - // hosts_to_delete_ and schedule a load. When done loading we'll delete - // the keyword. - hosts_to_delete_.push_back(host); - Load(); - } else { - DeleteGeneratedKeywordsMatchingHost(host); - } - } else if (type == NOTIFY_HISTORY_URL_VISITED) { + if (type == NOTIFY_HISTORY_URL_VISITED) { Details<history::URLVisitedDetails> visit_details(details); if (!loaded()) diff --git a/chrome/browser/template_url_model.h b/chrome/browser/template_url_model.h index 9ea3137..d09d3c8 100644 --- a/chrome/browser/template_url_model.h +++ b/chrome/browser/template_url_model.h @@ -205,8 +205,6 @@ class TemplateURLModel : public WebDataServiceConsumer, // NotificationObserver method. TemplateURLModel listens for three // notification types: - // . NOTIFY_HOST_DELETED_FROM_HISTORY: deletes generated keywords for the - // host that was deleted. // . NOTIFY_HISTORY_URL_VISITED: adds keyword search terms if the visit // corresponds to a keyword. // . NOTIFY_GOOGLE_URL_UPDATED: updates mapping for any keywords containing diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc index d9d7f1c..1774c1d 100644 --- a/chrome/browser/web_contents.cc +++ b/chrome/browser/web_contents.cc @@ -1513,9 +1513,8 @@ void WebContents::DidNavigateAnyFramePostCommit( RenderViewHost* render_view_host, const ViewHostMsg_FrameNavigate_Params& params) { // Have the controller save the current session. - controller()->SyncSessionWithEntryByPageID(type(), - site_instance(), - params.page_id); + controller()->NotifyEntryChangedByPageID(type(), site_instance(), + params.page_id); BroadcastProvisionalLoadCommit(render_view_host, params); } @@ -1680,7 +1679,7 @@ void WebContents::UpdateState(RenderViewHost* rvh, // Notify everybody of the changes (only when the current page changed). if (changed_flags && entry == controller()->GetActiveEntry()) NotifyNavigationStateChanged(changed_flags); - controller()->SyncSessionWithEntryByPageID(type(), site_instance(), page_id); + controller()->NotifyEntryChangedByPageID(type(), site_instance(), page_id); } void WebContents::UpdateTitle(RenderViewHost* rvh, |