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

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

Issue 12313075: [sync] Upstream the Android ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/profile_sync_service_android.h"
6
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/bind.h"
10 #include "base/i18n/time_formatting.h"
11 #include "base/json/json_writer.h"
12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/time.h"
15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/signin/signin_manager.h"
18 #include "chrome/browser/signin/signin_manager_factory.h"
19 #include "chrome/browser/signin/token_service.h"
20 #include "chrome/browser/signin/token_service_factory.h"
21 #include "chrome/browser/sync/about_sync_util.h"
22 #include "chrome/browser/sync/profile_sync_service.h"
23 #include "chrome/browser/sync/profile_sync_service_factory.h"
24 #include "chrome/browser/sync/sync_prefs.h"
25 #include "chrome/browser/sync/sync_ui_util.h"
26 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/pref_names.h"
28 #include "content/public/browser/notification_service.h"
29 #include "google/cacheinvalidation/types.pb.h"
30 #include "google_apis/gaia/gaia_constants.h"
31 #include "google_apis/gaia/google_service_auth_error.h"
32 #include "grit/generated_resources.h"
33 #include "jni/ProfileSyncService_jni.h"
34 #include "sync/internal_api/public/base/model_type_invalidation_map.h"
35 #include "sync/internal_api/public/read_transaction.h"
36 #include "ui/base/l10n/l10n_util.h"
37
38 using base::android::AttachCurrentThread;
39 using base::android::CheckException;
40 using base::android::ConvertJavaStringToUTF8;
41 using base::android::ConvertUTF8ToJavaString;
42 using base::android::ScopedJavaLocalRef;
43 using content::BrowserThread;
44
45 namespace {
46 const char kSyncDisabledStatus[] = "OFFLINE_DISABLED";
47
48 enum {
49 #define DEFINE_MODEL_TYPE_SELECTION(name,value) name = value,
50 #include "chrome/browser/sync/profile_sync_service_model_type_selection_android. h"
51 #undef DEFINE_MODEL_TYPE_SELECTION
52 };
53
54 } // namespace
55
56 ProfileSyncServiceAndroid::ProfileSyncServiceAndroid(JNIEnv* env, jobject obj)
57 : profile_(NULL),
58 sync_service_(NULL),
59 weak_java_profile_sync_service_(env, obj) {
60 if (g_browser_process == NULL ||
61 g_browser_process->profile_manager() == NULL) {
62 NOTREACHED() << "Browser process or profile manager not initialized";
63 return;
64 }
65
66 profile_ = g_browser_process->profile_manager()->GetDefaultProfile();
67 if (profile_ == NULL) {
68 NOTREACHED() << "Sync Init: Profile not found.";
69 return;
70 }
71
72 sync_service_ =
73 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_);
74 DCHECK(sync_service_);
75 }
76
77 void ProfileSyncServiceAndroid::Init() {
78 sync_service_->AddObserver(this);
79
80 std::string signed_in_username =
81 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername();
82 if (!signed_in_username.empty()) {
83 // If the user is logged in, see if he has a valid token - if not, fetch
84 // a new one.
85 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
86 if (!token_service->HasTokenForService(GaiaConstants::kSyncService) ||
87 (sync_service_->GetAuthError().state() ==
88 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)) {
89 DVLOG(2) << "Trying to update token for user " << signed_in_username;
90 InvalidateAuthToken();
91 }
92 }
93 }
94
95 void ProfileSyncServiceAndroid::RemoveObserver() {
96 if (sync_service_->HasObserver(this)) {
97 sync_service_->RemoveObserver(this);
98 }
99 }
100
101 ProfileSyncServiceAndroid::~ProfileSyncServiceAndroid() {
102 RemoveObserver();
103 }
104
105 void ProfileSyncServiceAndroid::SendNudgeNotification(
106 const std::string& str_object_id,
107 int64 version,
108 const std::string& state) {
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
110
111 // TODO(nileshagrawal): Merge this with ChromeInvalidationClient::Invalidate.
112 // Construct the ModelTypeStateMap and send it over with the notification.
113 syncer::ModelType model_type;
114 if (!syncer::NotificationTypeToRealModelType(str_object_id, &model_type)) {
115 DVLOG(1) << "Could not get invalidation model type; "
116 << "Sending notification with empty state map.";
117 syncer::ModelTypeInvalidationMap model_types_with_states;
118 content::NotificationService::current()->Notify(
119 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
120 content::Source<Profile>(profile_),
121 content::Details<const syncer::ModelTypeInvalidationMap>(
122 &model_types_with_states));
123 return;
124 }
125
126 if (version != ipc::invalidation::Constants::UNKNOWN) {
127 std::map<syncer::ModelType, int64>::const_iterator it =
128 max_invalidation_versions_.find(model_type);
129 if ((it != max_invalidation_versions_.end()) &&
130 (version <= it->second)) {
131 DVLOG(1) << "Dropping redundant invalidation with version " << version;
132 return;
133 }
134 max_invalidation_versions_[model_type] = version;
135 }
136
137 syncer::ModelTypeSet types;
138 types.Put(model_type);
139 syncer::ModelTypeInvalidationMap model_types_with_states =
140 syncer::ModelTypeSetToInvalidationMap(types, state);
141
142 content::NotificationService::current()->Notify(
143 chrome::NOTIFICATION_SYNC_REFRESH_REMOTE,
144 content::Source<Profile>(profile_),
145 content::Details<const syncer::ModelTypeInvalidationMap>(
146 &model_types_with_states));
147 }
148
149
150 void ProfileSyncServiceAndroid::OnStateChanged() {
151 // Check for auth errors.
152 const GoogleServiceAuthError& auth_error = sync_service_->GetAuthError();
153 if (auth_error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) {
154 DVLOG(2) << "Updating auth token.";
155 InvalidateAuthToken();
156 }
157
158 // Notify the java world that our sync state has changed.
159 JNIEnv* env = AttachCurrentThread();
160 Java_ProfileSyncService_syncStateChanged(
161 env, weak_java_profile_sync_service_.get(env).obj());
162 }
163
164 void ProfileSyncServiceAndroid::TokenAvailable(
165 JNIEnv* env, jobject, jstring username, jstring auth_token) {
166 std::string token = ConvertJavaStringToUTF8(env, auth_token);
167 TokenServiceFactory::GetForProfile(profile_)->OnIssueAuthTokenSuccess(
168 GaiaConstants::kSyncService, token);
169 }
170
171 void ProfileSyncServiceAndroid::EnableSync(JNIEnv* env, jobject) {
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
173 // Don't need to do anything if we're already enabled.
174 browser_sync::SyncPrefs prefs(profile_->GetPrefs());
175 if (prefs.IsStartSuppressed())
176 sync_service_->UnsuppressAndStart();
177 else
178 DVLOG(2) << "Ignoring call to EnableSync() because sync is already enabled";
179 }
180
181 void ProfileSyncServiceAndroid::DisableSync(JNIEnv* env, jobject) {
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
183 sync_service_->StopAndSuppress();
184 }
185
186 void ProfileSyncServiceAndroid::SignInSync(
187 JNIEnv* env, jobject, jstring username, jstring auth_token) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
189 // Just return if sync already has everything it needs to start up (sync
190 // should start up automatically as long as it has credentials). This can
191 // happen normally if (for example) the user closes and reopens the sync
192 // settings window quickly during initial startup.
193 if (sync_service_->IsSyncEnabledAndLoggedIn() &&
194 sync_service_->IsSyncTokenAvailable() &&
195 sync_service_->HasSyncSetupCompleted()) {
196 return;
197 }
198
199 if (!sync_service_->IsSyncEnabledAndLoggedIn() ||
200 !sync_service_->IsSyncTokenAvailable()) {
201 // Set the currently-signed-in username, fetch an auth token if necessary,
202 // and enable sync.
203 std::string name = ConvertJavaStringToUTF8(env, username);
204 SigninManagerFactory::GetForProfile(profile_)->
205 SetAuthenticatedUsername(name);
206 std::string token = ConvertJavaStringToUTF8(env, auth_token);
207 if (token.empty()) {
208 // No credentials passed in - request an auth token.
209 // If fetching the auth token is successful, this will cause
210 // ProfileSyncService to start sync when it receives
211 // NOTIFICATION_TOKEN_AVAILABLE.
212 DVLOG(2) << "Fetching auth token for " << name;
213 InvalidateAuthToken();
214 } else {
215 // OnIssueAuthTokenSuccess will send out a notification to the sync
216 // service that will cause the sync backend to initialize.
217 TokenService* token_service =
218 TokenServiceFactory::GetForProfile(profile_);
219 token_service->OnIssueAuthTokenSuccess(GaiaConstants::kSyncService,
220 token);
221 }
222 }
223
224 // Enable sync (if we don't have credentials yet, this will enable sync but
225 // will not start it up - sync will start once credentials arrive).
226 sync_service_->UnsuppressAndStart();
227 }
228
229 void ProfileSyncServiceAndroid::SignOutSync(JNIEnv* env, jobject) {
230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
231 DCHECK(profile_);
232 sync_service_->DisableForUser();
233
234 // Clear the tokens.
235 SigninManagerFactory::GetForProfile(profile_)->SignOut();
236
237 // Need to clear suppress start flag manually
238 browser_sync::SyncPrefs prefs(profile_->GetPrefs());
239 prefs.SetStartSuppressed(false);
240 }
241
242 ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::QuerySyncStatusSummary(
243 JNIEnv* env, jobject) {
244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
245 DCHECK(profile_);
246 std::string status(sync_service_->QuerySyncStatusSummary());
247 return ConvertUTF8ToJavaString(env, status);
248 }
249
250 jboolean ProfileSyncServiceAndroid::SetSyncSessionsId(
251 JNIEnv* env, jobject obj, jstring tag) {
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
253 DCHECK(profile_);
254 std::string machine_tag = ConvertJavaStringToUTF8(env, tag);
255 browser_sync::SyncPrefs prefs(profile_->GetPrefs());
256 prefs.SetSyncSessionsGUID(machine_tag);
257 return true;
258 }
259
260 jint ProfileSyncServiceAndroid::GetAuthError(JNIEnv* env, jobject) {
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
262 return sync_service_->GetAuthError().state();
263 }
264
265 jboolean ProfileSyncServiceAndroid::IsEncryptEverythingEnabled(
266 JNIEnv* env, jobject) {
267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
268 return sync_service_->EncryptEverythingEnabled();
269 }
270
271 jboolean ProfileSyncServiceAndroid::IsSyncInitialized(JNIEnv* env, jobject) {
272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
273 return sync_service_->sync_initialized();
274 }
275
276 jboolean ProfileSyncServiceAndroid::IsFirstSetupInProgress(
277 JNIEnv* env, jobject) {
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
279 return sync_service_->FirstSetupInProgress();
280 }
281
282 jboolean ProfileSyncServiceAndroid::IsPassphraseRequired(JNIEnv* env, jobject) {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
284 return sync_service_->IsPassphraseRequired();
285 }
286
287 jboolean ProfileSyncServiceAndroid::IsPassphraseRequiredForDecryption(
288 JNIEnv* env, jobject obj) {
289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
290 // In case of CUSTOM_PASSPHRASE we always sync passwords. Prompt the user for
291 // a passphrase if cryptographer has any pending keys.
292 if (sync_service_->GetPassphraseType() == syncer::CUSTOM_PASSPHRASE) {
293 return !IsCryptographerReady(env, obj);
294 }
295 if (sync_service_->IsPassphraseRequiredForDecryption()) {
296 // Passwords datatype should never prompt for a passphrase, except when
297 // user is using a custom passphrase. Do not prompt for a passphrase if
298 // passwords are the only encrypted datatype. This prevents a temporary
299 // notification for passphrase when PSS has not completed configuring
300 // DataTypeManager, after configuration password datatype shall be disabled.
301 const syncer::ModelTypeSet encrypted_types =
302 sync_service_->GetEncryptedDataTypes();
303 const bool are_passwords_the_only_encrypted_type =
304 encrypted_types.Has(syncer::PASSWORDS) && encrypted_types.Size() == 1 &&
305 !sync_service_->ShouldEnablePasswordSyncForAndroid();
306 return !are_passwords_the_only_encrypted_type;
307 }
308 return false;
309 }
310
311 jboolean ProfileSyncServiceAndroid::IsPassphraseRequiredForExternalType(
312 JNIEnv* env, jobject) {
313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
314 return
315 sync_service_->passphrase_required_reason() == syncer::REASON_DECRYPTION;
316 }
317
318 jboolean ProfileSyncServiceAndroid::IsUsingSecondaryPassphrase(
319 JNIEnv* env, jobject) {
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
321 return sync_service_->IsUsingSecondaryPassphrase();
322 }
323
324 jboolean ProfileSyncServiceAndroid::SetDecryptionPassphrase(
325 JNIEnv* env, jobject obj, jstring passphrase) {
326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
327 std::string key = ConvertJavaStringToUTF8(env, passphrase);
328 return sync_service_->SetDecryptionPassphrase(key);
329 }
330
331 void ProfileSyncServiceAndroid::SetEncryptionPassphrase(
332 JNIEnv* env, jobject obj, jstring passphrase, jboolean is_gaia) {
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
334 std::string key = ConvertJavaStringToUTF8(env, passphrase);
335 sync_service_->SetEncryptionPassphrase(
336 key,
337 is_gaia ? ProfileSyncService::IMPLICIT : ProfileSyncService::EXPLICIT);
338 }
339
340 jboolean ProfileSyncServiceAndroid::IsCryptographerReady(JNIEnv* env, jobject) {
341 syncer::ReadTransaction trans(FROM_HERE, sync_service_->GetUserShare());
342 return sync_service_->IsCryptographerReady(&trans);
343 }
344
345 jint ProfileSyncServiceAndroid::GetPassphraseType(JNIEnv* env, jobject) {
346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
347 return sync_service_->GetPassphraseType();
348 }
349
350 jboolean ProfileSyncServiceAndroid::HasExplicitPassphraseTime(
351 JNIEnv* env, jobject) {
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
353 base::Time passphrase_time = sync_service_->GetExplicitPassphraseTime();
354 return !passphrase_time.is_null();
355 }
356
357 ScopedJavaLocalRef<jstring>
358 ProfileSyncServiceAndroid::GetSyncEnterGooglePassphraseBodyWithDateText(
359 JNIEnv* env, jobject) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
361 base::Time passphrase_time = sync_service_->GetExplicitPassphraseTime();
362 string16 passphrase_time_str = base::TimeFormatShortDate(passphrase_time);
363 return base::android::ConvertUTF16ToJavaString(env,
364 l10n_util::GetStringFUTF16(
365 IDS_SYNC_ENTER_GOOGLE_PASSPHRASE_BODY_WITH_DATE,
366 passphrase_time_str));
367 }
368
369 ScopedJavaLocalRef<jstring>
370 ProfileSyncServiceAndroid::GetSyncEnterCustomPassphraseBodyWithDateText(
371 JNIEnv* env, jobject) {
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
373 base::Time passphrase_time = sync_service_->GetExplicitPassphraseTime();
374 string16 passphrase_time_str = base::TimeFormatShortDate(passphrase_time);
375 return base::android::ConvertUTF16ToJavaString(env,
376 l10n_util::GetStringFUTF16(IDS_SYNC_ENTER_PASSPHRASE_BODY_WITH_DATE,
377 passphrase_time_str));
378 }
379
380 ScopedJavaLocalRef<jstring>
381 ProfileSyncServiceAndroid::GetSyncEnterCustomPassphraseBodyText(
382 JNIEnv* env, jobject) {
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
384 return ConvertUTF8ToJavaString(
385 env, l10n_util::GetStringUTF8(IDS_SYNC_ENTER_PASSPHRASE_BODY));
386 }
387
388 jboolean ProfileSyncServiceAndroid::IsSyncKeystoreMigrationDone(
389 JNIEnv* env, jobject) {
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
391 syncer::SyncStatus status;
392 bool is_status_valid = sync_service_->QueryDetailedSyncStatus(&status);
393 return is_status_valid && !status.keystore_migration_time.is_null();
394 }
395
396 void ProfileSyncServiceAndroid::SetPreferredDataTypes(
397 JNIEnv* env, jobject obj,
398 jboolean sync_everything,
399 jlong model_type_selection) {
400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
401 syncer::ModelTypeSet types;
402 if (model_type_selection & AUTOFILL)
403 types.Put(syncer::AUTOFILL);
404 if (model_type_selection & BOOKMARK)
405 types.Put(syncer::BOOKMARKS);
406 if (model_type_selection & PASSWORD)
407 types.Put(syncer::PASSWORDS);
408 if (model_type_selection & SESSION)
409 types.Put(syncer::SESSIONS);
410 if (model_type_selection & TYPED_URL)
411 types.Put(syncer::TYPED_URLS);
412 sync_service_->OnUserChoseDatatypes(sync_everything, types);
413 }
414
415 void ProfileSyncServiceAndroid::SetSetupInProgress(
416 JNIEnv* env, jobject obj, jboolean in_progress) {
417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
418 sync_service_->SetSetupInProgress(in_progress);
419 }
420
421 void ProfileSyncServiceAndroid::SetSyncSetupCompleted(
422 JNIEnv* env, jobject obj) {
423 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
424 sync_service_->SetSyncSetupCompleted();
425 }
426
427 jboolean ProfileSyncServiceAndroid::HasSyncSetupCompleted(
428 JNIEnv* env, jobject obj) {
429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
430 return sync_service_->HasSyncSetupCompleted();
431 }
432
433 void ProfileSyncServiceAndroid::EnableEncryptEverything(
434 JNIEnv* env, jobject obj) {
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
436 sync_service_->EnableEncryptEverything();
437 }
438
439 jboolean ProfileSyncServiceAndroid::HasKeepEverythingSynced(
440 JNIEnv* env, jobject) {
441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
442 browser_sync::SyncPrefs prefs(profile_->GetPrefs());
443 return prefs.HasKeepEverythingSynced();
444 }
445
446 jboolean ProfileSyncServiceAndroid::IsAutofillSyncEnabled(
447 JNIEnv* env, jobject obj) {
448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
449 return HasKeepEverythingSynced(env, obj) ||
450 sync_service_->GetPreferredDataTypes().Has(syncer::AUTOFILL);
451 }
452
453 jboolean ProfileSyncServiceAndroid::IsBookmarkSyncEnabled(
454 JNIEnv* env, jobject obj) {
455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
456 return HasKeepEverythingSynced(env, obj) ||
457 sync_service_->GetPreferredDataTypes().Has(syncer::BOOKMARKS);
458 }
459
460 jboolean ProfileSyncServiceAndroid::IsPasswordSyncEnabled(
461 JNIEnv* env, jobject obj) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
463 return HasKeepEverythingSynced(env, obj) ||
464 sync_service_->GetPreferredDataTypes().Has(syncer::PASSWORDS);
465 }
466
467 jboolean ProfileSyncServiceAndroid::IsTypedUrlSyncEnabled(
468 JNIEnv* env, jobject obj) {
469 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
470 return HasKeepEverythingSynced(env, obj) ||
471 sync_service_->GetPreferredDataTypes().Has(syncer::TYPED_URLS);
472 }
473
474 jboolean ProfileSyncServiceAndroid::IsSessionSyncEnabled(
475 JNIEnv* env, jobject obj) {
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
477 return HasKeepEverythingSynced(env, obj) ||
478 sync_service_->GetPreferredDataTypes().Has(syncer::SESSIONS);
479 }
480
481 jboolean ProfileSyncServiceAndroid::HasUnrecoverableError(
482 JNIEnv* env, jobject) {
483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
484 return sync_service_->HasUnrecoverableError();
485 }
486
487 ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::GetAboutInfoForTest(
488 JNIEnv* env, jobject) {
489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
490
491 scoped_ptr<DictionaryValue> about_info =
492 sync_ui_util::ConstructAboutInformation(sync_service_);
493 std::string about_info_json;
494 base::JSONWriter::Write(about_info.get(), &about_info_json);
495
496 return ConvertUTF8ToJavaString(env, about_info_json);
497 }
498
499 void ProfileSyncServiceAndroid::InvalidateAuthToken() {
500 // Get the token from token-db. If there's no token yet, this must be the
501 // the first time the user is signing in so we don't need to invalidate
502 // anything.
503 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
504 std::string invalid_token;
505 if (token_service->HasTokenForService(GaiaConstants::kSyncService)) {
506 invalid_token = token_service->GetTokenForService(
507 GaiaConstants::kSyncService);
508 }
509 const std::string& sync_username =
510 SigninManagerFactory::GetForProfile(profile_)->GetAuthenticatedUsername();
511 // Call into java to invalidate the current token and get a new one.
512 JNIEnv* env = AttachCurrentThread();
513 ScopedJavaLocalRef<jstring> j_sync_username =
514 ConvertUTF8ToJavaString(env, sync_username);
515 ScopedJavaLocalRef<jstring> j_invalid_token =
516 ConvertUTF8ToJavaString(env, invalid_token);
517 Java_ProfileSyncService_getNewAuthToken(
518 env, weak_java_profile_sync_service_.get(env).obj(),
519 j_sync_username.obj(), j_invalid_token.obj());
520 }
521
522 void ProfileSyncServiceAndroid::NudgeSyncer(JNIEnv* env,
523 jobject obj,
524 jstring objectId,
525 jlong version,
526 jstring state) {
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
528 SendNudgeNotification(ConvertJavaStringToUTF8(env, objectId), version,
529 ConvertJavaStringToUTF8(env, state));
530 }
531
532 static int Init(JNIEnv* env, jobject obj) {
533 ProfileSyncServiceAndroid* profile_sync_service_android =
534 new ProfileSyncServiceAndroid(env, obj);
535 profile_sync_service_android->Init();
536 return reinterpret_cast<jint>(profile_sync_service_android);
537 }
538
539 // static
540 bool ProfileSyncServiceAndroid::Register(JNIEnv* env) {
541 return RegisterNativesImpl(env);
542 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698