| 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/extensions/external_pref_loader.h" |    5 #include "chrome/browser/extensions/external_pref_loader.h" | 
|    6  |    6  | 
|    7 #include <utility> |    7 #include <utility> | 
|    8  |    8  | 
|    9 #include "base/bind.h" |    9 #include "base/bind.h" | 
|   10 #include "base/files/file_enumerator.h" |   10 #include "base/files/file_enumerator.h" | 
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  126 void ExternalPrefLoader::StartLoading() { |  126 void ExternalPrefLoader::StartLoading() { | 
|  127   CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |  127   CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 
|  128   if ((options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) && |  128   if ((options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) && | 
|  129       (profile_ && profile_->IsSyncAllowed())) { |  129       (profile_ && profile_->IsSyncAllowed())) { | 
|  130     if (!PostLoadIfPrioritySyncReady()) { |  130     if (!PostLoadIfPrioritySyncReady()) { | 
|  131       DCHECK(profile_); |  131       DCHECK(profile_); | 
|  132       syncable_prefs::PrefServiceSyncable* prefs = |  132       syncable_prefs::PrefServiceSyncable* prefs = | 
|  133           PrefServiceSyncableFromProfile(profile_); |  133           PrefServiceSyncableFromProfile(profile_); | 
|  134       DCHECK(prefs); |  134       DCHECK(prefs); | 
|  135       syncable_pref_observer_.Add(prefs); |  135       syncable_pref_observer_.Add(prefs); | 
|  136       ProfileSyncService* service = |  136       browser_sync::ProfileSyncService* service = | 
|  137           ProfileSyncServiceFactory::GetForProfile(profile_); |  137           ProfileSyncServiceFactory::GetForProfile(profile_); | 
|  138       DCHECK(service); |  138       DCHECK(service); | 
|  139       if (service->CanSyncStart() && (service->IsFirstSetupComplete() || |  139       if (service->CanSyncStart() && (service->IsFirstSetupComplete() || | 
|  140                                       browser_defaults::kSyncAutoStarts)) { |  140                                       browser_defaults::kSyncAutoStarts)) { | 
|  141         service->AddObserver(this); |  141         service->AddObserver(this); | 
|  142       } else { |  142       } else { | 
|  143         PostLoadAndRemoveObservers(); |  143         PostLoadAndRemoveObservers(); | 
|  144       } |  144       } | 
|  145     } |  145     } | 
|  146   } else { |  146   } else { | 
|  147     BrowserThread::PostTask( |  147     BrowserThread::PostTask( | 
|  148         BrowserThread::FILE, FROM_HERE, |  148         BrowserThread::FILE, FROM_HERE, | 
|  149         base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |  149         base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 
|  150   } |  150   } | 
|  151 } |  151 } | 
|  152  |  152  | 
|  153 void ExternalPrefLoader::OnIsSyncingChanged() { |  153 void ExternalPrefLoader::OnIsSyncingChanged() { | 
|  154   PostLoadIfPrioritySyncReady(); |  154   PostLoadIfPrioritySyncReady(); | 
|  155 } |  155 } | 
|  156  |  156  | 
|  157 void ExternalPrefLoader::OnStateChanged() { |  157 void ExternalPrefLoader::OnStateChanged() { | 
|  158   ProfileSyncService* service = |  158   browser_sync::ProfileSyncService* service = | 
|  159       ProfileSyncServiceFactory::GetForProfile(profile_); |  159       ProfileSyncServiceFactory::GetForProfile(profile_); | 
|  160   DCHECK(service); |  160   DCHECK(service); | 
|  161   if (!service->CanSyncStart()) { |  161   if (!service->CanSyncStart()) { | 
|  162     PostLoadAndRemoveObservers(); |  162     PostLoadAndRemoveObservers(); | 
|  163   } |  163   } | 
|  164 } |  164 } | 
|  165  |  165  | 
|  166 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |  166 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { | 
|  167   DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |  167   DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); | 
|  168   DCHECK(profile_); |  168   DCHECK(profile_); | 
|  169  |  169  | 
|  170   syncable_prefs::PrefServiceSyncable* prefs = |  170   syncable_prefs::PrefServiceSyncable* prefs = | 
|  171       PrefServiceSyncableFromProfile(profile_); |  171       PrefServiceSyncableFromProfile(profile_); | 
|  172   DCHECK(prefs); |  172   DCHECK(prefs); | 
|  173   if (prefs->IsPrioritySyncing()) { |  173   if (prefs->IsPrioritySyncing()) { | 
|  174     PostLoadAndRemoveObservers(); |  174     PostLoadAndRemoveObservers(); | 
|  175     return true; |  175     return true; | 
|  176   } |  176   } | 
|  177  |  177  | 
|  178   return false; |  178   return false; | 
|  179 } |  179 } | 
|  180  |  180  | 
|  181 void ExternalPrefLoader::PostLoadAndRemoveObservers() { |  181 void ExternalPrefLoader::PostLoadAndRemoveObservers() { | 
|  182   syncable_prefs::PrefServiceSyncable* prefs = |  182   syncable_prefs::PrefServiceSyncable* prefs = | 
|  183       PrefServiceSyncableFromProfile(profile_); |  183       PrefServiceSyncableFromProfile(profile_); | 
|  184   DCHECK(prefs); |  184   DCHECK(prefs); | 
|  185   syncable_pref_observer_.Remove(prefs); |  185   syncable_pref_observer_.Remove(prefs); | 
|  186  |  186  | 
|  187   ProfileSyncService* service = |  187   browser_sync::ProfileSyncService* service = | 
|  188       ProfileSyncServiceFactory::GetForProfile(profile_); |  188       ProfileSyncServiceFactory::GetForProfile(profile_); | 
|  189   DCHECK(service); |  189   DCHECK(service); | 
|  190   service->RemoveObserver(this); |  190   service->RemoveObserver(this); | 
|  191  |  191  | 
|  192   BrowserThread::PostTask( |  192   BrowserThread::PostTask( | 
|  193       BrowserThread::FILE, FROM_HERE, |  193       BrowserThread::FILE, FROM_HERE, | 
|  194       base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |  194       base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 
|  195 } |  195 } | 
|  196  |  196  | 
|  197 void ExternalPrefLoader::LoadOnFileThread() { |  197 void ExternalPrefLoader::LoadOnFileThread() { | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  330   LoadFinished(); |  330   LoadFinished(); | 
|  331 } |  331 } | 
|  332  |  332  | 
|  333 ExternalTestingLoader::~ExternalTestingLoader() {} |  333 ExternalTestingLoader::~ExternalTestingLoader() {} | 
|  334  |  334  | 
|  335 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |  335 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 
|  336   return fake_base_path_; |  336   return fake_base_path_; | 
|  337 } |  337 } | 
|  338  |  338  | 
|  339 }  // namespace extensions |  339 }  // namespace extensions | 
| OLD | NEW |