Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: chrome/browser/extensions/external_pref_loader.cc

Issue 957753002: Install default apps if sync is disabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Check both states. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_);
Andrew T Wilson (Slow) 2015/02/25 14:47:31 You can't depend on ProfileSyncService existing, a
Ivan Podogov 2015/02/25 16:34:14 Funny thing is, IsSyncAccessible() call would also
Andrew T Wilson (Slow) 2015/02/25 17:47:22 If you find those, please file bugs. These regress
Ivan Podogov 2015/02/26 12:50:14 My bad, I mistook somethig: profile was nullptr, a
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 ProfileSyncService::SyncStatusSummary status =
145 service->QuerySyncStatusSummary();
146 if (status == ProfileSyncService::SyncStatusSummary::NOT_ENABLED ||
147 status == ProfileSyncService::SyncStatusSummary::UNRECOVERABLE_ERROR) {
Andrew T Wilson (Slow) 2015/02/25 14:47:31 Not sure if perhaps you should be checking for UNK
Ivan Podogov 2015/02/25 16:34:14 UNKNOWN_ERROR corresponds to some state that even
Andrew T Wilson (Slow) 2015/02/25 17:47:21 What I want to make sure is we aren't left in a st
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 BrowserThread::PostTask(
168 BrowserThread::FILE, FROM_HERE,
169 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this));
170
171 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_);
172 DCHECK(prefs);
173 syncable_pref_observer_.Remove(prefs);
174
175 ProfileSyncService* service =
176 ProfileSyncServiceFactory::GetForProfile(profile_);
177 DCHECK(service);
178 service->RemoveObserver(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
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
OLDNEW
« no previous file with comments | « chrome/browser/extensions/external_pref_loader.h ('k') | chrome/browser/extensions/external_provider_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698