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" |
Nikita (slow)
2014/10/27 09:44:49
#include "chrome/browser/profiles/profile.h"
Dmitry Polukhin
2014/10/27 14:48:48
Discussed offline, I don't use Profile, only pass
| |
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), options_(options), | |
Nikita (slow)
2014/10/27 09:44:49
nit: one initialization per line now that they all
Dmitry Polukhin
2014/10/27 14:48:48
Done.
| |
98 profile_(profile), pref_observer_added_(false) { | |
95 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
96 } | 100 } |
97 | 101 |
102 ExternalPrefLoader::~ExternalPrefLoader() { | |
103 if (pref_observer_added_) { | |
104 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | |
105 DCHECK(prefs); | |
106 prefs->RemoveObserver(this); | |
107 } | |
108 } | |
109 | |
98 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { | 110 const base::FilePath ExternalPrefLoader::GetBaseCrxFilePath() { |
99 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 111 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
100 | 112 |
101 // |base_path_| was set in LoadOnFileThread(). | 113 // |base_path_| was set in LoadOnFileThread(). |
102 return base_path_; | 114 return base_path_; |
103 } | 115 } |
104 | 116 |
105 void ExternalPrefLoader::StartLoading() { | 117 void ExternalPrefLoader::StartLoading() { |
106 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
107 BrowserThread::PostTask( | 119 if (options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC) { |
108 BrowserThread::FILE, FROM_HERE, | 120 if (!PostLoadIfPrioritySyncReady()) { |
109 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | 121 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); |
Nikita (slow)
2014/10/27 09:44:49
nit: DCHECK(profile_);
Dmitry Polukhin
2014/10/27 14:48:48
Done.
| |
122 DCHECK(prefs); | |
123 prefs->AddObserver(this); | |
124 pref_observer_added_ = true; | |
125 } | |
126 } else { | |
127 BrowserThread::PostTask( | |
128 BrowserThread::FILE, FROM_HERE, | |
Nikita (slow)
2014/10/27 09:44:49
nit: As a follow up change you can get rid of FILE
| |
129 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
130 } | |
131 } | |
132 | |
133 void ExternalPrefLoader::OnIsSyncingChanged() { | |
134 PostLoadIfPrioritySyncReady(); | |
135 } | |
136 | |
137 bool ExternalPrefLoader::PostLoadIfPrioritySyncReady() { | |
138 DCHECK(options_ & DELAY_LOAD_UNTIL_PRIORITY_SYNC); | |
139 DCHECK(profile_); | |
140 | |
141 PrefServiceSyncable* prefs = PrefServiceSyncable::FromProfile(profile_); | |
142 DCHECK(prefs); | |
143 if (prefs->IsPrioritySyncing()) { | |
144 BrowserThread::PostTask( | |
145 BrowserThread::FILE, FROM_HERE, | |
146 base::Bind(&ExternalPrefLoader::LoadOnFileThread, this)); | |
147 prefs->RemoveObserver(this); | |
148 pref_observer_added_ = false; | |
149 return true; | |
150 } | |
151 | |
152 return false; | |
110 } | 153 } |
111 | 154 |
112 void ExternalPrefLoader::LoadOnFileThread() { | 155 void ExternalPrefLoader::LoadOnFileThread() { |
113 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 156 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
114 | 157 |
115 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); | 158 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue); |
116 | 159 |
117 // TODO(skerner): Some values of base_path_id_ will cause | 160 // TODO(skerner): Some values of base_path_id_ will cause |
118 // PathService::Get() to return false, because the path does | 161 // PathService::Get() to return false, because the path does |
119 // not exist. Find and fix the build/install scripts so that | 162 // 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(); | 288 LoadFinished(); |
246 } | 289 } |
247 | 290 |
248 ExternalTestingLoader::~ExternalTestingLoader() {} | 291 ExternalTestingLoader::~ExternalTestingLoader() {} |
249 | 292 |
250 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { | 293 const base::FilePath ExternalTestingLoader::GetBaseCrxFilePath() { |
251 return fake_base_path_; | 294 return fake_base_path_; |
252 } | 295 } |
253 | 296 |
254 } // namespace extensions | 297 } // namespace extensions |
OLD | NEW |