OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/tether/tether_service_factory.h" | 5 #include "chrome/browser/chromeos/tether/tether_service_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | |
7 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/strings/string_number_conversions.h" | |
10 #include "chrome/browser/chromeos/tether/fake_tether_service.h" | |
8 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" | 11 #include "chrome/browser/cryptauth/chrome_cryptauth_service_factory.h" |
9 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
14 #include "chromeos/chromeos_switches.h" | |
11 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
12 #include "chromeos/network/network_handler.h" | 16 #include "chromeos/network/network_handler.h" |
13 #include "chromeos/network/network_state_handler.h" | 17 #include "chromeos/network/network_state_handler.h" |
14 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
15 #include "components/pref_registry/pref_registry_syncable.h" | 19 #include "components/pref_registry/pref_registry_syncable.h" |
16 | 20 |
17 // static | 21 // static |
18 TetherServiceFactory* TetherServiceFactory::GetInstance() { | 22 TetherServiceFactory* TetherServiceFactory::GetInstance() { |
19 return base::Singleton<TetherServiceFactory>::get(); | 23 return base::Singleton<TetherServiceFactory>::get(); |
20 } | 24 } |
(...skipping 12 matching lines...) Expand all Loading... | |
33 BrowserContextDependencyManager::GetInstance()) { | 37 BrowserContextDependencyManager::GetInstance()) { |
34 DependsOn(ChromeCryptAuthServiceFactory::GetInstance()); | 38 DependsOn(ChromeCryptAuthServiceFactory::GetInstance()); |
35 } | 39 } |
36 | 40 |
37 TetherServiceFactory::~TetherServiceFactory() {} | 41 TetherServiceFactory::~TetherServiceFactory() {} |
38 | 42 |
39 KeyedService* TetherServiceFactory::BuildServiceInstanceFor( | 43 KeyedService* TetherServiceFactory::BuildServiceInstanceFor( |
40 content::BrowserContext* context) const { | 44 content::BrowserContext* context) const { |
41 DCHECK(chromeos::NetworkHandler::IsInitialized()); | 45 DCHECK(chromeos::NetworkHandler::IsInitialized()); |
42 | 46 |
47 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
48 if (command_line->HasSwitch(chromeos::switches::kTetherStub)) { | |
49 FakeTetherService* fake_tether_service = new FakeTetherService( | |
50 Profile::FromBrowserContext(context), | |
51 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(), | |
52 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | |
53 ChromeCryptAuthServiceFactory::GetForBrowserContext( | |
54 Profile::FromBrowserContext(context)), | |
55 chromeos::NetworkHandler::Get()->network_state_handler()); | |
56 | |
57 int num_tether_networks = 0; | |
58 base::StringToInt( | |
59 command_line->GetSwitchValueASCII(chromeos::switches::kTetherStub), | |
60 &num_tether_networks); | |
61 fake_tether_service->set_num_tether_networks(num_tether_networks); | |
stevenjb
2017/05/23 23:17:33
Please make sure that setting this to 0 has the ex
Ryan Hansberry
2017/05/23 23:24:48
Verified that this works correctly.
| |
62 | |
63 return fake_tether_service; | |
64 } | |
65 | |
43 return new TetherService( | 66 return new TetherService( |
44 Profile::FromBrowserContext(context), | 67 Profile::FromBrowserContext(context), |
45 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(), | 68 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(), |
46 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), | 69 chromeos::DBusThreadManager::Get()->GetSessionManagerClient(), |
47 ChromeCryptAuthServiceFactory::GetForBrowserContext( | 70 ChromeCryptAuthServiceFactory::GetForBrowserContext( |
48 Profile::FromBrowserContext(context)), | 71 Profile::FromBrowserContext(context)), |
49 chromeos::NetworkHandler::Get()->network_state_handler()); | 72 chromeos::NetworkHandler::Get()->network_state_handler()); |
50 } | 73 } |
51 | 74 |
52 void TetherServiceFactory::RegisterProfilePrefs( | 75 void TetherServiceFactory::RegisterProfilePrefs( |
53 user_prefs::PrefRegistrySyncable* registry) { | 76 user_prefs::PrefRegistrySyncable* registry) { |
54 TetherService::RegisterProfilePrefs(registry); | 77 TetherService::RegisterProfilePrefs(registry); |
55 } | 78 } |
OLD | NEW |