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..9737751c58f7a3d73c986eb98f45a19cb451586b |
--- /dev/null |
+++ b/chrome/browser/tether/tether_service.cc |
@@ -0,0 +1,92 @@ |
+// 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" |
Lei Zhang
2017/04/19 19:13:17
Not using g_browser_process - not needed?
Ryan Hansberry
2017/04/20 17:22:32
Done.
|
+#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" |
Lei Zhang
2017/04/19 19:13:17
Is this used for anything? If not, remove and remo
Ryan Hansberry
2017/04/20 17:22:32
Removed this and the DEPS entry.
|
+#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::kInstantTetheringAllowed, true); |
+ chromeos::tether::Initializer::RegisterProfilePrefs(registry); |
+} |
+ |
+TetherService::TetherService(Profile* profile) |
+ : profile_(profile), shut_down_(false) { |
+ registrar_.Init(profile_->GetPrefs()); |
+ registrar_.Add( |
+ prefs::kInstantTetheringAllowed, |
+ base::Bind(&TetherService::OnPrefsChanged, base::Unretained(this))); |
+} |
+ |
+TetherService::~TetherService() {} |
+ |
+void TetherService::StartTether() { |
+ // TODO (hansberry): Switch to using an IsEnabled() method. |
Lei Zhang
2017/04/19 19:13:17
no space after TODO.
Ryan Hansberry
2017/04/20 17:22:32
Done.
|
+ 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; |
+ |
+ return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed); |
+} |
+ |
+void TetherService::Shutdown() { |
+ if (shut_down_) |
+ return; |
+ |
+ shut_down_ = true; |
+ registrar_.RemoveAll(); |
+ chromeos::tether::Initializer::Shutdown(); |
+} |
+ |
+void TetherService::OnPrefsChanged() { |
+ // TODO (hansberry): Switch to using an IsEnabled() method. |
+ if (IsAllowed() && base::CommandLine::ForCurrentProcess()->HasSwitch( |
+ chromeos::switches::kEnableTether)) { |
+ StartTether(); |
+ return; |
+ } |
+ |
+ chromeos::tether::Initializer::Shutdown(); |
+} |