Chromium Code Reviews| Index: chrome/browser/chromeos/net/network_pref_state_observer.cc |
| diff --git a/chrome/browser/chromeos/net/network_pref_state_observer.cc b/chrome/browser/chromeos/net/network_pref_state_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..93c7a15fcf75c79a67849ee7de901d81fe68457f |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/net/network_pref_state_observer.cc |
| @@ -0,0 +1,43 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/net/network_pref_state_observer.h" |
| + |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chromeos/network/network_handler.h" |
| +#include "content/public/browser/notification_service.h" |
| + |
| +namespace chromeos { |
| + |
| +NetworkPrefStateObserver::NetworkPrefStateObserver() { |
| + // Initialize NetworkHandlwer with device prefs only. |
|
emaxx
2016/11/02 18:18:05
nit: s/NetworkHandlwer/NetworkHandler/
stevenjb
2016/11/02 19:47:33
Done.
|
| + InitializeNetworkPrefServices(nullptr /* profile */); |
| + |
| + notification_registrar_.Add(this, |
| + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
|
emaxx
2016/11/02 18:18:05
Isn't the usage of NotificationType discouraged in
stevenjb
2016/11/02 19:47:33
I am not aware of any alternative, and we rely on
|
| + content::NotificationService::AllSources()); |
| +} |
| + |
| +NetworkPrefStateObserver::~NetworkPrefStateObserver() {} |
| + |
| +void NetworkPrefStateObserver::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + DCHECK_EQ(chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, type); |
| + Profile* profile = content::Details<Profile>(details).ptr(); |
| + DCHECK(profile); |
| + InitializeNetworkPrefServices(profile); |
| +} |
| + |
| +void NetworkPrefStateObserver::InitializeNetworkPrefServices(Profile* profile) { |
| + DCHECK(g_browser_process); |
| + NetworkHandler::Get()->InitializePrefServices( |
| + profile ? profile->GetPrefs() : nullptr, |
| + g_browser_process->local_state()); |
| +} |
| + |
| +} // namespace chromeos |