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

Side by Side Diff: chrome/browser/profiles/gaia_info_update_service.cc

Issue 8742009: Cache GAIA profile picture URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 9 years 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/profiles/gaia_info_update_service.h" 5 #include "chrome/browser/profiles/gaia_info_update_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return false; 71 return false;
72 } 72 }
73 73
74 return true; 74 return true;
75 } 75 }
76 76
77 // static 77 // static
78 void GAIAInfoUpdateService::RegisterUserPrefs(PrefService* prefs) { 78 void GAIAInfoUpdateService::RegisterUserPrefs(PrefService* prefs) {
79 prefs->RegisterInt64Pref( 79 prefs->RegisterInt64Pref(
80 prefs::kProfileGAIAInfoUpdateTime, 0, PrefService::UNSYNCABLE_PREF); 80 prefs::kProfileGAIAInfoUpdateTime, 0, PrefService::UNSYNCABLE_PREF);
81 prefs->RegisterStringPref(
82 prefs::kProfileGAIAInfoPictureURL, "", PrefService::UNSYNCABLE_PREF);
81 } 83 }
82 84
83 int GAIAInfoUpdateService::GetDesiredImageSideLength() { 85 int GAIAInfoUpdateService::GetDesiredImageSideLength() const {
84 return 256; 86 return 256;
85 } 87 }
86 88
87 Profile* GAIAInfoUpdateService::GetBrowserProfile() { 89 Profile* GAIAInfoUpdateService::GetBrowserProfile() {
88 return profile_; 90 return profile_;
89 } 91 }
90 92
91 bool GAIAInfoUpdateService::ShouldUseOAuthRefreshToken() { 93 bool GAIAInfoUpdateService::ShouldUseOAuthRefreshToken() const {
92 return true; 94 return true;
93 } 95 }
94 96
97 std::string GAIAInfoUpdateService::GetCachedPictureURL() const {
98 return profile_->GetPrefs()->GetString(prefs::kProfileGAIAInfoPictureURL);
99 }
100
95 void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader, 101 void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader,
96 bool success) { 102 bool success) {
97 // Save the last updated time. 103 // Save the last updated time.
98 last_updated_ = base::Time::Now(); 104 last_updated_ = base::Time::Now();
99 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, 105 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime,
100 last_updated_.ToInternalValue()); 106 last_updated_.ToInternalValue());
101 ScheduleNextUpdate(); 107 ScheduleNextUpdate();
102 108
103 if (!success) { 109 if (!success) {
104 profile_image_downloader_.reset(); 110 profile_image_downloader_.reset();
105 return; 111 return;
106 } 112 }
107 113
108 string16 full_name = downloader->GetProfileFullName(); 114 string16 full_name = downloader->GetProfileFullName();
109 SkBitmap bitmap = downloader->GetProfilePicture(); 115 SkBitmap bitmap = downloader->GetProfilePicture();
116 ProfileDownloader::PictureStatus picture_status =
117 downloader->GetProfilePictureStatus();
118 std::string picture_url = downloader->GetProfilePictureURL();
110 profile_image_downloader_.reset(); 119 profile_image_downloader_.reset();
111 120
112 ProfileInfoCache& cache = 121 ProfileInfoCache& cache =
113 g_browser_process->profile_manager()->GetProfileInfoCache(); 122 g_browser_process->profile_manager()->GetProfileInfoCache();
114 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); 123 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
115 if (profile_index == std::string::npos) 124 if (profile_index == std::string::npos)
116 return; 125 return;
117 126
118 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name); 127 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name);
119 gfx::Image gfx_image(new SkBitmap(bitmap)); 128 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) {
120 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); 129 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL,
130 picture_url);
131 gfx::Image gfx_image(new SkBitmap(bitmap));
132 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image);
133 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) {
134 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL);
135 }
121 136
122 // If this profile hasn't switched to using GAIA information for the profile 137 // If this profile hasn't switched to using GAIA information for the profile
123 // name and picture then switch it now. Once the profile has switched this 138 // name and picture then switch it now. Once the profile has switched this
124 // preference guards against clobbering the user's custom settings. 139 // preference guards against clobbering the user's custom settings.
125 if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) { 140 if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) {
126 cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true); 141 cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true);
127 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); 142 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true);
128 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); 143 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true);
129 } 144 }
130 } 145 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const base::TimeDelta update_delta = base::Time::Now() - last_updated_; 185 const base::TimeDelta update_delta = base::Time::Now() - last_updated_;
171 186
172 base::TimeDelta delta; 187 base::TimeDelta delta;
173 if (update_delta < base::TimeDelta() || update_delta > desired_delta) 188 if (update_delta < base::TimeDelta() || update_delta > desired_delta)
174 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); 189 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds);
175 else 190 else
176 delta = desired_delta - update_delta; 191 delta = desired_delta - update_delta;
177 192
178 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); 193 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update);
179 } 194 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/gaia_info_update_service.h ('k') | chrome/browser/profiles/gaia_info_update_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698