| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_enumerator.h" | 8 #include "base/files/file_enumerator.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
| 12 #include "base/json/json_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
| 19 #include "chrome/browser/prefs/pref_service_syncable.h" | 19 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 20 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_factory.h" | 22 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 24 | 25 |
| 25 using content::BrowserThread; | 26 using content::BrowserThread; |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 base::FilePath::CharType kExternalExtensionJson[] = | 30 base::FilePath::CharType kExternalExtensionJson[] = |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 // |base_path_| was set in LoadOnFileThread(). | 115 // |base_path_| was set in LoadOnFileThread(). |
| 115 return base_path_; | 116 return base_path_; |
| 116 } | 117 } |
| 117 | 118 |
| 118 void ExternalPrefLoader::StartLoading() { | 119 void ExternalPrefLoader::StartLoading() { |
| 119 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 120 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 120 if ((options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) && | 121 if ((options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) && |
| 121 (profile_ && profile_->IsSyncAllowed())) { | 122 (profile_ && profile_->IsSyncAllowed())) { |
| 122 if (!PostLoadIfPrioritySyncReady()) { | 123 if (!PostLoadIfPrioritySyncReady()) { |
| 123 DCHECK(profile_); | 124 DCHECK(profile_); |
| 124 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 125 PrefServiceSyncable* prefs = PrefServiceSyncableFromProfile(profile_); |
| 125 DCHECK(prefs); | 126 DCHECK(prefs); |
| 126 syncable_pref_observer_.Add(prefs); | 127 syncable_pref_observer_.Add(prefs); |
| 127 ProfileSyncService* service = | 128 ProfileSyncService* service = |
| 128 ProfileSyncServiceFactory::GetForProfile(profile_); | 129 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 129 DCHECK(service); | 130 DCHECK(service); |
| 130 if (service->CanSyncStart() && | 131 if (service->CanSyncStart() && |
| 131 (service->HasSyncSetupCompleted() || | 132 (service->HasSyncSetupCompleted() || |
| 132 browser_defaults::kSyncAutoStarts)) { | 133 browser_defaults::kSyncAutoStarts)) { |
| 133 service->AddObserver(this); | 134 service->AddObserver(this); |
| 134 } else { | 135 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 152 DCHECK(service); | 153 DCHECK(service); |
| 153 if (!service->CanSyncStart()) { | 154 if (!service->CanSyncStart()) { |
| 154 PostLoadAndRemoveObservers(); | 155 PostLoadAndRemoveObservers(); |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 | 158 |
| 158 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { | 159 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |
| 159 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); | 160 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |
| 160 DCHECK(profile_); | 161 DCHECK(profile_); |
| 161 | 162 |
| 162 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 163 PrefServiceSyncable* prefs = PrefServiceSyncableFromProfile(profile_); |
| 163 DCHECK(prefs); | 164 DCHECK(prefs); |
| 164 if (prefs->IsPrioritySyncing()) { | 165 if (prefs->IsPrioritySyncing()) { |
| 165 PostLoadAndRemoveObservers(); | 166 PostLoadAndRemoveObservers(); |
| 166 return true; | 167 return true; |
| 167 } | 168 } |
| 168 | 169 |
| 169 return false; | 170 return false; |
| 170 } | 171 } |
| 171 | 172 |
| 172 void ExternalPrefLoader::PostLoadAndRemoveObservers() { | 173 void ExternalPrefLoader::PostLoadAndRemoveObservers() { |
| 173 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 174 PrefServiceSyncable* prefs = PrefServiceSyncableFromProfile(profile_); |
| 174 DCHECK(prefs); | 175 DCHECK(prefs); |
| 175 syncable_pref_observer_.Remove(prefs); | 176 syncable_pref_observer_.Remove(prefs); |
| 176 | 177 |
| 177 ProfileSyncService* service = | 178 ProfileSyncService* service = |
| 178 ProfileSyncServiceFactory::GetForProfile(profile_); | 179 ProfileSyncServiceFactory::GetForProfile(profile_); |
| 179 DCHECK(service); | 180 DCHECK(service); |
| 180 service->RemoveObserver(this); | 181 service->RemoveObserver(this); |
| 181 | 182 |
| 182 BrowserThread::PostTask( | 183 BrowserThread::PostTask( |
| 183 BrowserThread::FILE, FROM_HERE, | 184 BrowserThread::FILE, FROM_HERE, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 LoadFinished(); | 321 LoadFinished(); |
| 321 } | 322 } |
| 322 | 323 |
| 323 ExternalTestingLoader::~ExternalTestingLoader() {} | 324 ExternalTestingLoader::~ExternalTestingLoader() {} |
| 324 | 325 |
| 325 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 326 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
| 326 return fake_base_path_; | 327 return fake_base_path_; |
| 327 } | 328 } |
| 328 | 329 |
| 329 } // namespace extensions | 330 } // namespace extensions |
| OLD | NEW |