OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/sync/sessions/browser_list_router_helper.h" | 5 #include "chrome/browser/sync/sessions/browser_list_router_helper.h" |
6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" |
7 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
8 #include "chrome/browser/ui/browser_list.h" | 9 #include "chrome/browser/ui/browser_list.h" |
9 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" | 10 #include "chrome/browser/ui/sync/tab_contents_synced_tab_delegate.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 | 12 |
12 namespace sync_sessions { | 13 namespace sync_sessions { |
13 | 14 |
14 BrowserListRouterHelper::BrowserListRouterHelper( | 15 BrowserListRouterHelper::BrowserListRouterHelper( |
15 SyncSessionsWebContentsRouter* router) | 16 SyncSessionsWebContentsRouter* router, |
16 : router_(router) { | 17 Profile* profile) |
| 18 : router_(router), profile_(profile) { |
17 BrowserList* browser_list = BrowserList::GetInstance(); | 19 BrowserList* browser_list = BrowserList::GetInstance(); |
18 for (Browser* browser : *browser_list) | 20 for (Browser* browser : *browser_list) { |
19 browser->tab_strip_model()->AddObserver(this); | 21 if (browser->profile() == profile_) { |
| 22 browser->tab_strip_model()->AddObserver(this); |
| 23 } |
| 24 } |
20 browser_list->AddObserver(this); | 25 browser_list->AddObserver(this); |
21 } | 26 } |
22 | 27 |
23 BrowserListRouterHelper::~BrowserListRouterHelper() { | 28 BrowserListRouterHelper::~BrowserListRouterHelper() { |
24 BrowserList* browser_list = BrowserList::GetInstance(); | 29 BrowserList* browser_list = BrowserList::GetInstance(); |
25 for (Browser* browser : *browser_list) | 30 for (Browser* browser : *browser_list) { |
26 browser->tab_strip_model()->RemoveObserver(this); | 31 if (browser->profile() == profile_) { |
| 32 browser->tab_strip_model()->RemoveObserver(this); |
| 33 } |
| 34 } |
| 35 |
27 BrowserList::GetInstance()->RemoveObserver(this); | 36 BrowserList::GetInstance()->RemoveObserver(this); |
28 } | 37 } |
29 | 38 |
30 void BrowserListRouterHelper::OnBrowserAdded(Browser* browser) { | 39 void BrowserListRouterHelper::OnBrowserAdded(Browser* browser) { |
31 browser->tab_strip_model()->AddObserver(this); | 40 if (browser->profile() == profile_) { |
| 41 browser->tab_strip_model()->AddObserver(this); |
| 42 } |
32 } | 43 } |
33 | 44 |
34 void BrowserListRouterHelper::OnBrowserRemoved(Browser* browser) { | 45 void BrowserListRouterHelper::OnBrowserRemoved(Browser* browser) { |
35 browser->tab_strip_model()->RemoveObserver(this); | 46 if (browser->profile() == profile_) { |
| 47 browser->tab_strip_model()->RemoveObserver(this); |
| 48 } |
36 } | 49 } |
37 | 50 |
38 void BrowserListRouterHelper::TabInsertedAt(TabStripModel* model, | 51 void BrowserListRouterHelper::TabInsertedAt(TabStripModel* model, |
39 content::WebContents* web_contents, | 52 content::WebContents* web_contents, |
40 int index, | 53 int index, |
41 bool foreground) { | 54 bool foreground) { |
42 router_->NotifyTabModified(web_contents, false); | 55 if (web_contents && Profile::FromBrowserContext( |
| 56 web_contents->GetBrowserContext()) == profile_) |
| 57 router_->NotifyTabModified(web_contents, false); |
43 } | 58 } |
44 | 59 |
45 } // namespace sync_sessions | 60 } // namespace sync_sessions |
OLD | NEW |