| 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/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 | 21 |
| 21 using content::BrowserThread; | 22 using content::BrowserThread; |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 base::FilePath::CharType kExternalExtensionJson[] = | 26 base::FilePath::CharType kExternalExtensionJson[] = |
| 26 FILE_PATH_LITERAL("external_extensions.json"); | 27 FILE_PATH_LITERAL("external_extensions.json"); |
| 27 | 28 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 84 |
| 84 LOG(WARNING) << "Expected a JSON dictionary in file " | 85 LOG(WARNING) << "Expected a JSON dictionary in file " |
| 85 << path.value() << "."; | 86 << path.value() << "."; |
| 86 return new base::DictionaryValue; | 87 return new base::DictionaryValue; |
| 87 } | 88 } |
| 88 | 89 |
| 89 } // namespace | 90 } // namespace |
| 90 | 91 |
| 91 namespace extensions { | 92 namespace extensions { |
| 92 | 93 |
| 93 ExternalPrefLoader::ExternalPrefLoader(int base_path_id, Options options) | 94 ExternalPrefLoader::ExternalPrefLoader(int base_path_id, |
| 94 : base_path_id_(base_path_id), options_(options) { | 95 Options options, |
| 96 Profile* profile) |
| 97 : base_path_id_(base_path_id), |
| 98 options_(options), |
| 99 profile_(profile), |
| 100 syncable_pref_observer_(this) { |
| 95 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 101 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 96 } | 102 } |
| 97 | 103 |
| 104 ExternalPrefLoader::~ExternalPrefLoader() { |
| 105 } |
| 106 |
| 98 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { | 107 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { |
| 99 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 108 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 100 | 109 |
| 101 // |base_path_| was set in LoadOnFileThread(). | 110 // |base_path_| was set in LoadOnFileThread(). |
| 102 return base_path_; | 111 return base_path_; |
| 103 } | 112 } |
| 104 | 113 |
| 105 void ExternalPrefLoader::StartLoading() { | 114 void ExternalPrefLoader::StartLoading() { |
| 106 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 115 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 107 BrowserThread::PostTask( | 116 if (options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) { |
| 108 BrowserThread::FILE, FROM_HERE, | 117 if (!PostLoadIfPrioritySyncReady()) { |
| 109 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 118 DCHECK(profile_); |
| 119 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
| 120 DCHECK(prefs); |
| 121 syncable_pref_observer_.Add(prefs); |
| 122 } |
| 123 } else { |
| 124 BrowserThread::PostTask( |
| 125 BrowserThread::FILE, FROM_HERE, |
| 126 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
| 127 } |
| 128 } |
| 129 |
| 130 void ExternalPrefLoader::OnIsSyncingChanged() { |
| 131 PostLoadIfPrioritySyncReady(); |
| 132 } |
| 133 |
| 134 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { |
| 135 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); |
| 136 DCHECK(profile_); |
| 137 |
| 138 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
| 139 DCHECK(prefs); |
| 140 if (prefs->IsPrioritySyncing()) { |
| 141 BrowserThread::PostTask( |
| 142 BrowserThread::FILE, FROM_HERE, |
| 143 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); |
| 144 syncable_pref_observer_.Remove(prefs); |
| 145 return true; |
| 146 } |
| 147 |
| 148 return false; |
| 110 } | 149 } |
| 111 | 150 |
| 112 void ExternalPrefLoader::LoadOnFileThread() { | 151 void ExternalPrefLoader::LoadOnFileThread() { |
| 113 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 152 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 114 | 153 |
| 115 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 154 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
| 116 | 155 |
| 117 // TODO(skerner): Some values of base_path_id_ will cause | 156 // TODO(skerner): Some values of base_path_id_ will cause |
| 118 // PathService::Get() to return false, because the path does | 157 // PathService::Get() to return false, because the path does |
| 119 // not exist. Find and fix the build/install scripts so that | 158 // not exist. Find and fix the build/install scripts so that |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 LoadFinished(); | 284 LoadFinished(); |
| 246 } | 285 } |
| 247 | 286 |
| 248 ExternalTestingLoader::~ExternalTestingLoader() {} | 287 ExternalTestingLoader::~ExternalTestingLoader() {} |
| 249 | 288 |
| 250 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 289 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
| 251 return fake_base_path_; | 290 return fake_base_path_; |
| 252 } | 291 } |
| 253 | 292 |
| 254 } // namespace extensions | 293 } // namespace extensions |
| OLD | NEW |