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

Side by Side Diff: chrome/browser/local_discovery/privet_notifications.cc

Issue 23903024: Enable device discovery notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/local_discovery/privet_notifications.h" 5 #include "chrome/browser/local_discovery/privet_notifications.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" 12 #include "chrome/browser/local_discovery/privet_device_lister_impl.h"
12 #include "chrome/browser/notifications/notification.h" 13 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_finder.h" 16 #include "chrome/browser/ui/browser_finder.h"
16 #include "chrome/browser/ui/host_desktop.h" 17 #include "chrome/browser/ui/host_desktop.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" 19 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h"
19 #include "content/public/browser/browser_context.h" 20 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/navigation_controller.h" 21 #include "content/public/browser/navigation_controller.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 142 }
142 } 143 }
143 144
144 PrivetNotificationsListener::DeviceContext::DeviceContext() { 145 PrivetNotificationsListener::DeviceContext::DeviceContext() {
145 } 146 }
146 147
147 PrivetNotificationsListener::DeviceContext::~DeviceContext() { 148 PrivetNotificationsListener::DeviceContext::~DeviceContext() {
148 } 149 }
149 150
150 PrivetNotificationService::PrivetNotificationService( 151 PrivetNotificationService::PrivetNotificationService(
151 content::BrowserContext* profile, 152 content::BrowserContext* profile)
152 NotificationUIManager* notification_manager) 153 : profile_(profile) {
153 : profile_(profile),
154 notification_manager_(notification_manager) {
155 base::MessageLoop::current()->PostDelayedTask( 154 base::MessageLoop::current()->PostDelayedTask(
156 FROM_HERE, 155 FROM_HERE,
157 base::Bind(&PrivetNotificationService::Start, AsWeakPtr()), 156 base::Bind(&PrivetNotificationService::Start, AsWeakPtr()),
158 base::TimeDelta::FromSeconds(kStartDelaySeconds + 157 base::TimeDelta::FromSeconds(kStartDelaySeconds +
159 base::RandInt(0, kStartDelaySeconds/4))); 158 base::RandInt(0, kStartDelaySeconds/4)));
160 } 159 }
161 160
162 PrivetNotificationService::~PrivetNotificationService() { 161 PrivetNotificationService::~PrivetNotificationService() {
163 ServiceDiscoveryHostClientFactory::ReleaseClient(); 162 ServiceDiscoveryHostClientFactory::ReleaseClient();
164 } 163 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 WebKit::WebTextDirectionDefault, 202 WebKit::WebTextDirectionDefault,
204 message_center::NotifierId( 203 message_center::NotifierId(
205 message_center::NotifierId::SYSTEM_COMPONENT), 204 message_center::NotifierId::SYSTEM_COMPONENT),
206 l10n_util::GetStringUTF16( 205 l10n_util::GetStringUTF16(
207 IDS_LOCAL_DISOCVERY_NOTIFICATION_DISPLAY_SOURCE_PRINTER), 206 IDS_LOCAL_DISOCVERY_NOTIFICATION_DISPLAY_SOURCE_PRINTER),
208 UTF8ToUTF16(kPrivetNotificationIDPrefix + 207 UTF8ToUTF16(kPrivetNotificationIDPrefix +
209 device_name), 208 device_name),
210 rich_notification_data, 209 rich_notification_data,
211 new PrivetNotificationDelegate(device_name, profile_)); 210 new PrivetNotificationDelegate(device_name, profile_));
212 211
213 notification_manager_->Add(notification, profile_object); 212 g_browser_process->notification_ui_manager()->Add(notification,
213 profile_object);
214 } 214 }
215 } 215 }
216 216
217 void PrivetNotificationService::PrivetRemoveNotification( 217 void PrivetNotificationService::PrivetRemoveNotification(
218 const std::string& device_name) { 218 const std::string& device_name) {
219 notification_manager_->CancelById(kPrivetNotificationIDPrefix + device_name); 219 g_browser_process->notification_ui_manager()->CancelById(
220 kPrivetNotificationIDPrefix + device_name);
220 } 221 }
221 222
222 void PrivetNotificationService::Start() { 223 void PrivetNotificationService::Start() {
223 service_discovery_client_ = ServiceDiscoveryHostClientFactory::GetClient(); 224 service_discovery_client_ = ServiceDiscoveryHostClientFactory::GetClient();
224 device_lister_.reset(new PrivetDeviceListerImpl(service_discovery_client_, 225 device_lister_.reset(new PrivetDeviceListerImpl(service_discovery_client_,
225 this)); 226 this));
226 device_lister_->Start(); 227 device_lister_->Start();
227 228
228 scoped_ptr<PrivetHTTPAsynchronousFactory> http_factory( 229 scoped_ptr<PrivetHTTPAsynchronousFactory> http_factory(
229 new PrivetHTTPAsynchronousFactoryImpl(service_discovery_client_.get(), 230 new PrivetHTTPAsynchronousFactoryImpl(service_discovery_client_.get(),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 contents->GetController().LoadURL(url, 282 contents->GetController().LoadURL(url,
282 content::Referrer(), 283 content::Referrer(),
283 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 284 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
284 ""); 285 "");
285 286
286 browser->tab_strip_model()->AppendWebContents(contents.release(), true); 287 browser->tab_strip_model()->AppendWebContents(contents.release(), true);
287 } 288 }
288 289
289 290
290 } // namespace local_discovery 291 } // namespace local_discovery
OLDNEW
« no previous file with comments | « chrome/browser/local_discovery/privet_notifications.h ('k') | chrome/browser/local_discovery/privet_notifications_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698