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 service->AddObserver(this); | |
|
Nicolas Zea
2015/02/26 22:03:47
You're still signing up for events that may never
Ivan Podogov
2015/02/27 08:47:17
You wrote: "This is where I think you should be ch
| |
| 122 } | 128 } |
| 123 } else { | 129 } else { |
| 124 BrowserThread::PostTask( | 130 BrowserThread::PostTask( |
| 125 BrowserThread::FILE, FROM_HERE, | 131 BrowserThread::FILE, FROM_HERE, |
| 126 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 132 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
| 127 } | 133 } |
| 128 } | 134 } |
| 129 | 135 |
| 130 void ExternalPrefLoader::OnIsSyncingChanged() { | 136 void ExternalPrefLoader::OnIsSyncingChanged() { |
| 131 PostLoadIfPrioritySyncReady(); | 137 PostLoadIfPrioritySyncReady(); |
| 132 } | 138 } |
| 133 | 139 |
| 140 void ExternalPrefLoader::OnStateChanged() { | |
| 141 ProfileSyncService* service = | |
| 142 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 143 DCHECK(service); | |
| 144 if (!service->IsSyncEnabledAndLoggedIn()) { | |
| 145 PostLoadAndRemoveObservers(); | |
| 146 } | |
| 147 } | |
| 148 | |
| 134 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { | 149 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |
| 135 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); | 150 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |
| 136 DCHECK(profile_); | 151 DCHECK(profile_); |
| 137 | 152 |
| 138 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 153 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
| 139 DCHECK(prefs); | 154 DCHECK(prefs); |
| 140 if (prefs->IsPrioritySyncing()) { | 155 if (prefs->IsPrioritySyncing()) { |
| 141 BrowserThread::PostTask( | 156 PostLoadAndRemoveObservers(); |
| 142 BrowserThread::FILE, FROM_HERE, | |
| 143 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
| 144 syncable_pref_observer_.Remove(prefs); | |
| 145 return true; | 157 return true; |
| 146 } | 158 } |
| 147 | 159 |
| 148 return false; | 160 return false; |
| 149 } | 161 } |
| 150 | 162 |
| 163 void ExternalPrefLoader::PostLoadAndRemoveObservers() { | |
| 164 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | |
| 165 DCHECK(prefs); | |
| 166 syncable_pref_observer_.Remove(prefs); | |
| 167 | |
| 168 ProfileSyncService* service = | |
| 169 ProfileSyncServiceFactory::GetForProfile(profile_); | |
| 170 DCHECK(service); | |
| 171 service->RemoveObserver(this); | |
| 172 | |
| 173 BrowserThread::PostTask( | |
| 174 BrowserThread::FILE, FROM_HERE, | |
| 175 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
| 176 } | |
| 177 | |
| 151 void ExternalPrefLoader::LoadOnFileThread() { | 178 void ExternalPrefLoader::LoadOnFileThread() { |
| 152 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 179 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 153 | 180 |
| 154 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 181 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 155 | 182 |
| 156 // TODO(skerner): Some values of base_path_id_ will cause | 183 // TODO(skerner): Some values of base_path_id_ will cause |
| 157 // PathService::Get() to return false, because the path does | 184 // PathService::Get() to return false, because the path does |
| 158 // not exist. Find and fix the build/install scripts so that | 185 // not exist. Find and fix the build/install scripts so that |
| 159 // this can become a CHECK(). Known examples include chrome | 186 // this can become a CHECK(). Known examples include chrome |
| 160 // OS developer builds and linux install packages. | 187 // OS developer builds and linux install packages. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 LoadFinished(); | 311 LoadFinished(); |
| 285 } | 312 } |
| 286 | 313 |
| 287 ExternalTestingLoader::~ExternalTestingLoader() {} | 314 ExternalTestingLoader::~ExternalTestingLoader() {} |
| 288 | 315 |
| 289 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 316 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
| 290 return fake_base_path_; | 317 return fake_base_path_; |
| 291 } | 318 } |
| 292 | 319 |
| 293 } // namespace extensions | 320 } // namespace extensions |
| OLD | NEW |