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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_settings_service.cc

Issue 1300643002: Added user settings to chrome://supervised-user-internals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: SupervisedUserSettingsService supports unsubscription Created 5 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/supervised_user/supervised_user_settings_service.h" 5 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/prefs/json_pref_store.h" 10 #include "base/prefs/json_pref_store.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 78 }
79 } 79 }
80 80
81 void SupervisedUserSettingsService::Init( 81 void SupervisedUserSettingsService::Init(
82 scoped_refptr<PersistentPrefStore> store) { 82 scoped_refptr<PersistentPrefStore> store) {
83 DCHECK(!store_.get()); 83 DCHECK(!store_.get());
84 store_ = store; 84 store_ = store;
85 store_->AddObserver(this); 85 store_->AddObserver(this);
86 } 86 }
87 87
88 void SupervisedUserSettingsService::Subscribe( 88 scoped_ptr<SupervisedUserSettingsService::SettingsCallbackList::Subscription>
89 SupervisedUserSettingsService::Subscribe(
89 const SettingsCallback& callback) { 90 const SettingsCallback& callback) {
90 if (IsReady()) { 91 if (IsReady()) {
91 scoped_ptr<base::DictionaryValue> settings = GetSettings(); 92 scoped_ptr<base::DictionaryValue> settings = GetSettings();
92 callback.Run(settings.get()); 93 callback.Run(settings.get());
93 } 94 }
94 95
95 subscribers_.push_back(callback); 96 return callback_list_.Add(callback);
96 } 97 }
97 98
98 void SupervisedUserSettingsService::SetActive(bool active) { 99 void SupervisedUserSettingsService::SetActive(bool active) {
99 active_ = active; 100 active_ = active;
100 InformSubscribers(); 101 InformSubscribers();
101 } 102 }
102 103
103 bool SupervisedUserSettingsService::IsReady() { 104 bool SupervisedUserSettingsService::IsReady() {
104 // Initialization cannot be complete but have failed at the same time. 105 // Initialization cannot be complete but have failed at the same time.
105 DCHECK(!(store_->IsInitializationComplete() && initialization_failed_)); 106 DCHECK(!(store_->IsInitializationComplete() && initialization_failed_));
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 400 }
400 401
401 return settings.Pass(); 402 return settings.Pass();
402 } 403 }
403 404
404 void SupervisedUserSettingsService::InformSubscribers() { 405 void SupervisedUserSettingsService::InformSubscribers() {
405 if (!IsReady()) 406 if (!IsReady())
406 return; 407 return;
407 408
408 scoped_ptr<base::DictionaryValue> settings = GetSettings(); 409 scoped_ptr<base::DictionaryValue> settings = GetSettings();
409 for (const auto& callback : subscribers_) 410 callback_list_.Notify(settings.get());
410 callback.Run(settings.get());
411 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698