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

Side by Side Diff: chrome/browser/tether/tether_service.cc

Issue 2819713002: Create TetherService, a TetherAllowed pref, and use DependencyManager for RegisterProfilePrefs call… (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/tether/tether_service.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/memory/ptr_util.h"
10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/net/tether_notification_presenter.h"
13 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
16 #include "chrome/browser/tether/tether_service_factory.h"
17 #include "chrome/common/pref_names.h"
18 #include "chromeos/chromeos_switches.h"
19 #include "chromeos/components/tether/initializer.h"
20 #include "chromeos/network/network_connect.h"
21 #include "chromeos/network/network_state_handler.h"
22 #include "components/prefs/pref_service.h"
23 #include "components/proximity_auth/logging/logging.h"
24 #include "ui/message_center/message_center.h"
25
26 // static
27 TetherService* TetherService::Get(Profile* profile) {
28 return TetherServiceFactory::GetForBrowserContext(profile);
29 }
30
31 // static
32 void TetherService::RegisterProfilePrefs(
33 user_prefs::PrefRegistrySyncable* registry) {
34 registry->RegisterBooleanPref(prefs::kTetherAllowed, true);
35 chromeos::tether::Initializer::RegisterProfilePrefs(registry);
36 }
37
38 TetherService::TetherService(Profile* profile)
39 : profile_(profile), shut_down_(false) {
40 registrar_.Init(profile_->GetPrefs());
41 registrar_.Add(
42 prefs::kTetherAllowed,
43 base::Bind(&TetherService::OnPrefsChanged, base::Unretained(this)));
44 }
45
46 TetherService::~TetherService() {}
47
48 void TetherService::StartTether() {
49 // TODO (hansberry): Switch to using an IsEnabled() method.
50 if (!IsAllowed() || !base::CommandLine::ForCurrentProcess()->HasSwitch(
51 chromeos::switches::kEnableTether)) {
52 return;
53 }
54
55 auto notification_presenter =
56 base::MakeUnique<chromeos::tether::TetherNotificationPresenter>(
57 message_center::MessageCenter::Get(),
58 chromeos::NetworkConnect::Get());
59 chromeos::tether::Initializer::Init(
60 ChromeCryptAuthServiceFactory::GetForBrowserContext(profile_),
61 std::move(notification_presenter), profile_->GetPrefs(),
62 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
63 chromeos::NetworkHandler::Get()->network_state_handler(),
64 chromeos::NetworkConnect::Get());
65 }
66
67 bool TetherService::IsAllowed() const {
68 if (shut_down_)
69 return false;
70
71 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
72 return false;
73
74 return true;
75 }
76
77 void TetherService::Shutdown() {
78 if (shut_down_)
79 return;
80
81 shut_down_ = true;
82 registrar_.RemoveAll();
83 chromeos::tether::Initializer::Shutdown();
84 }
85
86 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
87 // TODO (hansberry): Switch to using an IsEnabled() method.
88 if (IsAllowed() && base::CommandLine::ForCurrentProcess()->HasSwitch(
89 chromeos::switches::kEnableTether)) {
90 StartTether();
91 return;
92 }
93
94 chromeos::tether::Initializer::Shutdown();
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698