| 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/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 14 matching lines...) Expand all  Loading... | 
|   25  |   25  | 
|   26 // If the users's GAIA info is very out of date then wait at least this long |   26 // If the users's GAIA info is very out of date then wait at least this long | 
|   27 // before starting an update. This avoids slowdown during startup. |   27 // before starting an update. This avoids slowdown during startup. | 
|   28 const int kMinUpdateIntervalSeconds = 5; |   28 const int kMinUpdateIntervalSeconds = 5; | 
|   29  |   29  | 
|   30 } // namespace |   30 } // namespace | 
|   31  |   31  | 
|   32 GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile) |   32 GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile) | 
|   33     : profile_(profile) { |   33     : profile_(profile) { | 
|   34   PrefService* prefs = profile_->GetPrefs(); |   34   PrefService* prefs = profile_->GetPrefs(); | 
|   35   username_pref_.Init(prefs::kGoogleServicesUsername, prefs, this); |   35   username_pref_.Init(prefs::kGoogleServicesUsername, prefs, | 
 |   36                       base::Bind(&GAIAInfoUpdateService::OnUsernameChanged, | 
 |   37                                  base::Unretained(this))); | 
|   36  |   38  | 
|   37   last_updated_ = base::Time::FromInternalValue( |   39   last_updated_ = base::Time::FromInternalValue( | 
|   38       prefs->GetInt64(prefs::kProfileGAIAInfoUpdateTime)); |   40       prefs->GetInt64(prefs::kProfileGAIAInfoUpdateTime)); | 
|   39   ScheduleNextUpdate(); |   41   ScheduleNextUpdate(); | 
|   40 } |   42 } | 
|   41  |   43  | 
|   42 GAIAInfoUpdateService::~GAIAInfoUpdateService() { |   44 GAIAInfoUpdateService::~GAIAInfoUpdateService() { | 
|   43 } |   45 } | 
|   44  |   46  | 
|   45 void GAIAInfoUpdateService::Update() { |   47 void GAIAInfoUpdateService::Update() { | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  157     ProfileDownloader* downloader) { |  159     ProfileDownloader* downloader) { | 
|  158   profile_image_downloader_.reset(); |  160   profile_image_downloader_.reset(); | 
|  159  |  161  | 
|  160   // Save the last updated time. |  162   // Save the last updated time. | 
|  161   last_updated_ = base::Time::Now(); |  163   last_updated_ = base::Time::Now(); | 
|  162   profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, |  164   profile_->GetPrefs()->SetInt64(prefs::kProfileGAIAInfoUpdateTime, | 
|  163                                  last_updated_.ToInternalValue()); |  165                                  last_updated_.ToInternalValue()); | 
|  164   ScheduleNextUpdate(); |  166   ScheduleNextUpdate(); | 
|  165 } |  167 } | 
|  166  |  168  | 
|  167 void GAIAInfoUpdateService::OnPreferenceChanged(PrefServiceBase* service, |  | 
|  168                                                 const std::string& pref_name) { |  | 
|  169   if (prefs::kGoogleServicesUsername == pref_name) |  | 
|  170     OnUsernameChanged(); |  | 
|  171 } |  | 
|  172  |  | 
|  173 void GAIAInfoUpdateService::OnUsernameChanged() { |  169 void GAIAInfoUpdateService::OnUsernameChanged() { | 
|  174   ProfileInfoCache& cache = |  170   ProfileInfoCache& cache = | 
|  175       g_browser_process->profile_manager()->GetProfileInfoCache(); |  171       g_browser_process->profile_manager()->GetProfileInfoCache(); | 
|  176   size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); |  172   size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); | 
|  177   if (profile_index == std::string::npos) |  173   if (profile_index == std::string::npos) | 
|  178     return; |  174     return; | 
|  179  |  175  | 
|  180   std::string username = profile_->GetPrefs()->GetString( |  176   std::string username = profile_->GetPrefs()->GetString( | 
|  181       prefs::kGoogleServicesUsername); |  177       prefs::kGoogleServicesUsername); | 
|  182   if (username.empty()) { |  178   if (username.empty()) { | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
|  204   const base::TimeDelta update_delta = base::Time::Now() - last_updated_; |  200   const base::TimeDelta update_delta = base::Time::Now() - last_updated_; | 
|  205  |  201  | 
|  206   base::TimeDelta delta; |  202   base::TimeDelta delta; | 
|  207   if (update_delta < base::TimeDelta() || update_delta > desired_delta) |  203   if (update_delta < base::TimeDelta() || update_delta > desired_delta) | 
|  208     delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); |  204     delta = base::TimeDelta::FromSeconds(kMinUpdateIntervalSeconds); | 
|  209   else |  205   else | 
|  210     delta = desired_delta - update_delta; |  206     delta = desired_delta - update_delta; | 
|  211  |  207  | 
|  212   timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); |  208   timer_.Start(FROM_HERE, delta, this, &GAIAInfoUpdateService::Update); | 
|  213 } |  209 } | 
| OLD | NEW |