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 if (service) | |
Nicolas Zea
2015/02/26 21:46:47
I don't think this will catch the case where sync
| |
126 service->AddObserver(this); | |
127 else | |
128 PostLoadAndRemoveObservers(); | |
122 } | 129 } |
123 } else { | 130 } else { |
124 BrowserThread::PostTask( | 131 BrowserThread::PostTask( |
125 BrowserThread::FILE, FROM_HERE, | 132 BrowserThread::FILE, FROM_HERE, |
126 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 133 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
127 } | 134 } |
128 } | 135 } |
129 | 136 |
130 void ExternalPrefLoader::OnIsSyncingChanged() { | 137 void ExternalPrefLoader::OnIsSyncingChanged() { |
131 PostLoadIfPrioritySyncReady(); | 138 PostLoadIfPrioritySyncReady(); |
132 } | 139 } |
133 | 140 |
141 void ExternalPrefLoader::OnStateChanged() { | |
142 ProfileSyncService* service = | |
143 ProfileSyncServiceFactory::GetForProfile(profile_); | |
144 DCHECK(service); | |
145 | |
146 ProfileSyncService::SyncStatusSummary status = | |
147 service->QuerySyncStatusSummary(); | |
148 if (status == ProfileSyncService::SyncStatusSummary::NOT_ENABLED || | |
Nicolas Zea
2015/02/25 18:26:14
Do you have logic elsewhere to do the load when sy
Ivan Podogov
2015/02/26 12:50:15
The main idea is: if sync is enabled (and we don't
Nicolas Zea
2015/02/26 21:46:47
I'm a bit confused by this; I think we might be th
Ivan Podogov
2015/02/26 21:59:06
Um... These comments are for the old patchset, tak
| |
149 status == ProfileSyncService::SyncStatusSummary::UNRECOVERABLE_ERROR) { | |
150 PostLoadAndRemoveObservers(); | |
151 } | |
152 } | |
153 | |
134 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { | 154 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |
135 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); | 155 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |
136 DCHECK(profile_); | 156 DCHECK(profile_); |
137 | 157 |
138 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | 158 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
139 DCHECK(prefs); | 159 DCHECK(prefs); |
140 if (prefs->IsPrioritySyncing()) { | 160 if (prefs->IsPrioritySyncing()) { |
141 BrowserThread::PostTask( | 161 PostLoadAndRemoveObservers(); |
142 BrowserThread::FILE, FROM_HERE, | |
143 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
144 syncable_pref_observer_.Remove(prefs); | |
145 return true; | 162 return true; |
146 } | 163 } |
147 | 164 |
148 return false; | 165 return false; |
149 } | 166 } |
150 | 167 |
168 void ExternalPrefLoader::PostLoadAndRemoveObservers() { | |
169 BrowserThread::PostTask( | |
170 BrowserThread::FILE, FROM_HERE, | |
171 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
172 | |
173 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | |
174 DCHECK(prefs); | |
175 syncable_pref_observer_.Remove(prefs); | |
176 | |
177 ProfileSyncService* service = | |
178 ProfileSyncServiceFactory::GetForProfile(profile_); | |
179 if (service) | |
180 service->RemoveObserver(this); | |
181 } | |
182 | |
151 void ExternalPrefLoader::LoadOnFileThread() { | 183 void ExternalPrefLoader::LoadOnFileThread() { |
152 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 184 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
153 | 185 |
154 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 186 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
155 | 187 |
156 // TODO(skerner): Some values of base_path_id_ will cause | 188 // TODO(skerner): Some values of base_path_id_ will cause |
157 // PathService::Get() to return false, because the path does | 189 // PathService::Get() to return false, because the path does |
158 // not exist. Find and fix the build/install scripts so that | 190 // not exist. Find and fix the build/install scripts so that |
159 // this can become a CHECK(). Known examples include chrome | 191 // this can become a CHECK(). Known examples include chrome |
160 // OS developer builds and linux install packages. | 192 // OS developer builds and linux install packages. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 LoadFinished(); | 316 LoadFinished(); |
285 } | 317 } |
286 | 318 |
287 ExternalTestingLoader::~ExternalTestingLoader() {} | 319 ExternalTestingLoader::~ExternalTestingLoader() {} |
288 | 320 |
289 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 321 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
290 return fake_base_path_; | 322 return fake_base_path_; |
291 } | 323 } |
292 | 324 |
293 } // namespace extensions | 325 } // namespace extensions |
OLD | NEW |