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

Side by Side Diff: components/wifi_sync/wifi_credential_syncable_service_factory.cc

Issue 876833002: wifi_sync: allow WifiCredentialSyncableServiceFactory to ignore LoginState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.3-syncable-service
Patch Set: Created 5 years, 10 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
« no previous file with comments | « components/wifi_sync/wifi_credential_syncable_service_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/wifi_sync/wifi_credential_syncable_service_factory.h" 5 #include "components/wifi_sync/wifi_credential_syncable_service_factory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "components/keyed_service/content/browser_context_dependency_manager.h" 9 #include "components/keyed_service/content/browser_context_dependency_manager.h"
10 #include "components/wifi_sync/wifi_config_delegate.h"
10 #include "components/wifi_sync/wifi_credential_syncable_service.h" 11 #include "components/wifi_sync/wifi_credential_syncable_service.h"
12 #include "content/public/browser/browser_context.h"
11 13
12 #if defined(OS_CHROMEOS) 14 #if defined(OS_CHROMEOS)
15 #include "base/files/file_path.h"
13 #include "chromeos/login/login_state.h" 16 #include "chromeos/login/login_state.h"
14 #include "chromeos/network/network_handler.h" 17 #include "chromeos/network/network_handler.h"
15 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" 18 #include "components/wifi_sync/wifi_config_delegate_chromeos.h"
16 #endif 19 #endif
17 20
18 namespace wifi_sync { 21 namespace wifi_sync {
19 22
20 namespace {
21
22 scoped_ptr<WifiConfigDelegate> BuildConfigDelegate(
23 content::BrowserContext* context) {
24 #if defined(OS_CHROMEOS)
25 const chromeos::LoginState* login_state = chromeos::LoginState::Get();
26 DCHECK(login_state->IsUserLoggedIn());
27 DCHECK(!login_state->primary_user_hash().empty());
28 // TODO(quiche): Verify that |context| is the primary user's context.
29
30 // Note: NetworkHandler is a singleton that is managed by
31 // ChromeBrowserMainPartsChromeos, and destroyed after all
32 // KeyedService instances are destroyed.
33 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get();
34 return make_scoped_ptr(new WifiConfigDelegateChromeOs(
35 login_state->primary_user_hash(),
36 network_handler->managed_network_configuration_handler()));
37 #else
38 NOTREACHED();
39 return nullptr;
40 #endif
41 }
42
43 } // namespace
44
45 // static 23 // static
46 WifiCredentialSyncableService* 24 WifiCredentialSyncableService*
47 WifiCredentialSyncableServiceFactory::GetForBrowserContext( 25 WifiCredentialSyncableServiceFactory::GetForBrowserContext(
48 content::BrowserContext* browser_context) { 26 content::BrowserContext* browser_context) {
49 return static_cast<WifiCredentialSyncableService*>( 27 return static_cast<WifiCredentialSyncableService*>(
50 GetInstance()->GetServiceForBrowserContext(browser_context, true)); 28 GetInstance()->GetServiceForBrowserContext(browser_context, true));
51 } 29 }
52 30
53 // static 31 // static
54 WifiCredentialSyncableServiceFactory* 32 WifiCredentialSyncableServiceFactory*
55 WifiCredentialSyncableServiceFactory::GetInstance() { 33 WifiCredentialSyncableServiceFactory::GetInstance() {
56 return Singleton<WifiCredentialSyncableServiceFactory>::get(); 34 return Singleton<WifiCredentialSyncableServiceFactory>::get();
57 } 35 }
58 36
37 #if defined(OS_CHROMEOS)
38 void WifiCredentialSyncableServiceFactory::IgnoreLoginStateForTest() {
stevenjb 2015/01/28 01:04:58 Rather than having a method to set this, would it
mukesh agrawal 2015/01/28 20:07:23 Unfortunately, we don't have control over construc
39 use_login_state_chrome_os_ = false;
40 }
41 #endif
42
59 // Private methods. 43 // Private methods.
60 44
61 WifiCredentialSyncableServiceFactory::WifiCredentialSyncableServiceFactory() 45 WifiCredentialSyncableServiceFactory::WifiCredentialSyncableServiceFactory()
62 : BrowserContextKeyedServiceFactory( 46 : BrowserContextKeyedServiceFactory(
63 "WifiCredentialSyncableService", 47 "WifiCredentialSyncableService",
64 BrowserContextDependencyManager::GetInstance()) { 48 BrowserContextDependencyManager::GetInstance()),
49 use_login_state_chrome_os_(true) {
65 } 50 }
66 51
67 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { 52 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() {
68 } 53 }
69 54
70 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( 55 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor(
71 content::BrowserContext* context) const { 56 content::BrowserContext* context) const {
72 // TODO(quiche): Figure out if this behaves properly for multi-profile. 57 // TODO(quiche): Figure out if this behaves properly for multi-profile.
73 // crbug.com/430681. 58 // crbug.com/430681.
74 return new WifiCredentialSyncableService(BuildConfigDelegate(context)); 59 return new WifiCredentialSyncableService(BuildWifiConfigDelegate(context));
75 } 60 }
76 61
62 scoped_ptr<WifiConfigDelegate>
63 WifiCredentialSyncableServiceFactory::BuildWifiConfigDelegate(
64 content::BrowserContext* context) const {
stevenjb 2015/01/28 01:04:58 This extra layer just adds confusion IMHO, I would
mukesh agrawal 2015/01/28 20:07:23 Done.
65 #if defined(OS_CHROMEOS)
66 return BuildWifiConfigDelegateChromeOs(context);
67 #else
68 NOTREACHED();
69 return nullptr;
70 #endif
71 }
72
73 #if defined(OS_CHROMEOS)
74 scoped_ptr<WifiConfigDelegate>
75 WifiCredentialSyncableServiceFactory::BuildWifiConfigDelegateChromeOs(
76 content::BrowserContext* context) const {
77 // Note: NetworkHandler is a singleton that is managed by
78 // ChromeBrowserMainPartsChromeos, and destroyed after all
79 // KeyedService instances are destroyed.
80 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get();
81 return make_scoped_ptr(new WifiConfigDelegateChromeOs(
82 GetShillProfile(context),
83 network_handler->managed_network_configuration_handler()));
84 }
85
86 std::string WifiCredentialSyncableServiceFactory::GetShillProfile(
stevenjb 2015/01/28 01:04:57 This doesn't return a Profile as the name suggests
mukesh agrawal 2015/01/28 20:07:24 How's this? (I consider GetShillProfileId, but tha
87 content::BrowserContext* context) const {
88 if (use_login_state_chrome_os_) {
89 const chromeos::LoginState* login_state = chromeos::LoginState::Get();
90 DCHECK(login_state->IsUserLoggedIn());
91 DCHECK(!login_state->primary_user_hash().empty());
92 // TODO(quiche): Verify that |context| is the primary user's context.
93 return login_state->primary_user_hash();
94 } else {
95 return context->GetPath().BaseName().value();
96 }
97 }
98 #endif
99
77 } // namespace wifi_sync 100 } // namespace wifi_sync
OLDNEW
« no previous file with comments | « components/wifi_sync/wifi_credential_syncable_service_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698