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

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: Do not explicitly call on TetherService::Shutdown() from UserSessionManager. 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"
Lei Zhang 2017/04/19 19:13:17 Not using g_browser_process - not needed?
Ryan Hansberry 2017/04/20 17:22:32 Done.
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"
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.
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::kInstantTetheringAllowed, 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::kInstantTetheringAllowed,
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.
Lei Zhang 2017/04/19 19:13:17 no space after TODO.
Ryan Hansberry 2017/04/20 17:22:32 Done.
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 return profile_->GetPrefs()->GetBoolean(prefs::kInstantTetheringAllowed);
72 }
73
74 void TetherService::Shutdown() {
75 if (shut_down_)
76 return;
77
78 shut_down_ = true;
79 registrar_.RemoveAll();
80 chromeos::tether::Initializer::Shutdown();
81 }
82
83 void TetherService::OnPrefsChanged() {
84 // TODO (hansberry): Switch to using an IsEnabled() method.
85 if (IsAllowed() && base::CommandLine::ForCurrentProcess()->HasSwitch(
86 chromeos::switches::kEnableTether)) {
87 StartTether();
88 return;
89 }
90
91 chromeos::tether::Initializer::Shutdown();
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698