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

Unified Diff: components/wifi_sync/wifi_config_delegate_factory_chromeos.cc

Issue 836363002: wifi_sync: add WifiConfigDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@submit-4.1-network-state-helper
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/wifi_sync/wifi_config_delegate_factory_chromeos.cc
diff --git a/components/wifi_sync/wifi_config_delegate_factory_chromeos.cc b/components/wifi_sync/wifi_config_delegate_factory_chromeos.cc
new file mode 100644
index 0000000000000000000000000000000000000000..50f7a05724637eacd4bc0450fc4a58a167c0a032
--- /dev/null
+++ b/components/wifi_sync/wifi_config_delegate_factory_chromeos.cc
@@ -0,0 +1,75 @@
+// Copyright 2014 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 "components/wifi_sync/wifi_config_delegate_factory_chromeos.h"
+
+#include <string>
+
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "base/memory/singleton.h"
+#include "chromeos/login/login_state.h"
+#include "chromeos/network/network_handler.h"
+#include "components/wifi_sync/wifi_config_delegate_chromeos.h"
+#include "content/public/browser/browser_context.h"
+
+namespace wifi_sync {
+
+namespace {
+
+std::string GetChromeOsUserHash(
+ content::BrowserContext* context, bool use_login_state) {
+ if (use_login_state) {
+ auto login_state = chromeos::LoginState::Get();
+ DCHECK(login_state->IsUserLoggedIn());
+ DCHECK(!login_state->primary_user_hash().empty());
+ // TODO(quiche): verify that |context| is the primary user's
+ // context.
+ return login_state->primary_user_hash();
+ } else {
+ return context->GetPath().BaseName().value();
+ }
+}
+
+} // namespace
+
+// static
+WifiConfigDelegateFactoryChromeOs*
+WifiConfigDelegateFactoryChromeOs::GetInstance() {
+ return Singleton<WifiConfigDelegateFactoryChromeOs>::get();
+}
+
+void WifiConfigDelegateFactoryChromeOs::SetUseLoginState(bool use_login_state) {
+ use_login_state_ = use_login_state;
+}
+
+scoped_ptr<WifiConfigDelegate>
+WifiConfigDelegateFactoryChromeOs::BuildInstanceFor(
+ content::BrowserContext* context) {
+ // It is safe to pass the WifiConfigDelegate a bare pointer to the
+ // managed_network_configuration_handler, as long as the
+ // WifiConfigDelegate is owned by a KeyedService. The reasoning is
+ // as follows: a) |managed_network_configuration_handler| is owned
+ // by the chromeos::NetworkHandler singleton, b) the
+ // chromeos::NetworkHandler singleton is owned by the
+ // chromeos::internal::DBusServices singleton, c) the
+ // chromeos::internal::DBusServices singleton is guaranteed to
+ // outlive all KeyedServices.
+ auto network_handler = chromeos::NetworkHandler::Get();
+ return make_scoped_ptr(
+ new WifiConfigDelegateChromeOs(
+ GetChromeOsUserHash(context, use_login_state_),
+ network_handler->managed_network_configuration_handler()));
+}
+
+// Private methods.
+
+WifiConfigDelegateFactoryChromeOs::WifiConfigDelegateFactoryChromeOs()
+ : use_login_state_(true) {
+}
+
+WifiConfigDelegateFactoryChromeOs::~WifiConfigDelegateFactoryChromeOs() {
+}
+
+} // namespace wifi_sync
« no previous file with comments | « components/wifi_sync/wifi_config_delegate_factory_chromeos.h ('k') | components/wifi_sync/wifi_credential.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698