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