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

Side by Side Diff: chrome/browser/android/profiles/profile_downloader_android.cc

Issue 617183003: Make sure GetAuthenticatedAccountId() returns a canonicalized id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 6 years, 2 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
OLDNEW
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 "google_apis/gaia/gaia_auth_util.h"
15 #include "jni/ProfileDownloader_jni.h" 16 #include "jni/ProfileDownloader_jni.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "ui/gfx/android/java_bitmap.h" 18 #include "ui/gfx/android/java_bitmap.h"
18 #include "ui/gfx/image/image_skia.h" 19 #include "ui/gfx/image/image_skia.h"
19 #include "ui/gfx/screen.h" 20 #include "ui/gfx/screen.h"
20 21
21 namespace { 22 namespace {
22 23
23 // An account fetcher callback. 24 // An account fetcher callback.
24 class AccountInfoRetriever : public ProfileDownloaderDelegate { 25 class AccountInfoRetriever : public ProfileDownloaderDelegate {
25 public: 26 public:
26 explicit AccountInfoRetriever(Profile* profile, 27 explicit AccountInfoRetriever(Profile* profile,
27 const std::string& account_id, 28 const std::string& account_id,
29 const std::string& email,
28 const int desired_image_side_pixels) 30 const int desired_image_side_pixels)
29 : profile_(profile), 31 : profile_(profile),
30 account_id_(account_id), 32 account_id_(account_id),
33 email_(email),
31 desired_image_side_pixels_(desired_image_side_pixels) {} 34 desired_image_side_pixels_(desired_image_side_pixels) {}
32 35
33 void Start() { 36 void Start() {
34 profile_image_downloader_.reset(new ProfileDownloader(this)); 37 profile_image_downloader_.reset(new ProfileDownloader(this));
35 profile_image_downloader_->StartForAccount(account_id_); 38 profile_image_downloader_->StartForAccount(account_id_);
36 } 39 }
37 40
38 void Shutdown() { 41 void Shutdown() {
39 profile_image_downloader_.reset(); 42 profile_image_downloader_.reset();
40 delete this; 43 delete this;
(...skipping 12 matching lines...) Expand all
53 return profile_; 56 return profile_;
54 } 57 }
55 58
56 virtual std::string GetCachedPictureURL() const OVERRIDE { 59 virtual std::string GetCachedPictureURL() const OVERRIDE {
57 return std::string(); 60 return std::string();
58 } 61 }
59 62
60 virtual void OnProfileDownloadSuccess( 63 virtual void OnProfileDownloadSuccess(
61 ProfileDownloader* downloader) OVERRIDE { 64 ProfileDownloader* downloader) OVERRIDE {
62 ProfileDownloaderAndroid::OnProfileDownloadSuccess( 65 ProfileDownloaderAndroid::OnProfileDownloadSuccess(
63 account_id_, 66 email_,
64 downloader->GetProfileFullName(), 67 downloader->GetProfileFullName(),
65 downloader->GetProfilePicture()); 68 downloader->GetProfilePicture());
66 Shutdown(); 69 Shutdown();
67 } 70 }
68 71
69 virtual void OnProfileDownloadFailure( 72 virtual void OnProfileDownloadFailure(
70 ProfileDownloader* downloader, 73 ProfileDownloader* downloader,
71 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE { 74 ProfileDownloaderDelegate::FailureReason reason) OVERRIDE {
72 LOG(ERROR) << "Failed to download the profile information: " << reason; 75 LOG(ERROR) << "Failed to download the profile information: " << reason;
73 Shutdown(); 76 Shutdown();
74 } 77 }
75 78
76 // The profile image downloader instance. 79 // The profile image downloader instance.
77 scoped_ptr<ProfileDownloader> profile_image_downloader_; 80 scoped_ptr<ProfileDownloader> profile_image_downloader_;
78 81
79 // The browser profile associated with this download request. 82 // The browser profile associated with this download request.
80 Profile* profile_; 83 Profile* profile_;
81 84
82 // The account ID (email address) to be loaded. 85 // The account ID and email address of account to be loaded.
83 const std::string account_id_; 86 const std::string account_id_;
87 const std::string email_;
84 88
85 // Desired side length of the profile image (in pixels). 89 // Desired side length of the profile image (in pixels).
86 const int desired_image_side_pixels_; 90 const int desired_image_side_pixels_;
87 91
88 DISALLOW_COPY_AND_ASSIGN(AccountInfoRetriever); 92 DISALLOW_COPY_AND_ASSIGN(AccountInfoRetriever);
89 }; 93 };
90 94
91 } // namespace 95 } // namespace
92 96
93 // static 97 // static
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 147 }
144 148
145 return jbitmap.Release(); 149 return jbitmap.Release();
146 } 150 }
147 151
148 // static 152 // static
149 void StartFetchingAccountInfoFor( 153 void StartFetchingAccountInfoFor(
150 JNIEnv* env, 154 JNIEnv* env,
151 jclass clazz, 155 jclass clazz,
152 jobject jprofile, 156 jobject jprofile,
153 jstring jaccount_id, 157 jstring jemail,
154 jint image_side_pixels) { 158 jint image_side_pixels) {
155 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile); 159 Profile* profile = ProfileAndroid::FromProfileAndroid(jprofile);
156 const std::string account_id = 160 const std::string email =
157 base::android::ConvertJavaStringToUTF8(env, jaccount_id); 161 base::android::ConvertJavaStringToUTF8(env, jemail);
162 // TODO(rogerta): the java code will need to pass in the gaia-id
163 // of the account instead of the email when chrome uses gaia-id as key.
158 AccountInfoRetriever* retriever = 164 AccountInfoRetriever* retriever =
159 new AccountInfoRetriever(profile, account_id, image_side_pixels); 165 new AccountInfoRetriever(profile, gaia::CanonicalizeEmail(email), email,
166 image_side_pixels);
guohui 2014/10/07 04:06:03 it may be better to add a DCHECK for AccountTracke
Roger Tawa OOO till Jul 10th 2014/10/07 21:38:30 Done.
160 retriever->Start(); 167 retriever->Start();
161 } 168 }
162 169
163 // static 170 // static
164 bool ProfileDownloaderAndroid::Register(JNIEnv* env) { 171 bool ProfileDownloaderAndroid::Register(JNIEnv* env) {
165 return RegisterNativesImpl(env); 172 return RegisterNativesImpl(env);
166 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698