OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_android.h" | 5 #include "chrome/browser/sync/profile_sync_service_android.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <string> |
| 11 #include <vector> |
11 | 12 |
12 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
13 #include "base/android/jni_array.h" | 14 #include "base/android/jni_array.h" |
14 #include "base/android/jni_string.h" | 15 #include "base/android/jni_string.h" |
15 #include "base/bind.h" | 16 #include "base/bind.h" |
16 #include "base/i18n/time_formatting.h" | 17 #include "base/i18n/time_formatting.h" |
17 #include "base/json/json_writer.h" | 18 #include "base/json/json_writer.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 NOTREACHED() << "Browser process or profile manager not initialized"; | 90 NOTREACHED() << "Browser process or profile manager not initialized"; |
90 return; | 91 return; |
91 } | 92 } |
92 | 93 |
93 profile_ = ProfileManager::GetActiveUserProfile(); | 94 profile_ = ProfileManager::GetActiveUserProfile(); |
94 if (profile_ == nullptr) { | 95 if (profile_ == nullptr) { |
95 NOTREACHED() << "Sync Init: Profile not found."; | 96 NOTREACHED() << "Sync Init: Profile not found."; |
96 return; | 97 return; |
97 } | 98 } |
98 | 99 |
99 sync_prefs_.reset(new sync_driver::SyncPrefs(profile_->GetPrefs())); | 100 sync_prefs_.reset(new syncer::SyncPrefs(profile_->GetPrefs())); |
100 | 101 |
101 sync_service_ = | 102 sync_service_ = |
102 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); | 103 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); |
103 } | 104 } |
104 | 105 |
105 bool ProfileSyncServiceAndroid::Init() { | 106 bool ProfileSyncServiceAndroid::Init() { |
106 if (sync_service_) { | 107 if (sync_service_) { |
107 sync_service_->AddObserver(this); | 108 sync_service_->AddObserver(this); |
108 sync_service_->SetPlatformSyncAllowedProvider( | 109 sync_service_->SetPlatformSyncAllowedProvider( |
109 base::Bind(&ProfileSyncServiceAndroid::IsSyncAllowedByAndroid, | 110 base::Bind(&ProfileSyncServiceAndroid::IsSyncAllowedByAndroid, |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 461 } |
461 | 462 |
462 // Functionality only available for testing purposes. | 463 // Functionality only available for testing purposes. |
463 | 464 |
464 ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::GetAboutInfoForTest( | 465 ScopedJavaLocalRef<jstring> ProfileSyncServiceAndroid::GetAboutInfoForTest( |
465 JNIEnv* env, | 466 JNIEnv* env, |
466 const JavaParamRef<jobject>&) { | 467 const JavaParamRef<jobject>&) { |
467 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 468 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
468 | 469 |
469 std::unique_ptr<base::DictionaryValue> about_info = | 470 std::unique_ptr<base::DictionaryValue> about_info = |
470 sync_driver::sync_ui_util::ConstructAboutInformation( | 471 syncer::sync_ui_util::ConstructAboutInformation( |
471 sync_service_, sync_service_->signin(), chrome::GetChannel()); | 472 sync_service_, sync_service_->signin(), chrome::GetChannel()); |
472 std::string about_info_json; | 473 std::string about_info_json; |
473 base::JSONWriter::Write(*about_info, &about_info_json); | 474 base::JSONWriter::Write(*about_info, &about_info_json); |
474 | 475 |
475 return ConvertUTF8ToJavaString(env, about_info_json); | 476 return ConvertUTF8ToJavaString(env, about_info_json); |
476 } | 477 } |
477 | 478 |
478 jlong ProfileSyncServiceAndroid::GetLastSyncedTimeForTest( | 479 jlong ProfileSyncServiceAndroid::GetLastSyncedTimeForTest( |
479 JNIEnv* env, | 480 JNIEnv* env, |
480 const JavaParamRef<jobject>& obj) { | 481 const JavaParamRef<jobject>& obj) { |
481 // Use profile preferences here instead of SyncPrefs to avoid an extra | 482 // Use profile preferences here instead of SyncPrefs to avoid an extra |
482 // conversion, since SyncPrefs::GetLastSyncedTime() converts the stored value | 483 // conversion, since SyncPrefs::GetLastSyncedTime() converts the stored value |
483 // to to base::Time. | 484 // to to base::Time. |
484 return static_cast<jlong>( | 485 return static_cast<jlong>( |
485 profile_->GetPrefs()->GetInt64(sync_driver::prefs::kSyncLastSyncedTime)); | 486 profile_->GetPrefs()->GetInt64(syncer::prefs::kSyncLastSyncedTime)); |
486 } | 487 } |
487 | 488 |
488 void ProfileSyncServiceAndroid::OverrideNetworkResourcesForTest( | 489 void ProfileSyncServiceAndroid::OverrideNetworkResourcesForTest( |
489 JNIEnv* env, | 490 JNIEnv* env, |
490 const JavaParamRef<jobject>& obj, | 491 const JavaParamRef<jobject>& obj, |
491 jlong network_resources) { | 492 jlong network_resources) { |
492 syncer::NetworkResources* resources = | 493 syncer::NetworkResources* resources = |
493 reinterpret_cast<syncer::NetworkResources*>(network_resources); | 494 reinterpret_cast<syncer::NetworkResources*>(network_resources); |
494 sync_service_->OverrideNetworkResourcesForTest( | 495 sync_service_->OverrideNetworkResourcesForTest( |
495 base::WrapUnique<syncer::NetworkResources>(resources)); | 496 base::WrapUnique<syncer::NetworkResources>(resources)); |
(...skipping 15 matching lines...) Expand all Loading... |
511 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 512 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
512 ProfileSyncServiceAndroid* profile_sync_service_android = | 513 ProfileSyncServiceAndroid* profile_sync_service_android = |
513 new ProfileSyncServiceAndroid(env, obj); | 514 new ProfileSyncServiceAndroid(env, obj); |
514 if (profile_sync_service_android->Init()) { | 515 if (profile_sync_service_android->Init()) { |
515 return reinterpret_cast<intptr_t>(profile_sync_service_android); | 516 return reinterpret_cast<intptr_t>(profile_sync_service_android); |
516 } else { | 517 } else { |
517 delete profile_sync_service_android; | 518 delete profile_sync_service_android; |
518 return 0; | 519 return 0; |
519 } | 520 } |
520 } | 521 } |
OLD | NEW |