blob: 8e56978062138265e3987eab19ae98875f0c20b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/sync/credential_cache_service_factory_win.h"
#include "base/command_line.h"
#include "base/memory/singleton.h"
#include "base/win/windows_version.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/signin/token_service_factory.h"
#include "chrome/browser/sync/credential_cache_service_win.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/common/chrome_paths_internal.h"
#include "chrome/common/chrome_switches.h"
namespace syncer {
// static
CredentialCacheServiceFactory* CredentialCacheServiceFactory::GetInstance() {
return Singleton<CredentialCacheServiceFactory>::get();
}
// static
syncer::CredentialCacheService* CredentialCacheServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<syncer::CredentialCacheService*>(
GetInstance()->GetServiceForProfile(profile, true));
}
CredentialCacheServiceFactory::CredentialCacheServiceFactory()
: ProfileKeyedServiceFactory("CredentialCacheService",
ProfileDependencyManager::GetInstance()) {
// TODO(rsimha): Uncomment this once it exists.
// DependsOn(PrefServiceFactory::GetInstance());
DependsOn(ProfileSyncServiceFactory::GetInstance());
DependsOn(SigninManagerFactory::GetInstance());
DependsOn(TokenServiceFactory::GetInstance());
}
CredentialCacheServiceFactory::~CredentialCacheServiceFactory() {
}
// static
bool CredentialCacheServiceFactory::IsDefaultProfile(Profile* profile) {
DCHECK(profile);
FilePath default_user_data_dir;
chrome::GetDefaultUserDataDirectory(&default_user_data_dir);
return profile->GetPath() ==
ProfileManager::GetDefaultProfileDir(default_user_data_dir);
}
// static
// TODO(rsimha): This is a test-only hook. Remove before shipping.
// See http://crbug.com/144280.
bool CredentialCacheServiceFactory::IsDefaultAlternateProfileForTest(
Profile* profile) {
DCHECK(profile);
const CommandLine* command_line = CommandLine::ForCurrentProcess();
FilePath alternate_user_data_dir;
chrome::GetAlternateUserDataDirectory(&alternate_user_data_dir);
return profile->GetPath() ==
ProfileManager::GetDefaultProfileDir(alternate_user_data_dir);
}
bool CredentialCacheServiceFactory::ServiceIsCreatedWithProfile() const {
return true;
}
ProfileKeyedService* CredentialCacheServiceFactory::BuildServiceInstanceFor(
Profile* profile) const {
// Only instantiate a CredentialCacheService object if we are running in the
// default profile on Windows 8, and if credential caching is enabled.
// TODO(rsimha): To allow for testing, start CredentialCacheService if we are
// either in the default profile or the default alternate profile, so that
// an instance of desktop chrome using the default metro directory can be
// used for testing. See http://crbug.com/144280.
const CommandLine* command_line = CommandLine::ForCurrentProcess();
if (base::win::GetVersion() >= base::win::VERSION_WIN8 &&
(IsDefaultProfile(profile) ||
IsDefaultAlternateProfileForTest(profile)) &&
command_line->HasSwitch(switches::kEnableSyncCredentialCaching)) {
return new syncer::CredentialCacheService(profile);
}
return NULL;
}
} // namespace syncer
|