OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_ | |
6 #define CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_ | |
7 | |
8 #include "components/sessions/core/session_id.h" | |
9 #include "content/public/browser/web_contents_observer.h" | |
10 #include "content/public/browser/web_contents_user_data.h" | |
11 | |
12 namespace sync_sessions { | |
13 | |
14 class SyncSessionsWebContentsRouter; | |
15 | |
16 // TabHelper class that forwards tab-level WebContentsObserver events to a | |
17 // 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.
| |
18 // events to sessions sync. This class also tracks the source tab id of its | |
19 // corresponding tab, if available. | |
20 // A TabHelper is a WebContentsObserver tied to the top level WebContents for a | |
21 // browser tab. | |
22 // https://chromium.googlesource.com/chromium/src/+/master/docs/tab_helpers.md | |
23 | |
Nicolas Zea
2017/03/16 19:57:43
nit: remove newline?
Patrick Noland
2017/03/17 00:20:09
Done.
| |
24 class SyncSessionsRouterTabHelper | |
25 : public content::WebContentsUserData<SyncSessionsRouterTabHelper>, | |
26 public content::WebContentsObserver { | |
27 public: | |
28 ~SyncSessionsRouterTabHelper() override; | |
29 | |
30 static void CreateForWebContents( | |
31 content::WebContents* web_contents, | |
32 SyncSessionsWebContentsRouter* session_router); | |
33 | |
34 // Get the tab id of the tab responsible for creating the tab this helper | |
35 // 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
| |
36 SessionID::id_type source_tab_id() const { return source_tab_id_; } | |
37 | |
38 private: | |
39 friend class content::WebContentsUserData<SyncSessionsRouterTabHelper>; | |
40 // 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.
| |
41 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.
| |
42 SessionID::id_type source_tab_id_; | |
43 | |
44 // Set the tab id of the tab reponsible for creating the tab this helper | |
45 // corresponds to. | |
46 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.
| |
47 | |
48 // 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
| |
49 void DidFinishNavigation( | |
50 content::NavigationHandle* navigation_handle) override; | |
51 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; | |
52 void WebContentsDestroyed() override; | |
53 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | |
54 const GURL& validated_url) override; | |
55 void DidOpenRequestedURL(content::WebContents* new_contents, | |
56 content::RenderFrameHost* source_render_frame_host, | |
57 const GURL& url, | |
58 const content::Referrer& referrer, | |
59 WindowOpenDisposition disposition, | |
60 ui::PageTransition transition, | |
61 bool started_from_context_menu, | |
62 bool renderer_initiated) override; | |
63 | |
64 void NotifyRouter(); | |
65 | |
66 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.
| |
67 SyncSessionsWebContentsRouter* router); | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(SyncSessionsRouterTabHelper); | |
70 }; | |
71 | |
72 } // namespace sync_sessions | |
73 | |
74 #endif // CHROME_BROWSER_SYNC_SESSIONS_SYNC_SESSIONS_ROUTER_TAB_HELPER_H_ | |
OLD | NEW |