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

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: 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() {
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
93 std::string GAIAInfoUpdateService::GetCachedPictureURL() {
94 return profile_->GetPrefs()->GetString(prefs::kProfileGAIAInfoPictureURL);
95 }
96
91 void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader, 97 void GAIAInfoUpdateService::OnDownloadComplete(ProfileDownloader* downloader,
92 bool success) { 98 bool success) {
93 // Save the last updated time. 99 // Save the last updated time.
94 last_updated_ = base::Time::Now(); 100 last_updated_ = base::Time::Now();
95 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, 101 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime,
96 last_updated_.ToInternalValue()); 102 last_updated_.ToInternalValue());
97 ScheduleNextUpdate(); 103 ScheduleNextUpdate();
98 104
99 if (!success) { 105 if (!success) {
100 profile_image_downloader_.reset(); 106 profile_image_downloader_.reset();
101 return; 107 return;
102 } 108 }
103 109
104 string16 full_name = downloader->GetProfileFullName(); 110 string16 full_name = downloader->GetProfileFullName();
105 SkBitmap bitmap = downloader->GetProfilePicture(); 111 SkBitmap bitmap = downloader->GetProfilePicture();
112 ProfileDownloader::PictureResult picture_result =
113 downloader->GetProfilePictureResult();
114 std::string picture_url = downloader->GetProfilePictureURL();
106 profile_image_downloader_.reset(); 115 profile_image_downloader_.reset();
107 116
108 ProfileInfoCache& cache = 117 ProfileInfoCache& cache =
109 g_browser_process->profile_manager()->GetProfileInfoCache(); 118 g_browser_process->profile_manager()->GetProfileInfoCache();
110 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); 119 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
111 if (profile_index == std::string::npos) 120 if (profile_index == std::string::npos)
112 return; 121 return;
113 122
114 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name); 123 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name);
115 gfx::Image gfx_image(new SkBitmap(bitmap)); 124 if (picture_result == ProfileDownloader::PICTURE_SUCCESS) {
116 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); 125 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL,
126 picture_url);
127 gfx::Image gfx_image(new SkBitmap(bitmap));
128 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image);
129 } else if (picture_result == ProfileDownloader::PICTURE_DEFAULT) {
130 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL);
131 }
117 132
118 // If this profile hasn't switched to using GAIA information for the profile 133 // If this profile hasn't switched to using GAIA information for the profile
119 // name and picture then switch it now. Once the profile has switched this 134 // name and picture then switch it now. Once the profile has switched this
120 // preference guards against clobbering the user's custom settings. 135 // preference guards against clobbering the user's custom settings.
121 if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) { 136 if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) {
122 cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true); 137 cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true);
123 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); 138 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true);
124 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); 139 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true);
125 } 140 }
126 } 141 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 const base::TimeDelta update_delta = base::Time::Now() - last_updated_; 181 const base::TimeDelta update_delta = base::Time::Now() - last_updated_;
167 182
168 base::TimeDelta delta; 183 base::TimeDelta delta;
169 if (update_delta < base::TimeDelta() || update_delta > desired_delta) 184 if (update_delta < base::TimeDelta() || update_delta > desired_delta)
170 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); 185 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds);
171 else 186 else
172 delta = desired_delta - update_delta; 187 delta = desired_delta - update_delta;
173 188
174 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); 189 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update);
175 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698