OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/notification_service_sessions_router.h" | 5 #include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/extensions/tab_helper.h" | 9 #include "chrome/browser/extensions/tab_helper.h" |
10 #include "chrome/browser/favicon/favicon_changed_details.h" | 10 #include "chrome/browser/history/history_service.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/sync/glue/sync_start_util.h" | 13 #include "chrome/browser/sync/glue/sync_start_util.h" |
13 #include "chrome/browser/sync/glue/synced_tab_delegate.h" | 14 #include "chrome/browser/sync/glue/synced_tab_delegate.h" |
14 #include "chrome/browser/sync/sessions/sessions_util.h" | 15 #include "chrome/browser/sync/sessions/sessions_util.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
(...skipping 25 matching lines...) Expand all Loading... |
46 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, | 47 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_CHANGED, |
47 content::NotificationService::AllSources()); | 48 content::NotificationService::AllSources()); |
48 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 49 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
49 content::NotificationService::AllSources()); | 50 content::NotificationService::AllSources()); |
50 registrar_.Add(this, | 51 registrar_.Add(this, |
51 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 52 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
52 content::NotificationService::AllSources()); | 53 content::NotificationService::AllSources()); |
53 registrar_.Add(this, | 54 registrar_.Add(this, |
54 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 55 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
55 content::NotificationService::AllBrowserContextsAndSources()); | 56 content::NotificationService::AllBrowserContextsAndSources()); |
56 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_CHANGED, | 57 HistoryService* history_service = |
57 content::Source<Profile>(profile_)); | 58 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS); |
| 59 if (history_service) { |
| 60 favicon_changed_subscription_ = history_service->AddFaviconChangedCallback( |
| 61 base::Bind(&NotificationServiceSessionsRouter::OnFaviconChanged, |
| 62 base::Unretained(this))); |
| 63 } |
58 #if defined(ENABLE_MANAGED_USERS) | 64 #if defined(ENABLE_MANAGED_USERS) |
59 if (profile_->IsSupervised()) { | 65 if (profile_->IsSupervised()) { |
60 SupervisedUserService* supervised_user_service = | 66 SupervisedUserService* supervised_user_service = |
61 SupervisedUserServiceFactory::GetForProfile(profile_); | 67 SupervisedUserServiceFactory::GetForProfile(profile_); |
62 supervised_user_service->AddNavigationBlockedCallback( | 68 supervised_user_service->AddNavigationBlockedCallback( |
63 base::Bind(&NotificationServiceSessionsRouter::OnNavigationBlocked, | 69 base::Bind(&NotificationServiceSessionsRouter::OnNavigationBlocked, |
64 weak_ptr_factory_.GetWeakPtr())); | 70 weak_ptr_factory_.GetWeakPtr())); |
65 } | 71 } |
66 #endif | 72 #endif |
67 } | 73 } |
68 | 74 |
69 NotificationServiceSessionsRouter::~NotificationServiceSessionsRouter() {} | 75 NotificationServiceSessionsRouter::~NotificationServiceSessionsRouter() {} |
70 | 76 |
71 void NotificationServiceSessionsRouter::Observe( | 77 void NotificationServiceSessionsRouter::Observe( |
72 int type, | 78 int type, |
73 const content::NotificationSource& source, | 79 const content::NotificationSource& source, |
74 const content::NotificationDetails& details) { | 80 const content::NotificationDetails& details) { |
75 switch (type) { | 81 switch (type) { |
76 case chrome::NOTIFICATION_FAVICON_CHANGED: { | |
77 content::Details<FaviconChangedDetails> favicon_details(details); | |
78 if (handler_) | |
79 handler_->OnFaviconPageUrlsUpdated(favicon_details->urls); | |
80 return; | |
81 } | |
82 // Source<WebContents>. | 82 // Source<WebContents>. |
83 case chrome::NOTIFICATION_TAB_PARENTED: | 83 case chrome::NOTIFICATION_TAB_PARENTED: |
84 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: | 84 case content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME: |
85 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { | 85 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: { |
86 WebContents* web_contents = content::Source<WebContents>(source).ptr(); | 86 WebContents* web_contents = content::Source<WebContents>(source).ptr(); |
87 SyncedTabDelegate* tab = | 87 SyncedTabDelegate* tab = |
88 SyncedTabDelegate::ImplFromWebContents(web_contents); | 88 SyncedTabDelegate::ImplFromWebContents(web_contents); |
89 if (!tab || tab->profile() != profile_) | 89 if (!tab || tab->profile() != profile_) |
90 return; | 90 return; |
91 if (handler_) | 91 if (handler_) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 content::WebContents* web_contents) { | 142 content::WebContents* web_contents) { |
143 SyncedTabDelegate* tab = | 143 SyncedTabDelegate* tab = |
144 SyncedTabDelegate::ImplFromWebContents(web_contents); | 144 SyncedTabDelegate::ImplFromWebContents(web_contents); |
145 if (!tab || !handler_) | 145 if (!tab || !handler_) |
146 return; | 146 return; |
147 | 147 |
148 DCHECK(tab->profile() == profile_); | 148 DCHECK(tab->profile() == profile_); |
149 handler_->OnLocalTabModified(tab); | 149 handler_->OnLocalTabModified(tab); |
150 } | 150 } |
151 | 151 |
| 152 void NotificationServiceSessionsRouter::OnFaviconChanged( |
| 153 const std::set<GURL>& changed_favicons) { |
| 154 if (handler_) |
| 155 handler_->OnFaviconPageUrlsUpdated(changed_favicons); |
| 156 } |
| 157 |
152 void NotificationServiceSessionsRouter::StartRoutingTo( | 158 void NotificationServiceSessionsRouter::StartRoutingTo( |
153 LocalSessionEventHandler* handler) { | 159 LocalSessionEventHandler* handler) { |
154 DCHECK(!handler_); | 160 DCHECK(!handler_); |
155 handler_ = handler; | 161 handler_ = handler; |
156 } | 162 } |
157 | 163 |
158 void NotificationServiceSessionsRouter::Stop() { | 164 void NotificationServiceSessionsRouter::Stop() { |
159 weak_ptr_factory_.InvalidateWeakPtrs(); | 165 weak_ptr_factory_.InvalidateWeakPtrs(); |
160 handler_ = NULL; | 166 handler_ = NULL; |
161 } | 167 } |
162 | 168 |
163 } // namespace browser_sync | 169 } // namespace browser_sync |
OLD | NEW |