| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return; | 124 return; |
| 125 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { | 125 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { |
| 126 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, | 126 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, |
| 127 picture_url); | 127 picture_url); |
| 128 gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(bitmap); | 128 gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(bitmap); |
| 129 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); | 129 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image); |
| 130 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { | 130 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { |
| 131 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); | 131 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // If this profile hasn't switched to using GAIA information for the profile | 134 // Order matters here for shortcut management, like in |
| 135 // name and picture then switch it now. Once the profile has switched this | 135 // ProfileShortcutManagerWin::OnProfileAdded, as the picture update does not |
| 136 // preference guards against clobbering the user's custom settings. | 136 // allow us to change the target, so we have to apply any renaming first. We |
| 137 if (!cache.GetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index)) { | 137 // also need to re-fetch the index, as changing the profile name may alter it. |
| 138 cache.SetHasMigratedToGAIAInfoOfProfileAtIndex(profile_index, true); | 138 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |
| 139 // Order matters here for shortcut management, like in | 139 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); |
| 140 // ProfileShortcutManagerWin::OnProfileAdded, as the picture update does not | |
| 141 // allow us to change the target, so we have to apply any renaming first. We | |
| 142 // also need to re-fetch the index, as SetIsUsingGAIANameOfProfileAtIndex | |
| 143 // may alter it. | |
| 144 cache.SetIsUsingGAIANameOfProfileAtIndex(profile_index, true); | |
| 145 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | |
| 146 cache.SetIsUsingGAIAPictureOfProfileAtIndex(profile_index, true); | |
| 147 } | |
| 148 } | 140 } |
| 149 | 141 |
| 150 void GAIAInfoUpdateService::OnProfileDownloadFailure( | 142 void GAIAInfoUpdateService::OnProfileDownloadFailure( |
| 151 ProfileDownloader* downloader, | 143 ProfileDownloader* downloader, |
| 152 ProfileDownloaderDelegate::FailureReason reason) { | 144 ProfileDownloaderDelegate::FailureReason reason) { |
| 153 profile_image_downloader_.reset(); | 145 profile_image_downloader_.reset(); |
| 154 | 146 |
| 155 // Save the last updated time. | 147 // Save the last updated time. |
| 156 last_updated_ = base::Time::Now(); | 148 last_updated_ = base::Time::Now(); |
| 157 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, | 149 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const base::TimeDelta update_delta = base::Time::Now() - last_updated_; | 185 const base::TimeDelta update_delta = base::Time::Now() - last_updated_; |
| 194 | 186 |
| 195 base::TimeDelta delta; | 187 base::TimeDelta delta; |
| 196 if (update_delta < base::TimeDelta() || update_delta > desired_delta) | 188 if (update_delta < base::TimeDelta() || update_delta > desired_delta) |
| 197 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); | 189 delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); |
| 198 else | 190 else |
| 199 delta = desired_delta - update_delta; | 191 delta = desired_delta - update_delta; |
| 200 | 192 |
| 201 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); | 193 timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); |
| 202 } | 194 } |
| OLD | NEW |