Chromium Code Reviews| 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/prefs/pref_service_syncable.h" | 18 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 19 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 base::FilePath::CharType kExternalExtensionJson[] = | 27 base::FilePath::CharType kExternalExtensionJson[] = |
| 27 FILE_PATH_LITERAL("external_extensions.json"); | 28 FILE_PATH_LITERAL("external_extensions.json"); |
| 28 | 29 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 107 |
| 107 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { | 108 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { |
| 108 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 109 | 110 |
| 110 // |base_path_| was set in LoadOnFileThread(). | 111 // |base_path_| was set in LoadOnFileThread(). |
| 111 return base_path_; | 112 return base_path_; |
| 112 } | 113 } |
| 113 | 114 |
| 114 void ExternalPrefLoader::StartLoading() { | 115 void ExternalPrefLoader::StartLoading() { |
| 115 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 116 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 116 if (options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) { | 117 if ((options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) && |
| 118 (profile_ && profile_->IsSyncAccessible())) { | |
| 117 if (!PostLoadIfPrioritySyncReady()) { | 119 if (!PostLoadIfPrioritySyncReady()) { |
| 118 DCHECK(profile_); | 120 DCHECK(profile_); |
| 119 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 121 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
| 120 DCHECK(prefs); | 122 DCHECK(prefs); |
| 121 syncable_pref_observer_.Add(prefs); | 123 syncable_pref_observer_.Add(prefs); |
| 124 ProfileSyncService* service = | |
| 125 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 126 DCHECK(service); | |
| 127 if (service->IsSyncEnabledAndLoggedIn()) | |
|
Nicolas Zea
2015/02/27 19:25:00
Is this code only running in ChromeOS? if so, this
Ivan Podogov
2015/03/02 07:46:43
I'm not really sure of where this code may run, bu
| |
| 128 service->AddObserver(this); | |
| 129 else | |
| 130 PostLoadAndRemoveObservers(); | |
| 122 } | 131 } |
| 123 } else { | 132 } else { |
| 124 BrowserThread::PostTask( | 133 BrowserThread::PostTask( |
| 125 BrowserThread::FILE, FROM_HERE, | 134 BrowserThread::FILE, FROM_HERE, |
| 126 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 135 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
| 127 } | 136 } |
| 128 } | 137 } |
| 129 | 138 |
| 130 void ExternalPrefLoader::OnIsSyncingChanged() { | 139 void ExternalPrefLoader::OnIsSyncingChanged() { |
| 131 PostLoadIfPrioritySyncReady(); | 140 PostLoadIfPrioritySyncReady(); |
| 132 } | 141 } |
| 133 | 142 |
| 143 void ExternalPrefLoader::OnStateChanged() { | |
| 144 ProfileSyncService* service = | |
| 145 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 146 DCHECK(service); | |
| 147 if (!service->IsSyncEnabledAndLoggedIn()) { | |
| 148 PostLoadAndRemoveObservers(); | |
| 149 } | |
| 150 } | |
| 151 | |
| 134 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { | 152 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |
| 135 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); | 153 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |
| 136 DCHECK(profile_); | 154 DCHECK(profile_); |
| 137 | 155 |
| 138 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 156 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
| 139 DCHECK(prefs); | 157 DCHECK(prefs); |
| 140 if (prefs->IsPrioritySyncing()) { | 158 if (prefs->IsPrioritySyncing()) { |
| 141 BrowserThread::PostTask( | 159 PostLoadAndRemoveObservers(); |
| 142 BrowserThread::FILE, FROM_HERE, | |
| 143 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
| 144 syncable_pref_observer_.Remove(prefs); | |
| 145 return true; | 160 return true; |
| 146 } | 161 } |
| 147 | 162 |
| 148 return false; | 163 return false; |
| 149 } | 164 } |
| 150 | 165 |
| 166 void ExternalPrefLoader::PostLoadAndRemoveObservers() { | |
| 167 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | |
| 168 DCHECK(prefs); | |
| 169 syncable_pref_observer_.Remove(prefs); | |
| 170 | |
| 171 ProfileSyncService* service = | |
| 172 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 173 DCHECK(service); | |
| 174 service->RemoveObserver(this); | |
| 175 | |
| 176 BrowserThread::PostTask( | |
| 177 BrowserThread::FILE, FROM_HERE, | |
| 178 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
| 179 } | |
| 180 | |
| 151 void ExternalPrefLoader::LoadOnFileThread() { | 181 void ExternalPrefLoader::LoadOnFileThread() { |
| 152 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 182 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 153 | 183 |
| 154 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 184 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 155 | 185 |
| 156 // TODO(skerner): Some values of base_path_id_ will cause | 186 // TODO(skerner): Some values of base_path_id_ will cause |
| 157 // PathService::Get() to return false, because the path does | 187 // PathService::Get() to return false, because the path does |
| 158 // not exist. Find and fix the build/install scripts so that | 188 // not exist. Find and fix the build/install scripts so that |
| 159 // this can become a CHECK(). Known examples include chrome | 189 // this can become a CHECK(). Known examples include chrome |
| 160 // OS developer builds and linux install packages. | 190 // OS developer builds and linux install packages. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 LoadFinished(); | 314 LoadFinished(); |
| 285 } | 315 } |
| 286 | 316 |
| 287 ExternalTestingLoader::~ExternalTestingLoader() {} | 317 ExternalTestingLoader::~ExternalTestingLoader() {} |
| 288 | 318 |
| 289 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 319 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
| 290 return fake_base_path_; | 320 return fake_base_path_; |
| 291 } | 321 } |
| 292 | 322 |
| 293 } // namespace extensions | 323 } // namespace extensions |
| OLD | NEW |