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

Side by Side Diff: chrome/browser/sync/profile_sync_service_factory.cc

Issue 2494873003: [Sync] Allow sync start without sign-in if the local sync backend is on. (Closed)
Patch Set: Merge pref changes from https://codereview.chromium.org/2528163002/. Created 4 years 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/sync/profile_sync_service_factory.h" 5 #include "chrome/browser/sync/profile_sync_service_factory.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 void UpdateNetworkTime(const base::Time& network_time, 68 void UpdateNetworkTime(const base::Time& network_time,
69 const base::TimeDelta& resolution, 69 const base::TimeDelta& resolution,
70 const base::TimeDelta& latency) { 70 const base::TimeDelta& latency) {
71 content::BrowserThread::PostTask( 71 content::BrowserThread::PostTask(
72 content::BrowserThread::UI, FROM_HERE, 72 content::BrowserThread::UI, FROM_HERE,
73 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution, 73 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution,
74 latency, base::TimeTicks::Now())); 74 latency, base::TimeTicks::Now()));
75 } 75 }
76 76
77 #if defined(OS_WIN)
78 static const base::FilePath::CharType kLoopbackServerBackendFilename[] =
79 FILE_PATH_LITERAL("profile.pb");
80 #endif
81
77 } // anonymous namespace 82 } // anonymous namespace
78 83
79 // static 84 // static
80 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { 85 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() {
81 return base::Singleton<ProfileSyncServiceFactory>::get(); 86 return base::Singleton<ProfileSyncServiceFactory>::get();
82 } 87 }
83 88
84 // static 89 // static
85 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( 90 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile(
86 Profile* profile) { 91 Profile* profile) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 142
138 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() { 143 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() {
139 } 144 }
140 145
141 KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( 146 KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor(
142 content::BrowserContext* context) const { 147 content::BrowserContext* context) const {
143 ProfileSyncService::InitParams init_params; 148 ProfileSyncService::InitParams init_params;
144 149
145 Profile* profile = Profile::FromBrowserContext(context); 150 Profile* profile = Profile::FromBrowserContext(context);
146 151
147 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); 152 init_params.network_time_update_callback = base::Bind(&UpdateNetworkTime);
153 init_params.base_directory = profile->GetPath();
154 init_params.url_request_context = profile->GetRequestContext();
155 init_params.debug_identifier = profile->GetDebugName();
156 init_params.channel = chrome::GetChannel();
157 init_params.blocking_pool = content::BrowserThread::GetBlockingPool();
148 158
149 // Always create the GCMProfileService instance such that we can listen to 159 bool local_sync_backend_enabled = false;
150 // the profile notifications and purge the GCM store when the profile is
151 // being signed out.
152 gcm::GCMProfileServiceFactory::GetForProfile(profile);
153 160
154 // TODO(atwilson): Change AboutSigninInternalsFactory to load on startup 161 // Since the local sync backend is currently only supported on Windows don't
155 // once http://crbug.com/171406 has been fixed. 162 // even check the pref on other os-es.
156 AboutSigninInternalsFactory::GetForProfile(profile); 163 #if defined(OS_WIN)
164 syncer::SyncPrefs prefs(profile->GetPrefs());
165 local_sync_backend_enabled = prefs.IsLocalSyncEnabled();
166 if (local_sync_backend_enabled) {
167 // This code as it is now will assume the same profile order is present on
168 // all machines, which is not a given. It is to be defined if only the
169 // Default profile should get this treatment or all profile as is the case
170 // now. The solution for now will be to assume profiles are created in the
171 // same order on all machines and in the future decide if only the Default
172 // one should be considered roamed.
Nicolas Zea 2016/12/15 00:37:28 nit: should this refer to an open bug?
pastarmovj 2016/12/16 17:04:48 Done.
173 init_params.local_sync_backend_folder = prefs.GetLocalSyncBackendDir();
174 init_params.local_sync_backend_folder =
175 init_params.local_sync_backend_folder.Append(
176 init_params.base_directory.BaseName());
177 init_params.local_sync_backend_folder =
178 init_params.local_sync_backend_folder.Append(
179 kLoopbackServerBackendFilename);
157 180
158 init_params.signin_wrapper = 181 init_params.start_behavior = ProfileSyncService::AUTO_START;
159 base::MakeUnique<SupervisedUserSigninManagerWrapper>(profile, signin); 182 }
160 init_params.oauth2_token_service = 183 #endif // defined(OS_WIN)
161 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
162 init_params.gaia_cookie_manager_service =
163 GaiaCookieManagerServiceFactory::GetForProfile(profile);
164 184
165 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync 185 if (!local_sync_backend_enabled) {
166 // is set up and *not* a browser restart for a manual-start platform (where 186 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
167 // sync has already been set up, and should be able to start without user 187
168 // intervention). We can get rid of the browser_default eventually, but 188 // Always create the GCMProfileService instance such that we can listen to
169 // need to take care that ProfileSyncService doesn't get tripped up between 189 // the profile notifications and purge the GCM store when the profile is
170 // those two cases. Bug 88109. 190 // being signed out.
171 init_params.start_behavior = browser_defaults::kSyncAutoStarts 191 gcm::GCMProfileServiceFactory::GetForProfile(profile);
172 ? ProfileSyncService::AUTO_START 192
173 : ProfileSyncService::MANUAL_START; 193 // TODO(atwilson): Change AboutSigninInternalsFactory to load on startup
194 // once http://crbug.com/171406 has been fixed.
195 AboutSigninInternalsFactory::GetForProfile(profile);
196
197 init_params.signin_wrapper =
198 base::MakeUnique<SupervisedUserSigninManagerWrapper>(profile, signin);
199 init_params.oauth2_token_service =
200 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
201 init_params.gaia_cookie_manager_service =
202 GaiaCookieManagerServiceFactory::GetForProfile(profile);
203
204 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync
205 // is set up and *not* a browser restart for a manual-start platform (where
206 // sync has already been set up, and should be able to start without user
207 // intervention). We can get rid of the browser_default eventually, but
208 // need to take care that ProfileSyncService doesn't get tripped up between
209 // those two cases. Bug 88109.
210 init_params.start_behavior = browser_defaults::kSyncAutoStarts
211 ? ProfileSyncService::AUTO_START
212 : ProfileSyncService::MANUAL_START;
213 }
174 214
175 if (!client_factory_) { 215 if (!client_factory_) {
176 init_params.sync_client = 216 init_params.sync_client =
177 base::MakeUnique<browser_sync::ChromeSyncClient>(profile); 217 base::MakeUnique<browser_sync::ChromeSyncClient>(profile);
178 } else { 218 } else {
179 init_params.sync_client = client_factory_->Run(profile); 219 init_params.sync_client = client_factory_->Run(profile);
180 } 220 }
181 221
182 init_params.network_time_update_callback = base::Bind(&UpdateNetworkTime);
183 init_params.base_directory = profile->GetPath();
184 init_params.url_request_context = profile->GetRequestContext();
185 init_params.debug_identifier = profile->GetDebugName();
186 init_params.channel = chrome::GetChannel();
187 init_params.blocking_pool = content::BrowserThread::GetBlockingPool();
188
189 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params)); 222 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params));
190 223
191 // Will also initialize the sync client. 224 // Will also initialize the sync client.
192 pss->Initialize(); 225 pss->Initialize();
193 return pss.release(); 226 return pss.release();
194 } 227 }
195 228
196 // static 229 // static
197 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { 230 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) {
198 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr; 231 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr;
199 } 232 }
200 233
201 // static 234 // static
202 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( 235 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest(
203 SyncClientFactory* client_factory) { 236 SyncClientFactory* client_factory) {
204 client_factory_ = client_factory; 237 client_factory_ = client_factory;
205 } 238 }
206 239
207 // static 240 // static
208 ProfileSyncServiceFactory::SyncClientFactory* 241 ProfileSyncServiceFactory::SyncClientFactory*
209 ProfileSyncServiceFactory::client_factory_ = nullptr; 242 ProfileSyncServiceFactory::client_factory_ = nullptr;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698