Commit 6967652c authored by jianli's avatar jianli Committed by Commit bot

Clear GCM data when the user clears cookies and other site data

This is needed for the work to drop GCM sign-in enforcement. Since
we no longer wipe out the GCM data when the user signs out, we need
to give user a chance to clear the data if he or she wants.

BUG=384041
TEST=Manual test by selecting "Cookies and other site and plugin data"

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

Cr-Commit-Position: refs/heads/master@{#294754}
parent a541363f
......@@ -35,6 +35,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/services/gcm/gcm_profile_service.h"
#include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/sessions/tab_restore_service.h"
......@@ -45,6 +47,7 @@
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
#include "components/domain_reliability/service.h"
#include "components/gcm_driver/gcm_driver.h"
#include "components/nacl/browser/nacl_browser.h"
#include "components/nacl/browser/pnacl_host.h"
#include "components/password_manager/core/browser/password_store.h"
......@@ -532,6 +535,15 @@ void BrowsingDataRemover::RemoveImpl(int remove_mask,
}
#endif
#if !defined(OS_ANDROID)
if (remove_mask & REMOVE_GCM) {
gcm::GCMProfileService* gcm_profile_service =
gcm::GCMProfileServiceFactory::GetForProfile(profile_);
if (gcm_profile_service)
gcm_profile_service->driver()->Purge();
}
#endif
if (remove_mask & REMOVE_PASSWORDS) {
content::RecordAction(UserMetricsAction("ClearBrowsingData_Passwords"));
password_manager::PasswordStore* password_store =
......
......@@ -92,6 +92,9 @@ class BrowsingDataRemover
REMOVE_SERVICE_WORKERS = 1 << 14,
#if defined(OS_ANDROID)
REMOVE_APP_BANNER_DATA = 1 << 15,
#endif
#if !defined(OS_ANDROID)
REMOVE_GCM = 1 << 16,
#endif
// The following flag is used only in tests. In normal usage, hosted app
// data is controlled by the REMOVE_COOKIES flag, applied to the
......@@ -108,6 +111,9 @@ class BrowsingDataRemover
REMOVE_WEBSQL |
#if defined(OS_ANDROID)
REMOVE_APP_BANNER_DATA |
#endif
#if !defined(OS_ANDROID)
REMOVE_GCM |
#endif
REMOVE_CHANNEL_IDS,
......
......@@ -496,39 +496,41 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSimple) {
// Test cookie and app data settings.
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionSiteData) {
int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
int site_data_no_plugins_and_gcm = BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA &
~BrowsingDataRemover::REMOVE_GCM;
SetPrefsAndVerifySettings(BrowsingDataRemover::REMOVE_COOKIES,
UNPROTECTED_WEB,
site_data_no_plugins);
site_data_no_plugins_and_gcm);
SetPrefsAndVerifySettings(
BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY,
PROTECTED_WEB,
site_data_no_plugins);
site_data_no_plugins_and_gcm);
SetPrefsAndVerifySettings(
BrowsingDataRemover::REMOVE_COOKIES |
BrowsingDataRemover::REMOVE_HOSTED_APP_DATA_TESTONLY,
PROTECTED_WEB | UNPROTECTED_WEB,
site_data_no_plugins);
site_data_no_plugins_and_gcm);
SetPrefsAndVerifySettings(
BrowsingDataRemover::REMOVE_COOKIES |
BrowsingDataRemover::REMOVE_PLUGIN_DATA,
UNPROTECTED_WEB,
BrowsingDataRemover::REMOVE_SITE_DATA);
site_data_no_plugins_and_gcm | BrowsingDataRemover::REMOVE_PLUGIN_DATA);
}
// Test an arbitrary assortment of settings.
IN_PROC_BROWSER_TEST_F(ExtensionBrowsingDataTest, SettingsFunctionAssorted) {
int site_data_no_plugins = BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA;
int site_data_no_plugins_and_gcm = BrowsingDataRemover::REMOVE_SITE_DATA &
~BrowsingDataRemover::REMOVE_PLUGIN_DATA &
~BrowsingDataRemover::REMOVE_GCM;
SetPrefsAndVerifySettings(
BrowsingDataRemover::REMOVE_COOKIES |
BrowsingDataRemover::REMOVE_HISTORY |
BrowsingDataRemover::REMOVE_DOWNLOADS,
UNPROTECTED_WEB,
site_data_no_plugins |
site_data_no_plugins_and_gcm |
BrowsingDataRemover::REMOVE_HISTORY |
BrowsingDataRemover::REMOVE_DOWNLOADS);
}
......@@ -116,9 +116,11 @@ void GCMProfileService::IdentityObserver::OnActiveAccountLogout() {
// Check is necessary to not crash browser_tests.
if (gcm_account_tracker_)
gcm_account_tracker_->Stop();
// TODO(fgorski): If we purge here, what should happen when we get
// OnActiveAccountLogin() right after that?
driver_->Purge();
// When sign-in enforcement is not dropped, OnSignedOut will also clear all
// the GCM data and a new GCM ID will be retrieved after the user signs in
// again. Otherwise, the user sign-out will not affect the existing GCM
// data.
driver_->OnSignedOut();
}
std::string GCMProfileService::IdentityObserver::SignedInUserName() const {
......
......@@ -25,6 +25,9 @@ void FakeGCMDriver::RemoveAppHandler(const std::string& app_id) {
void FakeGCMDriver::OnSignedIn() {
}
void FakeGCMDriver::OnSignedOut() {
}
void FakeGCMDriver::Purge() {
}
......
......@@ -22,6 +22,7 @@ class FakeGCMDriver : public GCMDriver {
GCMAppHandler* handler) OVERRIDE;
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
virtual void OnSignedIn() OVERRIDE;
virtual void OnSignedOut() OVERRIDE;
virtual void Purge() OVERRIDE;
virtual void AddConnectionObserver(GCMConnectionObserver* observer) OVERRIDE;
virtual void RemoveConnectionObserver(
......
......@@ -72,9 +72,9 @@ class GCMDriver {
// been called, no other GCMDriver methods may be used.
virtual void Shutdown();
// Call this method when the user signs in to a GAIA account.
// TODO(jianli): To be removed when sign-in enforcement is dropped.
// Called when the user signs in to or out of a GAIA account.
virtual void OnSignedIn() = 0;
virtual void OnSignedOut() = 0;
// Removes all the cached and persisted GCM data. If the GCM service is
// restarted after the purge, a new Android ID will be obtained.
......
......@@ -95,6 +95,9 @@ bool GCMDriverAndroid::RegisterBindings(JNIEnv* env) {
void GCMDriverAndroid::OnSignedIn() {
}
void GCMDriverAndroid::OnSignedOut() {
}
void GCMDriverAndroid::Purge() {
}
......
......@@ -45,6 +45,7 @@ class GCMDriverAndroid : public GCMDriver {
// GCMDriver implementation:
virtual void OnSignedIn() OVERRIDE;
virtual void OnSignedOut() OVERRIDE;
virtual void Purge() OVERRIDE;
virtual void Enable() OVERRIDE;
virtual void AddConnectionObserver(GCMConnectionObserver* observer) OVERRIDE;
......
......@@ -369,13 +369,18 @@ void GCMDriverDesktop::OnSignedIn() {
EnsureStarted();
}
void GCMDriverDesktop::OnSignedOut() {
signed_in_ = false;
// When sign-in enforcement is dropped, we will no longer wipe out the GCM
// data when the user signs out.
if (!GCMDriver::IsAllowedForAllUsers())
Purge();
}
void GCMDriverDesktop::Purge() {
DCHECK(ui_thread_->RunsTasksOnCurrentThread());
// We still proceed with the check-out logic even if the check-in is not
// initiated in the current session. This will make sure that all the
// persisted data written previously will get purged.
signed_in_ = false;
RemoveCachedData();
io_thread_->PostTask(FROM_HERE,
......@@ -616,7 +621,6 @@ GCMClient::Result GCMDriverDesktop::EnsureStarted() {
if (app_handlers().empty())
return GCMClient::UNKNOWN_ERROR;
// TODO(jianli): To be removed when sign-in enforcement is dropped.
if (!signed_in_ && !GCMDriver::IsAllowedForAllUsers())
return GCMClient::NOT_SIGNED_IN;
......
......@@ -54,6 +54,7 @@ class GCMDriverDesktop : public GCMDriver {
// GCMDriver overrides:
virtual void Shutdown() OVERRIDE;
virtual void OnSignedIn() OVERRIDE;
virtual void OnSignedOut() OVERRIDE;
virtual void Purge() OVERRIDE;
virtual void AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) OVERRIDE;
......
......@@ -258,7 +258,7 @@ void GCMDriverTest::SignIn(const std::string& account_id) {
}
void GCMDriverTest::SignOut() {
driver_->Purge();
driver_->OnSignedOut();
PumpIOLoop();
PumpUILoop();
}
......@@ -350,6 +350,7 @@ TEST_F(GCMDriverTest, Create) {
}
TEST_F(GCMDriverTest, CreateByFieldTrial) {
// Turn on the signal to drop sign-in enforcement.
ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial("GCM", "Enabled"));
// Create GCMDriver first. GCM is not started.
......@@ -364,6 +365,18 @@ TEST_F(GCMDriverTest, CreateByFieldTrial) {
PumpIOLoop();
EXPECT_TRUE(driver()->IsConnected());
EXPECT_TRUE(gcm_connection_observer()->connected());
// Sign-in will not affect GCM state.
SignIn(kTestAccountID1);
PumpIOLoop();
EXPECT_TRUE(driver()->IsStarted());
EXPECT_TRUE(driver()->IsConnected());
// Sign-out will not affect GCM state.
SignOut();
PumpIOLoop();
EXPECT_TRUE(driver()->IsStarted());
EXPECT_TRUE(driver()->IsConnected());
}
TEST_F(GCMDriverTest, Shutdown) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment