| OLD | NEW | 
|    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/command_line.h" |    8 #include "base/command_line.h" | 
|    9 #include "base/message_loop/message_loop.h" |    9 #include "base/message_loop/message_loop.h" | 
|   10 #include "base/metrics/histogram.h" |   10 #include "base/metrics/histogram.h" | 
|   11 #include "base/prefs/pref_service.h" |   11 #include "base/prefs/pref_service.h" | 
|   12 #include "base/rand_util.h" |   12 #include "base/rand_util.h" | 
|   13 #include "base/strings/utf_string_conversions.h" |   13 #include "base/strings/utf_string_conversions.h" | 
|   14 #include "chrome/browser/browser_process.h" |   14 #include "chrome/browser/browser_process.h" | 
|   15 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" |   15 #include "chrome/browser/local_discovery/privet_device_lister_impl.h" | 
|   16 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" |   16 #include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h" | 
|   17 #include "chrome/browser/local_discovery/privet_traffic_detector.h" |  | 
|   18 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |   17 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" | 
|   19 #include "chrome/browser/notifications/notification.h" |   18 #include "chrome/browser/notifications/notification.h" | 
|   20 #include "chrome/browser/notifications/notification_ui_manager.h" |   19 #include "chrome/browser/notifications/notification_ui_manager.h" | 
|   21 #include "chrome/browser/profiles/profile.h" |   20 #include "chrome/browser/profiles/profile.h" | 
|   22 #include "chrome/browser/signin/signin_manager_base.h" |   21 #include "chrome/browser/signin/signin_manager_base.h" | 
|   23 #include "chrome/browser/signin/signin_manager_factory.h" |   22 #include "chrome/browser/signin/signin_manager_factory.h" | 
|   24 #include "chrome/browser/ui/browser.h" |   23 #include "chrome/browser/ui/browser.h" | 
|   25 #include "chrome/browser/ui/browser_finder.h" |   24 #include "chrome/browser/ui/browser_finder.h" | 
|   26 #include "chrome/browser/ui/browser_window.h" |   25 #include "chrome/browser/ui/browser_window.h" | 
|   27 #include "chrome/browser/ui/host_desktop.h" |   26 #include "chrome/browser/ui/host_desktop.h" | 
|   28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |   27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 
|   29 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" |   28 #include "chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h" | 
|   30 #include "chrome/common/chrome_switches.h" |   29 #include "chrome/common/chrome_switches.h" | 
|   31 #include "chrome/common/pref_names.h" |   30 #include "chrome/common/pref_names.h" | 
|   32 #include "content/public/browser/browser_context.h" |   31 #include "content/public/browser/browser_context.h" | 
|   33 #include "content/public/browser/navigation_controller.h" |   32 #include "content/public/browser/navigation_controller.h" | 
|   34 #include "content/public/browser/web_contents.h" |   33 #include "content/public/browser/web_contents.h" | 
|   35 #include "content/public/common/page_transition_types.h" |   34 #include "content/public/common/page_transition_types.h" | 
|   36 #include "grit/generated_resources.h" |   35 #include "grit/generated_resources.h" | 
|   37 #include "grit/theme_resources.h" |   36 #include "grit/theme_resources.h" | 
|   38 #include "ui/base/l10n/l10n_util.h" |   37 #include "ui/base/l10n/l10n_util.h" | 
|   39 #include "ui/base/resource/resource_bundle.h" |   38 #include "ui/base/resource/resource_bundle.h" | 
|   40 #include "ui/message_center/message_center_util.h" |   39 #include "ui/message_center/message_center_util.h" | 
|   41 #include "ui/message_center/notifier_settings.h" |   40 #include "ui/message_center/notifier_settings.h" | 
|   42  |   41  | 
 |   42 #if defined(ENABLE_MDNS) | 
 |   43 #include "chrome/browser/local_discovery/privet_traffic_detector.h" | 
 |   44 #endif | 
 |   45  | 
|   43 namespace local_discovery { |   46 namespace local_discovery { | 
|   44  |   47  | 
|   45 namespace { |   48 namespace { | 
|   46  |   49  | 
|   47 const int kTenMinutesInSeconds = 600; |   50 const int kTenMinutesInSeconds = 600; | 
|   48 const char kPrivetInfoKeyUptime[] = "uptime"; |   51 const char kPrivetInfoKeyUptime[] = "uptime"; | 
|   49 const char kPrivetNotificationID[] = "privet_notification"; |   52 const char kPrivetNotificationID[] = "privet_notification"; | 
|   50 const char kPrivetNotificationOriginUrl[] = "chrome://devices"; |   53 const char kPrivetNotificationOriginUrl[] = "chrome://devices"; | 
|   51 const int kStartDelaySeconds = 5; |   54 const int kStartDelaySeconds = 5; | 
|   52  |   55  | 
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  297  |  300  | 
|  298   enable_privet_notification_member_.Init( |  301   enable_privet_notification_member_.Init( | 
|  299       prefs::kLocalDiscoveryNotificationsEnabled, |  302       prefs::kLocalDiscoveryNotificationsEnabled, | 
|  300       Profile::FromBrowserContext(profile_)->GetPrefs(), |  303       Profile::FromBrowserContext(profile_)->GetPrefs(), | 
|  301       base::Bind(&PrivetNotificationService::OnNotificationsEnabledChanged, |  304       base::Bind(&PrivetNotificationService::OnNotificationsEnabledChanged, | 
|  302                  base::Unretained(this))); |  305                  base::Unretained(this))); | 
|  303   OnNotificationsEnabledChanged(); |  306   OnNotificationsEnabledChanged(); | 
|  304 } |  307 } | 
|  305  |  308  | 
|  306 void PrivetNotificationService::OnNotificationsEnabledChanged() { |  309 void PrivetNotificationService::OnNotificationsEnabledChanged() { | 
 |  310 #if defined(ENABLE_MDNS) | 
|  307   if (IsForced()) { |  311   if (IsForced()) { | 
|  308     StartLister(); |  312     StartLister(); | 
|  309   } else if (*enable_privet_notification_member_) { |  313   } else if (*enable_privet_notification_member_) { | 
|  310     ReportPrivetUmaEvent(PRIVET_SERVICE_STARTED); |  314     ReportPrivetUmaEvent(PRIVET_SERVICE_STARTED); | 
|  311     traffic_detector_ = |  315     traffic_detector_ = | 
|  312         new PrivetTrafficDetector( |  316         new PrivetTrafficDetector( | 
|  313             net::ADDRESS_FAMILY_IPV4, |  317             net::ADDRESS_FAMILY_IPV4, | 
|  314             base::Bind(&PrivetNotificationService::StartLister, AsWeakPtr())); |  318             base::Bind(&PrivetNotificationService::StartLister, AsWeakPtr())); | 
|  315     traffic_detector_->Start(); |  319     traffic_detector_->Start(); | 
|  316   } else { |  320   } else { | 
|  317     traffic_detector_ = NULL; |  321     traffic_detector_ = NULL; | 
|  318     device_lister_.reset(); |  322     device_lister_.reset(); | 
|  319     service_discovery_client_ = NULL; |  323     service_discovery_client_ = NULL; | 
|  320     privet_notifications_listener_.reset(); |  324     privet_notifications_listener_.reset(); | 
|  321   } |  325   } | 
 |  326 #else | 
 |  327   if (IsForced() || *enable_privet_notification_member_) { | 
 |  328     StartLister(); | 
 |  329   } else { | 
 |  330     device_lister_.reset(); | 
 |  331     service_discovery_client_ = NULL; | 
 |  332     privet_notifications_listener_.reset(); | 
 |  333   } | 
 |  334 #endif | 
|  322 } |  335 } | 
|  323  |  336  | 
|  324 void PrivetNotificationService::StartLister() { |  337 void PrivetNotificationService::StartLister() { | 
|  325   ReportPrivetUmaEvent(PRIVET_LISTER_STARTED); |  338   ReportPrivetUmaEvent(PRIVET_LISTER_STARTED); | 
 |  339 #if defined(ENABLE_MDNS) | 
|  326   traffic_detector_ = NULL; |  340   traffic_detector_ = NULL; | 
|  327   DCHECK(!service_discovery_client_); |  341 #endif  // ENABLE_MDNS | 
|  328   service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); |  342   service_discovery_client_ = ServiceDiscoverySharedClient::GetInstance(); | 
|  329   device_lister_.reset(new PrivetDeviceListerImpl(service_discovery_client_, |  343   device_lister_.reset(new PrivetDeviceListerImpl(service_discovery_client_, | 
|  330                                                   this)); |  344                                                   this)); | 
|  331   device_lister_->Start(); |  345   device_lister_->Start(); | 
|  332   device_lister_->DiscoverNewDevices(false); |  346   device_lister_->DiscoverNewDevices(false); | 
|  333  |  347  | 
|  334   scoped_ptr<PrivetHTTPAsynchronousFactory> http_factory( |  348   scoped_ptr<PrivetHTTPAsynchronousFactory> http_factory( | 
|  335       PrivetHTTPAsynchronousFactory::CreateInstance( |  349       PrivetHTTPAsynchronousFactory::CreateInstance( | 
|  336           service_discovery_client_.get(), profile_->GetRequestContext())); |  350           service_discovery_client_.get(), profile_->GetRequestContext())); | 
|  337  |  351  | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  390  |  404  | 
|  391 void PrivetNotificationDelegate::DisableNotifications() { |  405 void PrivetNotificationDelegate::DisableNotifications() { | 
|  392   Profile* profile_obj = Profile::FromBrowserContext(profile_); |  406   Profile* profile_obj = Profile::FromBrowserContext(profile_); | 
|  393  |  407  | 
|  394   profile_obj->GetPrefs()->SetBoolean( |  408   profile_obj->GetPrefs()->SetBoolean( | 
|  395       prefs::kLocalDiscoveryNotificationsEnabled, |  409       prefs::kLocalDiscoveryNotificationsEnabled, | 
|  396       false); |  410       false); | 
|  397 } |  411 } | 
|  398  |  412  | 
|  399 }  // namespace local_discovery |  413 }  // namespace local_discovery | 
| OLD | NEW |