Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/android/profiles/profile_downloader_android.h" | 5 #include "chrome/browser/android/profiles/profile_downloader_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_android.h" | 10 #include "chrome/browser/profiles/profile_android.h" |
| 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 12 #include "chrome/browser/profiles/profile_downloader.h" | 12 #include "chrome/browser/profiles/profile_downloader.h" |
| 13 #include "chrome/browser/profiles/profile_downloader_delegate.h" | 13 #include "chrome/browser/profiles/profile_downloader_delegate.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/signin/account_tracker_service_factory.h" | |
| 16 #include "components/signin/core/browser/account_tracker_service.h" | |
| 17 #include "google_apis/gaia/gaia_auth_util.h" | |
| 15 #include "jni/ProfileDownloader_jni.h" | 18 #include "jni/ProfileDownloader_jni.h" |
| 16 #include "third_party/skia/include/core/SkBitmap.h" | 19 #include "third_party/skia/include/core/SkBitmap.h" |
| 17 #include "ui/gfx/android/java_bitmap.h" | 20 #include "ui/gfx/android/java_bitmap.h" |
| 18 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
| 19 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| 23 // An account fetcher callback. | 26 // An account fetcher callback. |
| 24 class AccountInfoRetriever : public ProfileDownloaderDelegate { | 27 class AccountInfoRetriever : public ProfileDownloaderDelegate { |
| 25 public: | 28 public: |
| 26 explicit AccountInfoRetriever(Profile* profile, | 29 explicit AccountInfoRetriever(Profile* profile, |
|
Joao da Silva
2014/10/08 13:19:17
explicit isnt required here
Roger Tawa OOO till Jul 10th
2014/10/08 19:47:29
Done.
| |
| 27 const std::string& account_id, | 30 const std::string& account_id, |
| 31 const std::string& email, | |
| 28 const int desired_image_side_pixels) | 32 const int desired_image_side_pixels) |
| 29 : profile_(profile), | 33 : profile_(profile), |
| 30 account_id_(account_id), | 34 account_id_(account_id), |
| 35 email_(email), | |
| 31 desired_image_side_pixels_(desired_image_side_pixels) {} | 36 desired_image_side_pixels_(desired_image_side_pixels) {} |
| 32 | 37 |
| 33 void Start() { | 38 void Start() { |
| 34 profile_image_downloader_.reset(new ProfileDownloader(this)); | 39 profile_image_downloader_.reset(new ProfileDownloader(this)); |
| 35 profile_image_downloader_->StartForAccount(account_id_); | 40 profile_image_downloader_->StartForAccount(account_id_); |
| 36 } | 41 } |
| 37 | 42 |
| 38 void Shutdown() { | 43 void Shutdown() { |
| 39 profile_image_downloader_.reset(); | 44 profile_image_downloader_.reset(); |
| 40 delete this; | 45 delete this; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 53 return profile_; | 58 return profile_; |
| 54 } | 59 } |
| 55 | 60 |
| 56 virtual std::string GetCachedPictureURL() const OVERRIDE { | 61 virtual std::string GetCachedPictureURL() const OVERRIDE { |
| 57 return std::string(); | 62 return std::string(); |
| 58 } | 63 } |
| 59 | 64 |
| 60 virtual void OnProfileDownloadSuccess( | 65 virtual void OnProfileDownloadSuccess( |
| 61 ProfileDownloader* downloader) OVERRIDE { | 66 ProfileDownloader* downloader) OVERRIDE { |
| 62 ProfileDownloaderAndroid::OnProfileDownloadSuccess( | 67 ProfileDownloaderAndroid::OnProfileDownloadSuccess( |
| 63 account_id_, | 68 email_, |
| 64 downloader->GetProfileFullName(), | 69 downloader->GetProfileFullName(), |
| 65 downloader->GetProfilePicture()); | 70 downloader->GetProfilePicture()); |
| 66 Shutdown(); | 71 Shutdown(); |
| 67 } | 72 } |
| 68 | 73 |
| 69 virtual void OnProfileDownloadFailure( | 74 virtual void OnProfileDownloadFailure( |
| 70 ProfileDownloader* downloader, | 75 ProfileDownloader* downloader, |
| 71 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE { | 76 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE { |
| 72 LOG(ERROR) << "Failed to download the profile information: " << reason; | 77 LOG(ERROR) << "Failed to download the profile information: " << reason; |
| 73 Shutdown(); | 78 Shutdown(); |
| 74 } | 79 } |
| 75 | 80 |
| 76 // The profile image downloader instance. | 81 // The profile image downloader instance. |
| 77 scoped_ptr<ProfileDownloader> profile_image_downloader_; | 82 scoped_ptr<ProfileDownloader> profile_image_downloader_; |
| 78 | 83 |
| 79 // The browser profile associated with this download request. | 84 // The browser profile associated with this download request. |
| 80 Profile* profile_; | 85 Profile* profile_; |
| 81 | 86 |
| 82 // The account ID (email address) to be loaded. | 87 // The account ID and email address of account to be loaded. |
| 83 const std::string account_id_; | 88 const std::string account_id_; |
| 89 const std::string email_; | |
| 84 | 90 |
| 85 // Desired side length of the profile image (in pixels). | 91 // Desired side length of the profile image (in pixels). |
| 86 const int desired_image_side_pixels_; | 92 const int desired_image_side_pixels_; |
| 87 | 93 |
| 88 DISALLOW_COPY_AND_ASSIGN(AccountInfoRetriever); | 94 DISALLOW_COPY_AND_ASSIGN(AccountInfoRetriever); |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 } // namespace | 97 } // namespace |
| 92 | 98 |
| 93 // static | 99 // static |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 } | 149 } |
| 144 | 150 |
| 145 return jbitmap.Release(); | 151 return jbitmap.Release(); |
| 146 } | 152 } |
| 147 | 153 |
| 148 // static | 154 // static |
| 149 void StartFetchingAccountInfoFor( | 155 void StartFetchingAccountInfoFor( |
| 150 JNIEnv* env, | 156 JNIEnv* env, |
| 151 jclass clazz, | 157 jclass clazz, |
| 152 jobject jprofile, | 158 jobject jprofile, |
| 153 jstring jaccount_id, | 159 jstring jemail, |
| 154 jint image_side_pixels) { | 160 jint image_side_pixels) { |
| 155 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); | 161 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); |
| 156 const std::string account_id = | 162 const std::string email = |
| 157 base::android::ConvertJavaStringToUTF8(env, jaccount_id); | 163 base::android::ConvertJavaStringToUTF8(env, jemail); |
| 164 // TODO(rogerta): the java code will need to pass in the gaia-id | |
| 165 // of the account instead of the email when chrome uses gaia-id as key. | |
| 166 DCHECK_EQ(AccountTrackerService::MIGRATION_NOT_STARTED, | |
| 167 AccountTrackerServiceFactory::GetForProfile(profile)-> | |
| 168 GetMigrationState()); | |
| 158 AccountInfoRetriever* retriever = | 169 AccountInfoRetriever* retriever = |
| 159 new AccountInfoRetriever(profile, account_id, image_side_pixels); | 170 new AccountInfoRetriever(profile, gaia::CanonicalizeEmail(email), email, |
|
Joao da Silva
2014/10/08 13:19:17
signin_manager_base.cc calls SanitizeEmail too, sh
Roger Tawa OOO till Jul 10th
2014/10/08 19:47:29
Good point. Done.
| |
| 171 image_side_pixels); | |
| 160 retriever->Start(); | 172 retriever->Start(); |
| 161 } | 173 } |
| 162 | 174 |
| 163 // static | 175 // static |
| 164 bool ProfileDownloaderAndroid::Register(JNIEnv* env) { | 176 bool ProfileDownloaderAndroid::Register(JNIEnv* env) { |
| 165 return RegisterNativesImpl(env); | 177 return RegisterNativesImpl(env); |
| 166 } | 178 } |
| OLD | NEW |