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

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

Issue 23863004: Delay delay launch of local discovery notification service. (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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" 11 #include "chrome/browser/local_discovery/privet_device_lister_impl.h"
11 #include "chrome/browser/notifications/notification.h" 12 #include "chrome/browser/notifications/notification.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/host_desktop.h" 16 #include "chrome/browser/ui/host_desktop.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" 18 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h"
18 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/navigation_controller.h" 20 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
21 #include "content/public/common/page_transition_types.h" 22 #include "content/public/common/page_transition_types.h"
22 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
23 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/message_center/notifier_settings.h" 27 #include "ui/message_center/notifier_settings.h"
27 28
28 namespace local_discovery { 29 namespace local_discovery {
29 30
30 namespace { 31 namespace {
31 const int kTenMinutesInSeconds = 600; 32 const int kTenMinutesInSeconds = 600;
32 const char kPrivetInfoKeyUptime[] = "uptime"; 33 const char kPrivetInfoKeyUptime[] = "uptime";
33 const char kPrivetNotificationIDPrefix[] = "privet_notification:"; 34 const char kPrivetNotificationIDPrefix[] = "privet_notification:";
34 const char kPrivetNotificationOriginUrl[] = "chrome://devices"; 35 const char kPrivetNotificationOriginUrl[] = "chrome://devices";
36 const int kStartDelaySeconds = 30;
35 } 37 }
36 38
37 PrivetNotificationsListener::PrivetNotificationsListener( 39 PrivetNotificationsListener::PrivetNotificationsListener(
38 scoped_ptr<PrivetHTTPAsynchronousFactory> privet_http_factory, 40 scoped_ptr<PrivetHTTPAsynchronousFactory> privet_http_factory,
39 Delegate* delegate) : delegate_(delegate) { 41 Delegate* delegate) : delegate_(delegate) {
40 privet_http_factory_.swap(privet_http_factory); 42 privet_http_factory_.swap(privet_http_factory);
41 } 43 }
42 44
43 PrivetNotificationsListener::~PrivetNotificationsListener() { 45 PrivetNotificationsListener::~PrivetNotificationsListener() {
44 } 46 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 145 }
144 146
145 PrivetNotificationsListener::DeviceContext::~DeviceContext() { 147 PrivetNotificationsListener::DeviceContext::~DeviceContext() {
146 } 148 }
147 149
148 PrivetNotificationService::PrivetNotificationService( 150 PrivetNotificationService::PrivetNotificationService(
149 content::BrowserContext* profile, 151 content::BrowserContext* profile,
150 NotificationUIManager* notification_manager) 152 NotificationUIManager* notification_manager)
151 : profile_(profile), 153 : profile_(profile),
152 notification_manager_(notification_manager) { 154 notification_manager_(notification_manager) {
153 base::MessageLoop::current()->PostTask( 155 base::MessageLoop::current()->PostDelayedTask(
154 FROM_HERE, 156 FROM_HERE,
155 base::Bind(&PrivetNotificationService::Start, AsWeakPtr())); 157 base::Bind(&PrivetNotificationService::Start, AsWeakPtr()),
158 base::TimeDelta::FromSeconds(kStartDelaySeconds +
159 base::RandInt(0, kStartDelaySeconds/4)));
156 } 160 }
157 161
158 PrivetNotificationService::~PrivetNotificationService() { 162 PrivetNotificationService::~PrivetNotificationService() {
159 ServiceDiscoveryHostClientFactory::ReleaseClient(); 163 ServiceDiscoveryHostClientFactory::ReleaseClient();
160 } 164 }
161 165
162 void PrivetNotificationService::DeviceChanged( 166 void PrivetNotificationService::DeviceChanged(
163 bool added, 167 bool added,
164 const std::string& name, 168 const std::string& name,
165 const DeviceDescription& description) { 169 const DeviceDescription& description) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 contents->GetController().LoadURL(url, 281 contents->GetController().LoadURL(url,
278 content::Referrer(), 282 content::Referrer(),
279 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 283 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
280 ""); 284 "");
281 285
282 browser->tab_strip_model()->AppendWebContents(contents.release(), true); 286 browser->tab_strip_model()->AppendWebContents(contents.release(), true);
283 } 287 }
284 288
285 289
286 } // namespace local_discovery 290 } // namespace local_discovery
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698