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

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

Issue 1913373002: Revert "Refactor ProfileInfoCache in most of c/b/profiles" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 (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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/profiles/profile_attributes_entry.h" 14 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_attributes_storage.h"
16 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/profiles/profile_metrics.h" 16 #include "chrome/browser/profiles/profile_metrics.h"
18 #include "chrome/browser/profiles/profiles_state.h" 17 #include "chrome/browser/profiles/profiles_state.h"
19 #include "chrome/browser/signin/signin_manager_factory.h" 18 #include "chrome/browser/signin/signin_manager_factory.h"
20 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
21 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
22 #include "components/signin/core/common/profile_management_switches.h" 21 #include "components/signin/core/common/profile_management_switches.h"
23 #include "components/signin/core/common/signin_pref_names.h" 22 #include "components/signin/core/common/signin_pref_names.h"
24 #include "content/public/browser/notification_details.h" 23 #include "content/public/browser/notification_details.h"
25 #include "third_party/skia/include/core/SkBitmap.h" 24 #include "third_party/skia/include/core/SkBitmap.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 last_updated_.ToInternalValue()); 113 last_updated_.ToInternalValue());
115 ScheduleNextUpdate(); 114 ScheduleNextUpdate();
116 115
117 base::string16 full_name = downloader->GetProfileFullName(); 116 base::string16 full_name = downloader->GetProfileFullName();
118 base::string16 given_name = downloader->GetProfileGivenName(); 117 base::string16 given_name = downloader->GetProfileGivenName();
119 SkBitmap bitmap = downloader->GetProfilePicture(); 118 SkBitmap bitmap = downloader->GetProfilePicture();
120 ProfileDownloader::PictureStatus picture_status = 119 ProfileDownloader::PictureStatus picture_status =
121 downloader->GetProfilePictureStatus(); 120 downloader->GetProfilePictureStatus();
122 std::string picture_url = downloader->GetProfilePictureURL(); 121 std::string picture_url = downloader->GetProfilePictureURL();
123 122
124 ProfileAttributesEntry* entry; 123 ProfileInfoCache& cache =
125 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). 124 g_browser_process->profile_manager()->GetProfileInfoCache();
126 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { 125 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
126 if (profile_index == std::string::npos)
127 return; 127 return;
128 }
129 128
130 entry->SetGAIAName(full_name); 129 cache.SetGAIANameOfProfileAtIndex(profile_index, full_name);
131 entry->SetGAIAGivenName(given_name); 130 // The profile index may have changed.
131 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
132 DCHECK_NE(profile_index, std::string::npos);
133
134 cache.SetGAIAGivenNameOfProfileAtIndex(profile_index, given_name);
135 // The profile index may have changed.
136 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
137 DCHECK_NE(profile_index, std::string::npos);
132 138
133 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) { 139 if (picture_status == ProfileDownloader::PICTURE_SUCCESS) {
134 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL, 140 profile_->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL,
135 picture_url); 141 picture_url);
136 gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(bitmap); 142 gfx::Image gfx_image = gfx::Image::CreateFrom1xBitmap(bitmap);
137 entry->SetGAIAPicture(&gfx_image); 143 cache.SetGAIAPictureOfProfileAtIndex(profile_index, &gfx_image);
138 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) { 144 } else if (picture_status == ProfileDownloader::PICTURE_DEFAULT) {
139 entry->SetGAIAPicture(nullptr); 145 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL);
140 } 146 }
141 147
142 const base::string16 hosted_domain = downloader->GetProfileHostedDomain(); 148 const base::string16 hosted_domain = downloader->GetProfileHostedDomain();
143 profile_->GetPrefs()->SetString(prefs::kGoogleServicesHostedDomain, 149 profile_->GetPrefs()->SetString(prefs::kGoogleServicesHostedDomain,
144 (hosted_domain.empty() ? Profile::kNoHostedDomainFound : 150 (hosted_domain.empty() ? Profile::kNoHostedDomainFound :
145 base::UTF16ToUTF8(hosted_domain))); 151 base::UTF16ToUTF8(hosted_domain)));
146 } 152 }
147 153
148 void GAIAInfoUpdateService::OnProfileDownloadFailure( 154 void GAIAInfoUpdateService::OnProfileDownloadFailure(
149 ProfileDownloader* downloader, 155 ProfileDownloader* downloader,
150 ProfileDownloaderDelegate::FailureReason reason) { 156 ProfileDownloaderDelegate::FailureReason reason) {
151 profile_image_downloader_.reset(); 157 profile_image_downloader_.reset();
152 158
153 // Save the last updated time. 159 // Save the last updated time.
154 last_updated_ = base::Time::Now(); 160 last_updated_ = base::Time::Now();
155 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, 161 profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime,
156 last_updated_.ToInternalValue()); 162 last_updated_.ToInternalValue());
157 ScheduleNextUpdate(); 163 ScheduleNextUpdate();
158 } 164 }
159 165
160 void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) { 166 void GAIAInfoUpdateService::OnUsernameChanged(const std::string& username) {
161 ProfileAttributesEntry* entry; 167 ProfileInfoCache& cache =
162 if (!g_browser_process->profile_manager()->GetProfileAttributesStorage(). 168 g_browser_process->profile_manager()->GetProfileInfoCache();
163 GetProfileAttributesWithPath(profile_->GetPath(), &entry)) { 169 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
170 if (profile_index == std::string::npos)
164 return; 171 return;
165 }
166 172
167 if (username.empty()) { 173 if (username.empty()) {
168 // Unset the old user's GAIA info. 174 // Unset the old user's GAIA info.
169 entry->SetGAIAName(base::string16()); 175 cache.SetGAIANameOfProfileAtIndex(profile_index, base::string16());
170 entry->SetGAIAGivenName(base::string16()); 176 cache.SetGAIAGivenNameOfProfileAtIndex(profile_index, base::string16());
171 entry->SetGAIAPicture(nullptr); 177 // The profile index may have changed.
178 profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath());
179 if (profile_index == std::string::npos)
180 return;
181 cache.SetGAIAPictureOfProfileAtIndex(profile_index, NULL);
172 // Unset the cached URL. 182 // Unset the cached URL.
173 profile_->GetPrefs()->ClearPref(prefs::kProfileGAIAInfoPictureURL); 183 profile_->GetPrefs()->ClearPref(prefs::kProfileGAIAInfoPictureURL);
174 } else { 184 } else {
175 // Update the new user's GAIA info. 185 // Update the new user's GAIA info.
176 Update(); 186 Update();
177 } 187 }
178 } 188 }
179 189
180 void GAIAInfoUpdateService::Shutdown() { 190 void GAIAInfoUpdateService::Shutdown() {
181 timer_.Stop(); 191 timer_.Stop();
182 profile_image_downloader_.reset(); 192 profile_image_downloader_.reset();
183 SigninManagerBase* signin_manager = 193 SigninManagerBase* signin_manager =
184 SigninManagerFactory::GetForProfile(profile_); 194 SigninManagerFactory::GetForProfile(profile_);
185 signin_manager->RemoveObserver(this); 195 signin_manager->RemoveObserver(this);
186 196
187 // OK to reset |profile_| pointer here because GAIAInfoUpdateService will not 197 // OK to reset |profile_| pointer here because GAIAInfoUpdateService will not
188 // access it again. This pointer is also used to implement the delegate for 198 // access it again. This pointer is also used to implement the delegate for
189 // |profile_image_downloader_|. However that object was destroyed above. 199 // |profile_image_downloader_|. However that object was destroyed above.
190 profile_ = nullptr; 200 profile_ = NULL;
191 } 201 }
192 202
193 void GAIAInfoUpdateService::ScheduleNextUpdate() { 203 void GAIAInfoUpdateService::ScheduleNextUpdate() {
194 if (timer_.IsRunning()) 204 if (timer_.IsRunning())
195 return; 205 return;
196 206
197 const base::TimeDelta desired_delta = 207 const base::TimeDelta desired_delta =
198 base::TimeDelta::FromHours(kUpdateIntervalHours); 208 base::TimeDelta::FromHours(kUpdateIntervalHours);
199 const base::TimeDelta update_delta = base::Time::Now() - last_updated_; 209 const base::TimeDelta update_delta = base::Time::Now() - last_updated_;
200 210
(...skipping 10 matching lines...) Expand all
211 const std::string& account_id, 221 const std::string& account_id,
212 const std::string& username, 222 const std::string& username,
213 const std::string& password) { 223 const std::string& password) {
214 OnUsernameChanged(username); 224 OnUsernameChanged(username);
215 } 225 }
216 226
217 void GAIAInfoUpdateService::GoogleSignedOut(const std::string& account_id, 227 void GAIAInfoUpdateService::GoogleSignedOut(const std::string& account_id,
218 const std::string& username) { 228 const std::string& username) {
219 OnUsernameChanged(std::string()); 229 OnUsernameChanged(std::string());
220 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698