Skip to content

Commit

Permalink
Add a new component for WiFi credential sync. Populate the
Browse files Browse the repository at this point in the history
new component with a stub SyncableService, and its
corresponding factory. This SyncableService is plumbed
into sync iff "--enable-wifi-credential-sync" is present
in the command-line.

Also:
- add sync integration tests (single client, and two client)
- add WifiSecurityClass: an enum to provide an internal
  representation of WiFi security classes (e.g. WEP, PSK).
- add WifiCredential: an abstraction of the parameters
  required to find and connect to a WiFi network
- add conversions between ModelType and NotificationType,
  for WIFI_CREDENTIALS

BUG=chromium:426693
BUG=chromium:426696
BUG=chromium:427595
TEST=sync_integration_tests --gtest_filter="*Wifi*"
TEST=components_unittests --gtest_filter="Wifi*"

Review URL: https://codereview.chromium.org/709683004

Cr-Commit-Position: refs/heads/master@{#309333}
  • Loading branch information
quiche authored and Commit bot committed Dec 20, 2014
1 parent 7608f02 commit 271c6cc
Show file tree
Hide file tree
Showing 33 changed files with 879 additions and 1 deletion.
1 change: 1 addition & 0 deletions chrome/browser/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ source_set("chromeos") {
"//components/session_manager/core",
"//components/user_manager",
"//components/wallpaper",
"//components/wifi_sync",
"//chrome/browser/devtools",
"//chrome/browser/extensions",
"//chrome/browser/history:in_memory_url_index_cache_proto",
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/sync/DEPS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include_rules = [
"+components/sync_driver",
"+components/wifi_sync",

# Used by tests.
"+google/cacheinvalidation",
Expand Down
22 changes: 22 additions & 0 deletions chrome/browser/sync/profile_sync_components_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
#include "chrome/browser/spellchecker/spellcheck_service.h"
#endif

#if defined(OS_CHROMEOS)
#include "components/wifi_sync/wifi_credential_syncable_service.h"
#include "components/wifi_sync/wifi_credential_syncable_service_factory.h"
#endif

using browser_sync::AutofillDataTypeController;
using browser_sync::AutofillProfileDataTypeController;
using browser_sync::BookmarkChangeProcessor;
Expand Down Expand Up @@ -392,6 +397,18 @@ void ProfileSyncComponentsFactoryImpl::RegisterDesktopDataTypes(
this,
profile_));
#endif

#if defined(OS_CHROMEOS)
if (command_line_->HasSwitch(switches::kEnableWifiCredentialSync) &&
!disabled_types.Has(syncer::WIFI_CREDENTIALS)) {
pss->RegisterDataTypeController(
new UIDataTypeController(
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
base::Bind(&ChromeReportUnrecoverableError),
syncer::WIFI_CREDENTIALS,
this));
}
#endif
}

DataTypeManager* ProfileSyncComponentsFactoryImpl::CreateDataTypeManager(
Expand Down Expand Up @@ -528,6 +545,11 @@ base::WeakPtr<syncer::SyncableService> ProfileSyncComponentsFactoryImpl::
return base::WeakPtr<syncer::SyncableService>();
#endif
}
#if defined(OS_CHROMEOS)
case syncer::WIFI_CREDENTIALS:
return wifi_sync::WifiCredentialSyncableServiceFactory::
GetForBrowserContext(profile_)->AsWeakPtr();
#endif
default:
// The following datatypes still need to be transitioned to the
// syncer::SyncableService API:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 "base/command_line.h"
#include "base/macros.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/wifi_credentials_helper.h"
#include "chrome/common/chrome_switches.h"

class SingleClientWifiCredentialsSyncTest : public SyncTest {
public:
SingleClientWifiCredentialsSyncTest() : SyncTest(SINGLE_CLIENT) {}
~SingleClientWifiCredentialsSyncTest() override {}

void SetUpCommandLine(CommandLine* command_line) override {
SyncTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnableWifiCredentialSync);
}

private:
DISALLOW_COPY_AND_ASSIGN(SingleClientWifiCredentialsSyncTest);
};

IN_PROC_BROWSER_TEST_F(SingleClientWifiCredentialsSyncTest, NoCredentials) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(wifi_credentials_helper::VerifierIsEmpty());
ASSERT_TRUE(wifi_credentials_helper::ProfileMatchesVerifier(0));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 "base/command_line.h"
#include "base/macros.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "chrome/browser/sync/test/integration/wifi_credentials_helper.h"
#include "chrome/common/chrome_switches.h"

class TwoClientWifiCredentialsSyncTest : public SyncTest {
public:
TwoClientWifiCredentialsSyncTest() : SyncTest(TWO_CLIENT) {}
~TwoClientWifiCredentialsSyncTest() override {}

void SetUpCommandLine(CommandLine* command_line) override {
SyncTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(switches::kEnableWifiCredentialSync);
}

private:
DISALLOW_COPY_AND_ASSIGN(TwoClientWifiCredentialsSyncTest);
};

IN_PROC_BROWSER_TEST_F(TwoClientWifiCredentialsSyncTest, NoCredentials) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(wifi_credentials_helper::VerifierIsEmpty());
ASSERT_TRUE(wifi_credentials_helper::AllProfilesMatch());
}
95 changes: 95 additions & 0 deletions chrome/browser/sync/test/integration/wifi_credentials_helper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// 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 "chrome/browser/sync/test/integration/wifi_credentials_helper.h"

#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
#include "chrome/browser/sync/test/integration/sync_test.h"
#include "components/wifi_sync/wifi_credential.h"
#include "components/wifi_sync/wifi_security_class.h"

#if defined(OS_CHROMEOS)
#include "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.h"
#endif

using wifi_sync::WifiCredential;
using sync_datatype_helper::test;

using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet;

namespace wifi_credentials_helper {

namespace {

WifiCredentialSet GetWifiCredentialsForProfile(const Profile* profile) {
#if defined(OS_CHROMEOS)
return GetWifiCredentialsForProfileChromeOs(profile);
#else
NOTIMPLEMENTED();
return WifiCredential::MakeSet();
#endif
}

bool CredentialsMatch(const WifiCredentialSet& a_credentials,
const WifiCredentialSet& b_credentials) {
if (a_credentials.size() != b_credentials.size()) {
LOG(ERROR) << "CredentialSets a and b do not match in size: "
<< a_credentials.size()
<< " vs " << b_credentials.size() << " respectively.";
return false;
}

for (const auto &credential : a_credentials) {
if (b_credentials.find(credential) == b_credentials.end()) {
LOG(ERROR)
<< "Network from a not found in b. "
<< "SSID (hex): "
<< base::HexEncode(credential.ssid().data(),
credential.ssid().size()).c_str()
<< " SecurityClass: " << credential.security_class()
<< " Passphrase: " << credential.passphrase();
return false;
}
}

return true;
}

} // namespace

bool VerifierIsEmpty() {
return GetWifiCredentialsForProfile(test()->verifier()).empty();
}

bool ProfileMatchesVerifier(int profile_index) {
WifiCredentialSet verifier_credentials =
GetWifiCredentialsForProfile(test()->verifier());
WifiCredentialSet other_credentials =
GetWifiCredentialsForProfile(test()->GetProfile(profile_index));
return CredentialsMatch(verifier_credentials, other_credentials);
}

bool AllProfilesMatch() {
if (test()->use_verifier() && !ProfileMatchesVerifier(0)) {
LOG(ERROR) << "Profile 0 does not match verifier.";
return false;
}

WifiCredentialSet profile0_credentials =
GetWifiCredentialsForProfile(test()->GetProfile(0));
for (int i = 1; i < test()->num_clients(); ++i) {
WifiCredentialSet other_profile_credentials =
GetWifiCredentialsForProfile(test()->GetProfile(i));
if (!CredentialsMatch(profile0_credentials, other_profile_credentials)) {
LOG(ERROR) << "Profile " << i << " " << "does not match with profile 0.";
return false;
}
}
return true;
}

} // namespace wifi_credentials_helper
26 changes: 26 additions & 0 deletions chrome/browser/sync/test/integration/wifi_credentials_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.

#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_H_

// Functions needed by multiple wifi_credentials integration
// tests. This module is platfrom-agnostic, and calls out to
// platform-specific code as needed.
namespace wifi_credentials_helper {

// Checks if the verifier has any items in it. Returns true iff the
// verifier has no items.
bool VerifierIsEmpty();

// Compares the BrowserContext for |profile_index| with the
// verifier. Returns true iff their WiFi credentials match.
bool ProfileMatchesVerifier(int profile_index);

// Returns true iff all BrowserContexts match with the verifier.
bool AllProfilesMatch();

} // namespace wifi_credentials_helper

#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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 "chrome/browser/sync/test/integration/wifi_credentials_helper_chromeos.h"

#include <string>

#include "base/files/file_path.h"
#include "base/logging.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/network/network_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "components/wifi_sync/network_state_helper_chromeos.h"
#include "components/wifi_sync/wifi_security_class.h"

using WifiCredentialSet = wifi_sync::WifiCredential::CredentialSet;

namespace wifi_credentials_helper {

namespace {

const char kProfilePrefix[] = "/profile/";

std::string ChromeOsUserHashForBrowserContext(
const content::BrowserContext& context) {
return context.GetPath().BaseName().value();
}

std::string ShillProfilePathForBrowserContext(
const content::BrowserContext& context) {
return kProfilePrefix + ChromeOsUserHashForBrowserContext(context);
}

chromeos::NetworkStateHandler* GetNetworkStateHandler() {
DCHECK(chromeos::NetworkHandler::Get()->network_state_handler());
return chromeos::NetworkHandler::Get()->network_state_handler();
}

} // namespace

WifiCredentialSet GetWifiCredentialsForProfileChromeOs(const Profile* profile) {
DCHECK(profile);
return wifi_sync::GetWifiCredentialsForShillProfile(
GetNetworkStateHandler(), ShillProfilePathForBrowserContext(*profile));
}

} // namespace wifi_credentials_helper
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.

#ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_CHROMEOS_H_
#define CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_CHROMEOS_H_

#include "components/wifi_sync/wifi_credential.h"

class Profile;

namespace wifi_credentials_helper {

// Returns the ChromeOS WiFi credentials associated with |profile|.
wifi_sync::WifiCredential::CredentialSet GetWifiCredentialsForProfileChromeOs(
const Profile* profile);

} // namespace wifi_credentials_helper

#endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_WIFI_CREDENTIALS_HELPER_CHROMEOS_H_
1 change: 1 addition & 0 deletions chrome/chrome_browser_chromeos.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@
'../components/components.gyp:variations',
'../components/components.gyp:variations_http_provider',
'../components/components.gyp:wallpaper',
'../components/components.gyp:wifi_sync',
'../components/components_strings.gyp:components_strings',
'../content/app/resources/content_resources.gyp:content_resources',
'../content/content.gyp:content_browser',
Expand Down
22 changes: 22 additions & 0 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@
'browser/sync/test/integration/single_client_supervised_user_settings_sync_test.cc',
'browser/sync/test/integration/single_client_themes_sync_test.cc',
'browser/sync/test/integration/single_client_typed_urls_sync_test.cc',
'browser/sync/test/integration/single_client_wifi_credentials_sync_test.cc',
'browser/sync/test/integration/sync_auth_test.cc',
'browser/sync/test/integration/sync_errors_test.cc',
'browser/sync/test/integration/sync_exponential_backoff_test.cc',
Expand All @@ -1268,6 +1269,7 @@
'browser/sync/test/integration/two_client_sessions_sync_test.cc',
'browser/sync/test/integration/two_client_themes_sync_test.cc',
'browser/sync/test/integration/two_client_typed_urls_sync_test.cc',
'browser/sync/test/integration/two_client_wifi_credentials_sync_test.cc',
],
'test_support_sync_integration_sources': [
'browser/sync/test/integration/apps_helper.cc',
Expand Down Expand Up @@ -1332,6 +1334,10 @@
'browser/sync/test/integration/typed_urls_helper.h',
'browser/sync/test/integration/updated_progress_marker_checker.cc',
'browser/sync/test/integration/updated_progress_marker_checker.h',
'browser/sync/test/integration/wifi_credentials_helper.cc',
'browser/sync/test/integration/wifi_credentials_helper.h',
'browser/sync/test/integration/wifi_credentials_helper_chromeos.cc',
'browser/sync/test/integration/wifi_credentials_helper_chromeos.h',
],
'sync_performance_tests_sources': [
'app/chrome_command_ids.h',
Expand Down Expand Up @@ -2633,6 +2639,15 @@
'browser/sync/test/integration/dictionary_load_observer.h',
],
}],
['chromeos==0', {
# Note: this list is duplicated in the GN build.
'sources!': [
'browser/sync/test/integration/wifi_credentials_helper.cc',
'browser/sync/test/integration/wifi_credentials_helper.h',
# 'browser/sync/test/integration/wifi_credentials_helper_chromeos.cc',
# 'browser/sync/test/integration/wifi_credentials_helper_chromeos.h',
],
}],
['enable_app_list==0', {
# Note: this list is duplicated in the GN build.
'sources!': [
Expand Down Expand Up @@ -2740,6 +2755,13 @@
'../ui/views/views.gyp:views',
],
}],
['chromeos == 0', {
'sources!': [
# Note: this list is duplicated in the GN build.
'browser/sync/test/integration/single_client_wifi_credentials_sync_test.cc',
'browser/sync/test/integration/two_client_wifi_credentials_sync_test.cc',
],
}],
['enable_basic_printing==1 or enable_print_preview==1', {
'dependencies': [
'../printing/printing.gyp:printing',
Expand Down
3 changes: 3 additions & 0 deletions chrome/common/chrome_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,9 @@ extern const char kEnableWebAppFrame[] = "enable-web-app-frame";
// Enables the Website Settings page on the Settings page.
const char kEnableWebsiteSettingsManager[] = "enable-website-settings-manager";

// Enables synchronizing WiFi credentials across devices, using Chrome Sync.
const char kEnableWifiCredentialSync[] = "enable-wifi-credential-sync";

// Explicitly allows additional ports using a comma-separated list of port
// numbers.
const char kExplicitlyAllowedPorts[] = "explicitly-allowed-ports";
Expand Down
1 change: 1 addition & 0 deletions chrome/common/chrome_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ extern const char kEnableTranslateNewUX[];
extern const char kEnableUserAlternateProtocolPorts[];
extern const char kEnableWebAppFrame[];
extern const char kEnableWebsiteSettingsManager[];
extern const char kEnableWifiCredentialSync[];
extern const char kEnhancedBookmarksExperiment[];
extern const char kExplicitlyAllowedPorts[];
extern const char kExtensionContentVerificationBootstrap[];
Expand Down
Loading

0 comments on commit 271c6cc

Please sign in to comment.