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

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

Issue 536573003: Add ExtensionManagement based ExternalLoader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ext-2
Patch Set: fixes to #14 Created 6 years, 3 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_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"
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 10
20 namespace extensions { 11 namespace extensions {
21 12
22 ExternalPolicyLoader::ExternalPolicyLoader(Profile* profile) 13 ExternalPolicyLoader::ExternalPolicyLoader(ExtensionManagement *settings)
23 : profile_(profile) { 14 : settings_(settings) {
24 pref_change_registrar_.Init(profile_->GetPrefs()); 15 settings_->AddObserver(this);
25 pref_change_registrar_.Add(pref_names::kInstallForceList, 16 }
26 base::Bind(&ExternalPolicyLoader::StartLoading, 17
27 base::Unretained(this))); 18 ExternalPolicyLoader::~ExternalPolicyLoader() {
28 pref_change_registrar_.Add(pref_names::kAllowedTypes, 19 settings_->RemoveObserver(this);
29 base::Bind(&ExternalPolicyLoader::StartLoading, 20 }
30 base::Unretained(this))); 21
31 notification_registrar_.Add(this, 22 void ExternalPolicyLoader::OnExtensionManagementSettingsChanged() {
32 chrome::NOTIFICATION_PROFILE_DESTROYED, 23 StartLoading();
33 content::Source<Profile>(profile_));
34 } 24 }
35 25
36 // static 26 // static
37 void ExternalPolicyLoader::AddExtension(base::DictionaryValue* dict, 27 void ExternalPolicyLoader::AddExtension(base::DictionaryValue* dict,
38 const std::string& extension_id, 28 const std::string& extension_id,
39 const std::string& update_url) { 29 const std::string& update_url) {
40 dict->SetString(base::StringPrintf("%s.%s", extension_id.c_str(), 30 dict->SetString(base::StringPrintf("%s.%s", extension_id.c_str(),
41 ExternalProviderImpl::kExternalUpdateUrl), 31 ExternalProviderImpl::kExternalUpdateUrl),
42 update_url); 32 update_url);
43 } 33 }
44 34
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) <<
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() { 35 void ExternalPolicyLoader::StartLoading() {
60 const base::DictionaryValue* forcelist = 36 prefs_ = settings_->GetForceInstallList();
61 profile_->GetPrefs()->GetDictionary(pref_names::kInstallForceList);
62 prefs_.reset(forcelist ? forcelist->DeepCopy() : NULL);
63 LoadFinished(); 37 LoadFinished();
64 } 38 }
65 39
66 } // namespace extensions 40 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698