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

Unified Diff: chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h

Issue 2753753005: [sync] WebContentsObserver based sessions notifications (Closed)
Patch Set: [sync] WebContentsObserver based sessions notifications Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h
diff --git a/chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h b/chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..11cea0d466d21c61dc082f838d715c1030c77a1a
--- /dev/null
+++ b/chrome/browser/sync/sessions/sync_sessions_router_tab_helper.h
@@ -0,0 +1,74 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_
+#define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_
+
+#include "components/sessions/core/session_id.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "content/public/browser/web_contents_user_data.h"
+
+namespace sync_sessions {
+
+class SyncSessionsWebContentsRouter;
+
+// TabHelper class that forwards tab-level WebContentsObserver events to a
+// global sessions router. The global router is responsible for forwarding these
Nicolas Zea 2017/03/16 19:57:43 it's not really global though right? It's per prof
Patrick Noland 2017/03/16 20:23:27 Right.
Patrick Noland 2017/03/17 00:20:09 Done.
+// events to sessions sync. This class also tracks the source tab id of its
+// corresponding tab, if available.
+// A TabHelper is a WebContentsObserver tied to the top level WebContents for a
+// browser tab.
+// https://chromium.googlesource.com/chromium/src/+/master/docs/tab_helpers.md
+
Nicolas Zea 2017/03/16 19:57:43 nit: remove newline?
Patrick Noland 2017/03/17 00:20:09 Done.
+class SyncSessionsRouterTabHelper
+ : public content::WebContentsUserData<SyncSessionsRouterTabHelper>,
+ public content::WebContentsObserver {
+ public:
+ ~SyncSessionsRouterTabHelper() override;
+
+ static void CreateForWebContents(
+ content::WebContents* web_contents,
+ SyncSessionsWebContentsRouter* session_router);
+
+ // Get the tab id of the tab responsible for creating the tab this helper
+ // corresponds to. Returns -1 if there is no such tab.
Nicolas Zea 2017/03/16 19:57:43 maybe define -1 as an enum? E.g. SyncSessionRouter
Patrick Noland 2017/03/17 00:20:09 Done, but in SyncedTabDelegate. This new definitio
+ SessionID::id_type source_tab_id() const { return source_tab_id_; }
+
+ private:
+ friend class content::WebContentsUserData<SyncSessionsRouterTabHelper>;
+ // router_ is a KeyedService and is guaranteed to outlive |this|.
Nicolas Zea 2017/03/16 19:57:43 newline above
Patrick Noland 2017/03/17 00:20:09 Done.
+ SyncSessionsWebContentsRouter* router_;
Nicolas Zea 2017/03/16 19:57:43 Member variables like this should be defined below
Patrick Noland 2017/03/17 00:20:09 Done.
+ SessionID::id_type source_tab_id_;
+
+ // Set the tab id of the tab reponsible for creating the tab this helper
+ // corresponds to.
+ void SetSourceTabID(const SessionID::id_type id);
Nicolas Zea 2017/03/16 19:57:43 if you're using source_tab_id() above, for consist
Patrick Noland 2017/03/17 00:20:09 Done.
+
+ // WebContentsObserver implementation.
Nicolas Zea 2017/03/16 19:57:43 Any reason these are private?
Patrick Noland 2017/03/16 20:23:27 Just caution about future use. There's not current
+ void DidFinishNavigation(
+ content::NavigationHandle* navigation_handle) override;
+ void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
+ void WebContentsDestroyed() override;
+ void DidFinishLoad(content::RenderFrameHost* render_frame_host,
+ const GURL& validated_url) override;
+ void DidOpenRequestedURL(content::WebContents* new_contents,
+ content::RenderFrameHost* source_render_frame_host,
+ const GURL& url,
+ const content::Referrer& referrer,
+ WindowOpenDisposition disposition,
+ ui::PageTransition transition,
+ bool started_from_context_menu,
+ bool renderer_initiated) override;
+
+ void NotifyRouter();
+
+ explicit SyncSessionsRouterTabHelper(content::WebContents* web_contents,
Nicolas Zea 2017/03/16 19:57:43 Constructors should be defined before other method
Patrick Noland 2017/03/17 00:20:09 Done.
+ SyncSessionsWebContentsRouter* router);
+
+ DISALLOW_COPY_AND_ASSIGN(SyncSessionsRouterTabHelper);
+};
+
+} // namespace sync_sessions
+
+#endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698