Index: chrome/browser/tether/tether_service.cc |
diff --git a/chrome/browser/tether/tether_service.cc b/chrome/browser/tether/tether_service.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8ee2790121f4cbba5cd659ef5afd53615ce75be2 |
--- /dev/null |
+++ b/chrome/browser/tether/tether_service.cc |
@@ -0,0 +1,95 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/tether/tether_service.h" |
+ |
+#include "base/bind.h" |
+#include "base/command_line.h" |
+#include "base/memory/ptr_util.h" |
+#include "build/build_config.h" |
+#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/chromeos/net/tether_notification_presenter.h" |
+#include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
+#include "chrome/browser/tether/tether_service_factory.h" |
+#include "chrome/common/pref_names.h" |
+#include "chromeos/chromeos_switches.h" |
+#include "chromeos/components/tether/initializer.h" |
+#include "chromeos/network/network_connect.h" |
+#include "chromeos/network/network_state_handler.h" |
+#include "components/prefs/pref_service.h" |
+#include "components/proximity_auth/logging/logging.h" |
+#include "ui/message_center/message_center.h" |
+ |
+// static |
+TetherService* TetherService::Get(Profile* profile) { |
+ return TetherServiceFactory::GetForBrowserContext(profile); |
+} |
+ |
+// static |
+void TetherService::RegisterProfilePrefs( |
+ user_prefs::PrefRegistrySyncable* registry) { |
+ registry->RegisterBooleanPref(prefs::kTetherAllowed, true); |
+ chromeos::tether::Initializer::RegisterProfilePrefs(registry); |
+} |
+ |
+TetherService::TetherService(Profile* profile) |
+ : profile_(profile), shut_down_(false) { |
+ registrar_.Init(profile_->GetPrefs()); |
+ registrar_.Add( |
+ prefs::kTetherAllowed, |
+ base::Bind(&TetherService::OnPrefsChanged, base::Unretained(this))); |
+} |
+ |
+TetherService::~TetherService() {} |
+ |
+void TetherService::StartTether() { |
+ // TODO (hansberry): Switch to using an IsEnabled() method. |
+ if (!IsAllowed() || !base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ chromeos::switches::kEnableTether)) { |
+ return; |
+ } |
+ |
+ auto notification_presenter = |
+ base::MakeUnique<chromeos::tether::TetherNotificationPresenter>( |
+ message_center::MessageCenter::Get(), |
+ chromeos::NetworkConnect::Get()); |
+ chromeos::tether::Initializer::Init( |
+ ChromeCryptAuthServiceFactory::GetForBrowserContext(profile_), |
+ std::move(notification_presenter), profile_->GetPrefs(), |
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
+ chromeos::NetworkHandler::Get()->network_state_handler(), |
+ chromeos::NetworkConnect::Get()); |
+} |
+ |
+bool TetherService::IsAllowed() const { |
+ if (shut_down_) |
+ return false; |
+ |
+ if (!profile_->GetPrefs()->GetBoolean(prefs::kTetherAllowed)) |
Kyle Horimoto
2017/04/14 01:08:26
Just return profile_->GetPrefs()->GetBoolean(prefs
Ryan Hansberry
2017/04/14 02:34:10
Done.
Kyle Horimoto
2017/04/14 18:39:20
I think you forgot to upload your changes :)
Ryan Hansberry
2017/04/18 17:59:05
Accidentally uploaded them to the CL depending on
|
+ return false; |
+ |
+ return true; |
+} |
+ |
+void TetherService::Shutdown() { |
+ if (shut_down_) |
+ return; |
+ |
+ shut_down_ = true; |
+ registrar_.RemoveAll(); |
+ chromeos::tether::Initializer::Shutdown(); |
+} |
+ |
+void TetherService::OnPrefsChanged() { |
Kyle Horimoto
2017/04/14 00:15:43
What about if tethering is disabled, then reenable
Ryan Hansberry
2017/04/14 02:34:10
Not sure I follow -- are you mixing up the Service
Kyle Horimoto
2017/04/14 18:39:20
Yep, I was mixing it up. Thanks for the explanatio
|
+ // TODO (hansberry): Switch to using an IsEnabled() method. |
+ if (IsAllowed() && base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ chromeos::switches::kEnableTether)) { |
+ StartTether(); |
+ return; |
+ } |
+ |
+ chromeos::tether::Initializer::Shutdown(); |
+} |