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

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: use directory-level dependency (instead of file-level) 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 <string>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
9 #include "components/keyed_service/content/browser_context_dependency_manager.h" 11 #include "components/keyed_service/content/browser_context_dependency_manager.h"
12 #include "components/wifi_sync/wifi_config_delegate.h"
10 #include "components/wifi_sync/wifi_credential_syncable_service.h" 13 #include "components/wifi_sync/wifi_credential_syncable_service.h"
14 #include "content/public/browser/browser_context.h"
11 15
12 #if defined(OS_CHROMEOS) 16 #if defined(OS_CHROMEOS)
17 #include "base/files/file_path.h"
13 #include "chromeos/login/login_state.h" 18 #include "chromeos/login/login_state.h"
14 #include "chromeos/network/network_handler.h" 19 #include "chromeos/network/network_handler.h"
15 #include "components/wifi_sync/wifi_config_delegate_chromeos.h" 20 #include "components/wifi_sync/wifi_config_delegate_chromeos.h"
16 #endif 21 #endif
17 22
18 namespace wifi_sync { 23 namespace wifi_sync {
19 24
20 namespace { 25 namespace {
21 26
22 scoped_ptr<WifiConfigDelegate> BuildConfigDelegate(
23 content::BrowserContext* context) {
24 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
25 const chromeos::LoginState* login_state = chromeos::LoginState::Get(); 28 std::string GetUserHash(content::BrowserContext* context,
26 DCHECK(login_state->IsUserLoggedIn()); 29 bool use_login_state) {
27 DCHECK(!login_state->primary_user_hash().empty()); 30 if (use_login_state) {
28 // TODO(quiche): Verify that |context| is the primary user's context. 31 const chromeos::LoginState* login_state = chromeos::LoginState::Get();
29 32 DCHECK(login_state->IsUserLoggedIn());
30 // Note: NetworkHandler is a singleton that is managed by 33 DCHECK(!login_state->primary_user_hash().empty());
31 // ChromeBrowserMainPartsChromeos, and destroyed after all 34 // TODO(quiche): Verify that |context| is the primary user's context.
32 // KeyedService instances are destroyed. 35 return login_state->primary_user_hash();
33 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get(); 36 } else {
34 return make_scoped_ptr(new WifiConfigDelegateChromeOs( 37 return context->GetPath().BaseName().value();
Charlie Reis 2015/02/05 01:07:57 It's not clear to me why this is a good hash, or w
mukesh agrawal 2015/02/06 02:40:55 Done (I think). I couldn't find a documentation o
35 login_state->primary_user_hash(), 38 }
36 network_handler->managed_network_configuration_handler())); 39 }
37 #else
38 NOTREACHED();
39 return nullptr;
40 #endif 40 #endif
41 }
42 41
43 } // namespace 42 } // namespace
44 43
45 // static 44 // static
46 WifiCredentialSyncableService* 45 WifiCredentialSyncableService*
47 WifiCredentialSyncableServiceFactory::GetForBrowserContext( 46 WifiCredentialSyncableServiceFactory::GetForBrowserContext(
48 content::BrowserContext* browser_context) { 47 content::BrowserContext* browser_context) {
49 return static_cast<WifiCredentialSyncableService*>( 48 return static_cast<WifiCredentialSyncableService*>(
50 GetInstance()->GetServiceForBrowserContext(browser_context, true)); 49 GetInstance()->GetServiceForBrowserContext(browser_context, true));
51 } 50 }
(...skipping 12 matching lines...) Expand all
64 BrowserContextDependencyManager::GetInstance()) { 63 BrowserContextDependencyManager::GetInstance()) {
65 } 64 }
66 65
67 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() { 66 WifiCredentialSyncableServiceFactory::~WifiCredentialSyncableServiceFactory() {
68 } 67 }
69 68
70 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor( 69 KeyedService* WifiCredentialSyncableServiceFactory::BuildServiceInstanceFor(
71 content::BrowserContext* context) const { 70 content::BrowserContext* context) const {
72 // TODO(quiche): Figure out if this behaves properly for multi-profile. 71 // TODO(quiche): Figure out if this behaves properly for multi-profile.
73 // crbug.com/430681. 72 // crbug.com/430681.
74 return new WifiCredentialSyncableService(BuildConfigDelegate(context)); 73 #if defined(OS_CHROMEOS)
74 return new WifiCredentialSyncableService(
75 BuildWifiConfigDelegateChromeOs(context));
76 #else
77 NOTREACHED();
78 return nullptr;
79 #endif
75 } 80 }
76 81
82 #if defined(OS_CHROMEOS)
83 scoped_ptr<WifiConfigDelegate>
84 WifiCredentialSyncableServiceFactory::BuildWifiConfigDelegateChromeOs(
85 content::BrowserContext* context) const {
86 // Note: NetworkHandler is a singleton that is managed by
87 // ChromeBrowserMainPartsChromeos, and destroyed after all
88 // KeyedService instances are destroyed.
89 chromeos::NetworkHandler* network_handler = chromeos::NetworkHandler::Get();
90 return make_scoped_ptr(new WifiConfigDelegateChromeOs(
91 GetUserHash(context, !ignore_login_state_for_test_),
92 network_handler->managed_network_configuration_handler()));
93 }
94 #endif
95
77 } // namespace wifi_sync 96 } // 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