OLD | NEW |
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 "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 std::string picture_url = downloader->GetProfilePictureURL(); | 106 std::string picture_url = downloader->GetProfilePictureURL(); |
107 profile_image_downloader_.reset(); | 107 profile_image_downloader_.reset(); |
108 | 108 |
109 ProfileInfoCache& cache = | 109 ProfileInfoCache& cache = |
110 g_browser_process->profile_manager()->GetProfileInfoCache(); | 110 g_browser_process->profile_manager()->GetProfileInfoCache(); |
111 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 111 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
112 if (profile_index == std::string::npos) | 112 if (profile_index == std::string::npos) |
113 return; | 113 return; |
114 | 114 |
115 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name); | 115 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name); |
| 116 // The profile index may have changed. |
| 117 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 118 if (profile_index == std::string::npos) |
| 119 return; |
116 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { | 120 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { |
117 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, | 121 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, |
118 picture_url); | 122 picture_url); |
119 gfx::Image gfx_image(new SkBitmap(bitmap)); | 123 gfx::Image gfx_image(new SkBitmap(bitmap)); |
120 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); | 124 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); |
121 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { | 125 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { |
122 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); | 126 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); |
123 } | 127 } |
124 | 128 |
125 // If this profile hasn't switched to using GAIA information for the profile | 129 // If this profile hasn't switched to using GAIA information for the profile |
(...skipping 24 matching lines...) Expand all Loading... |
150 g_browser_process->profile_manager()->GetProfileInfoCache(); | 154 g_browser_process->profile_manager()->GetProfileInfoCache(); |
151 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 155 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
152 if (profile_index == std::string::npos) | 156 if (profile_index == std::string::npos) |
153 return; | 157 return; |
154 | 158 |
155 std::string username = profile_->GetPrefs()->GetString( | 159 std::string username = profile_->GetPrefs()->GetString( |
156 prefs::kGoogleServicesUsername); | 160 prefs::kGoogleServicesUsername); |
157 if (username.empty()) { | 161 if (username.empty()) { |
158 // Unset the old user's GAIA info. | 162 // Unset the old user's GAIA info. |
159 cache.SetGAIANameOfProfileAtIndex(profile_index, string16()); | 163 cache.SetGAIANameOfProfileAtIndex(profile_index, string16()); |
| 164 // The profile index may have changed. |
| 165 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 166 if (profile_index == std::string::npos) |
| 167 return; |
160 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); | 168 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); |
| 169 // Unset the cached URL. |
| 170 profile_->GetPrefs()->ClearPref(prefs::kProfileGAIAInfoPictureURL); |
161 } else { | 171 } else { |
162 // Update the new user's GAIA info. | 172 // Update the new user's GAIA info. |
163 Update(); | 173 Update(); |
164 } | 174 } |
165 } | 175 } |
166 | 176 |
167 void GAIAInfoUpdateService::ScheduleNextUpdate() { | 177 void GAIAInfoUpdateService::ScheduleNextUpdate() { |
168 if (timer_.IsRunning()) | 178 if (timer_.IsRunning()) |
169 return; | 179 return; |
170 | 180 |
171 const base::TimeDelta desired_delta = | 181 const base::TimeDelta desired_delta = |
172 base::TimeDelta::FromHours(kUpdateIntervalHours); | 182 base::TimeDelta::FromHours(kUpdateIntervalHours); |
173 const base::TimeDelta update_delta = base::Time::Now() - last_updated_; | 183 const base::TimeDelta update_delta = base::Time::Now() - last_updated_; |
174 | 184 |
175 base::TimeDelta delta; | 185 base::TimeDelta delta; |
176 if (update_delta < base::TimeDelta() || update_delta > desired_delta) | 186 if (update_delta < base::TimeDelta() || update_delta > desired_delta) |
177 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); | 187 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); |
178 else | 188 else |
179 delta = desired_delta - update_delta; | 189 delta = desired_delta - update_delta; |
180 | 190 |
181 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); | 191 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); |
182 } | 192 } |
OLD | NEW |