Chromium Code Reviews| 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_policy_loader.h" | 5 #include "chrome/browser/extensions/external_policy_loader.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/prefs/pref_service.h" | |
| 10 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 11 #include "base/values.h" | 8 #include "base/values.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | |
| 13 #include "chrome/browser/extensions/external_provider_impl.h" | 9 #include "chrome/browser/extensions/external_provider_impl.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/pref_names.h" | |
| 16 #include "content/public/browser/notification_details.h" | |
| 17 #include "content/public/browser/notification_source.h" | |
| 18 #include "extensions/browser/pref_names.h" | |
| 19 | 11 |
| 20 namespace extensions { | 12 namespace extensions { |
| 21 | 13 |
| 22 ExternalPolicyLoader::ExternalPolicyLoader(Profile* profile) | 14 ExternalPolicyLoader::ExternalPolicyLoader(Profile* profile) |
| 23 : profile_(profile) { | 15 : settings_(ExtensionManagementFactory::GetInstance() |
|
Joao da Silva
2014/09/04 12:07:46
GetInstance() is not needed here, just do
Extens
binjin
2014/09/04 14:27:06
Done.
| |
| 24 pref_change_registrar_.Init(profile_->GetPrefs()); | 16 ->GetForBrowserContext(profile)) { |
| 25 pref_change_registrar_.Add(pref_names::kInstallForceList, | 17 settings_->AddObserver(this); |
| 26 base::Bind(&ExternalPolicyLoader::StartLoading, | 18 } |
| 27 base::Unretained(this))); | 19 |
| 28 pref_change_registrar_.Add(pref_names::kAllowedTypes, | 20 ExternalPolicyLoader::~ExternalPolicyLoader() { |
| 29 base::Bind(&ExternalPolicyLoader::StartLoading, | 21 settings_->RemoveObserver(this); |
| 30 base::Unretained(this))); | 22 } |
| 31 notification_registrar_.Add(this, | 23 |
| 32 chrome::NOTIFICATION_PROFILE_DESTROYED, | 24 void ExternalPolicyLoader::OnExtensionManagementSettingsChanged() { |
| 33 content::Source<Profile>(profile_)); | 25 StartLoading(); |
| 34 } | 26 } |
| 35 | 27 |
| 36 // static | 28 // static |
| 37 void ExternalPolicyLoader::AddExtension(base::DictionaryValue* dict, | 29 void ExternalPolicyLoader::AddExtension(base::DictionaryValue* dict, |
| 38 const std::string& extension_id, | 30 const std::string& extension_id, |
| 39 const std::string& update_url) { | 31 const std::string& update_url) { |
| 40 dict->SetString(base::StringPrintf("%s.%s", extension_id.c_str(), | 32 dict->SetString(base::StringPrintf("%s.%s", extension_id.c_str(), |
| 41 ExternalProviderImpl::kExternalUpdateUrl), | 33 ExternalProviderImpl::kExternalUpdateUrl), |
| 42 update_url); | 34 update_url); |
|
Joao da Silva
2014/09/04 12:07:46
Move this method to ExtensionManagement too.
binjin
2014/09/04 14:27:06
I think it's better to move this to ExternalProvid
| |
| 43 } | 35 } |
| 44 | 36 |
| 45 void ExternalPolicyLoader::Observe( | |
| 46 int type, | |
| 47 const content::NotificationSource& source, | |
| 48 const content::NotificationDetails& details) { | |
| 49 if (profile_ == NULL) return; | |
| 50 DCHECK(type == chrome::NOTIFICATION_PROFILE_DESTROYED) << | |
|
Joao da Silva
2014/09/04 12:07:46
I wonder why this was here before. Are we sure tha
binjin
2014/09/04 14:27:06
Not sure. Does the destroyed order of ExtensionMan
Joao da Silva
2014/09/04 16:55:29
I just worry that |settings_| may be a stray point
| |
| 51 "Unexpected notification type."; | |
| 52 if (content::Source<Profile>(source).ptr() == profile_) { | |
| 53 notification_registrar_.RemoveAll(); | |
| 54 pref_change_registrar_.RemoveAll(); | |
| 55 profile_ = NULL; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void ExternalPolicyLoader::StartLoading() { | 37 void ExternalPolicyLoader::StartLoading() { |
| 60 const base::DictionaryValue* forcelist = | 38 prefs_ = settings_->GetForceInstallList(); |
| 61 profile_->GetPrefs()->GetDictionary(pref_names::kInstallForceList); | |
| 62 prefs_.reset(forcelist ? forcelist->DeepCopy() : NULL); | |
| 63 LoadFinished(); | 39 LoadFinished(); |
| 64 } | 40 } |
| 65 | 41 |
| 66 } // namespace extensions | 42 } // namespace extensions |
| OLD | NEW |