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

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