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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { |
117 if (!PostLoadIfPrioritySyncReady()) { | 118 if (!PostLoadIfPrioritySyncReady()) { |
118 DCHECK(profile_); | 119 DCHECK(profile_); |
119 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 120 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
120 DCHECK(prefs); | 121 DCHECK(prefs); |
121 syncable_pref_observer_.Add(prefs); | 122 syncable_pref_observer_.Add(prefs); |
123 ProfileSyncService* service = | |
124 ProfileSyncServiceFactory::GetForProfile(profile_); | |
125 DCHECK(service); | |
126 service->AddObserver(this); | |
122 } | 127 } |
123 } else { | 128 } else { |
124 BrowserThread::PostTask( | 129 BrowserThread::PostTask( |
125 BrowserThread::FILE, FROM_HERE, | 130 BrowserThread::FILE, FROM_HERE, |
126 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 131 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
127 } | 132 } |
128 } | 133 } |
129 | 134 |
130 void ExternalPrefLoader::OnIsSyncingChanged() { | 135 void ExternalPrefLoader::OnIsSyncingChanged() { |
131 PostLoadIfPrioritySyncReady(); | 136 PostLoadIfPrioritySyncReady(); |
132 } | 137 } |
133 | 138 |
139 void ExternalPrefLoader::OnStateChanged() { | |
140 ProfileSyncService* service = | |
141 ProfileSyncServiceFactory::GetForProfile(profile_); | |
142 DCHECK(service); | |
143 | |
144 if (service->QuerySyncStatusSummary() == | |
145 ProfileSyncService::SyncStatusSummary::NOT_ENABLED) { | |
Dmitry Polukhin
2015/02/25 13:39:11
I would also do the same in case of unrecoverable
Ivan Podogov
2015/02/25 13:45:58
Done.
| |
146 PostLoadAndRemoveObservers(); | |
147 } | |
148 } | |
149 | |
134 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { | 150 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |
135 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); | 151 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |
136 DCHECK(profile_); | 152 DCHECK(profile_); |
137 | 153 |
138 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 154 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
139 DCHECK(prefs); | 155 DCHECK(prefs); |
140 if (prefs->IsPrioritySyncing()) { | 156 if (prefs->IsPrioritySyncing()) { |
141 BrowserThread::PostTask( | 157 PostLoadAndRemoveObservers(); |
142 BrowserThread::FILE, FROM_HERE, | |
143 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
144 syncable_pref_observer_.Remove(prefs); | |
145 return true; | 158 return true; |
146 } | 159 } |
147 | 160 |
148 return false; | 161 return false; |
149 } | 162 } |
150 | 163 |
164 void ExternalPrefLoader::PostLoadAndRemoveObservers() { | |
165 BrowserThread::PostTask( | |
166 BrowserThread::FILE, FROM_HERE, | |
167 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
168 | |
169 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | |
170 DCHECK(prefs); | |
171 syncable_pref_observer_.Remove(prefs); | |
172 | |
173 ProfileSyncService* service = | |
174 ProfileSyncServiceFactory::GetForProfile(profile_); | |
175 DCHECK(service); | |
176 service->RemoveObserver(this); | |
177 } | |
178 | |
151 void ExternalPrefLoader::LoadOnFileThread() { | 179 void ExternalPrefLoader::LoadOnFileThread() { |
152 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 180 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
153 | 181 |
154 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 182 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
155 | 183 |
156 // TODO(skerner): Some values of base_path_id_ will cause | 184 // TODO(skerner): Some values of base_path_id_ will cause |
157 // PathService::Get() to return false, because the path does | 185 // PathService::Get() to return false, because the path does |
158 // not exist. Find and fix the build/install scripts so that | 186 // not exist. Find and fix the build/install scripts so that |
159 // this can become a CHECK(). Known examples include chrome | 187 // this can become a CHECK(). Known examples include chrome |
160 // OS developer builds and linux install packages. | 188 // OS developer builds and linux install packages. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 LoadFinished(); | 312 LoadFinished(); |
285 } | 313 } |
286 | 314 |
287 ExternalTestingLoader::~ExternalTestingLoader() {} | 315 ExternalTestingLoader::~ExternalTestingLoader() {} |
288 | 316 |
289 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 317 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
290 return fake_base_path_; | 318 return fake_base_path_; |
291 } | 319 } |
292 | 320 |
293 } // namespace extensions | 321 } // namespace extensions |
OLD | NEW |