summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasilii@chromium.org <vasilii@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-12 08:00:21 +0000
committervasilii@chromium.org <vasilii@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-12 08:00:21 +0000
commit82478fddbc14681442d09301dc4e9adf947d9468 (patch)
tree31ee34e34faa2260aed22e573339dcd4b134cfda
parent4674d46aec4f4627f7d32645bbe42bf2138dbb1e (diff)
downloadchromium_src-82478fddbc14681442d09301dc4e9adf947d9468.zip
chromium_src-82478fddbc14681442d09301dc4e9adf947d9468.tar.gz
chromium_src-82478fddbc14681442d09301dc4e9adf947d9468.tar.bz2
Merge 216683 "Profile Reset: include disabled extensions to the ..."
> Profile Reset: include disabled extensions to the feedback information. > > BUG=235037 > TBR=dbeam@chromium.org > > Review URL: https://chromiumcodereview.appspot.com/22351008 TBR=vasilii@chromium.org Review URL: https://codereview.chromium.org/22787002 git-svn-id: svn://svn.chromium.org/chrome/branches/1547/src@216957 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/profile_resetter/profile_resetter_unittest.cc51
-rw-r--r--chrome/browser/profile_resetter/resettable_settings_snapshot.cc39
-rw-r--r--chrome/browser/profile_resetter/resettable_settings_snapshot.h14
-rw-r--r--chrome/browser/ui/webui/options/reset_profile_settings_handler.cc2
4 files changed, 85 insertions, 21 deletions
diff --git a/chrome/browser/profile_resetter/profile_resetter_unittest.cc b/chrome/browser/profile_resetter/profile_resetter_unittest.cc
index 8a4993e..d417348 100644
--- a/chrome/browser/profile_resetter/profile_resetter_unittest.cc
+++ b/chrome/browser/profile_resetter/profile_resetter_unittest.cc
@@ -695,39 +695,46 @@ TEST_F(ProfileResetterTest, CheckSnapshots) {
ResettableSettingsSnapshot empty_snap(profile());
EXPECT_EQ(0, empty_snap.FindDifferentFields(empty_snap));
+ scoped_refptr<Extension> ext = CreateExtension(
+ "example",
+ base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
+ Manifest::INVALID_LOCATION,
+ extensions::Manifest::TYPE_EXTENSION,
+ false);
+ ASSERT_TRUE(ext);
+ service_->AddExtension(ext.get());
+
+ std::string master_prefs(kDistributionConfig);
+ std::string ext_id = ext->id();
+ ReplaceString(&master_prefs, "placeholder_for_id", ext_id);
+
// Reset to non organic defaults.
ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE |
ProfileResetter::HOMEPAGE |
- ProfileResetter::STARTUP_PAGES, kDistributionConfig);
+ ProfileResetter::STARTUP_PAGES, master_prefs);
ResettableSettingsSnapshot nonorganic_snap(profile());
- EXPECT_EQ(ResettableSettingsSnapshot::STARTUP_URLS |
- ResettableSettingsSnapshot::STARTUP_TYPE |
- ResettableSettingsSnapshot::HOMEPAGE |
- ResettableSettingsSnapshot::HOMEPAGE_IS_NTP |
- ResettableSettingsSnapshot::DSE_URL,
+ EXPECT_EQ(ResettableSettingsSnapshot::ALL_FIELDS,
empty_snap.FindDifferentFields(nonorganic_snap));
- empty_snap.SubtractStartupURLs(nonorganic_snap);
+ empty_snap.Subtract(nonorganic_snap);
EXPECT_TRUE(empty_snap.startup_urls().empty());
EXPECT_EQ(SessionStartupPref::GetDefaultStartupType(),
empty_snap.startup_type());
EXPECT_TRUE(empty_snap.homepage().empty());
EXPECT_TRUE(empty_snap.homepage_is_ntp());
EXPECT_NE(std::string::npos, empty_snap.dse_url().find("{google:baseURL}"));
+ EXPECT_EQ(std::vector<std::string>(), empty_snap.enabled_extensions());
// Reset to organic defaults.
ResetAndWait(ProfileResetter::DEFAULT_SEARCH_ENGINE |
ProfileResetter::HOMEPAGE |
- ProfileResetter::STARTUP_PAGES);
+ ProfileResetter::STARTUP_PAGES |
+ ProfileResetter::EXTENSIONS);
ResettableSettingsSnapshot organic_snap(profile());
- EXPECT_EQ(ResettableSettingsSnapshot::STARTUP_URLS |
- ResettableSettingsSnapshot::STARTUP_TYPE |
- ResettableSettingsSnapshot::HOMEPAGE |
- ResettableSettingsSnapshot::HOMEPAGE_IS_NTP |
- ResettableSettingsSnapshot::DSE_URL,
+ EXPECT_EQ(ResettableSettingsSnapshot::ALL_FIELDS,
nonorganic_snap.FindDifferentFields(organic_snap));
- nonorganic_snap.SubtractStartupURLs(organic_snap);
+ nonorganic_snap.Subtract(organic_snap);
const GURL urls[] = {GURL("http://foo.de"), GURL("http://goo.gl")};
EXPECT_EQ(std::vector<GURL>(urls, urls + arraysize(urls)),
nonorganic_snap.startup_urls());
@@ -735,6 +742,8 @@ TEST_F(ProfileResetterTest, CheckSnapshots) {
EXPECT_EQ("http://www.foo.com", nonorganic_snap.homepage());
EXPECT_FALSE(nonorganic_snap.homepage_is_ntp());
EXPECT_EQ("http://www.foo.com/s?q={searchTerms}", nonorganic_snap.dse_url());
+ EXPECT_EQ(std::vector<std::string>(1, ext_id),
+ nonorganic_snap.enabled_extensions());
}
TEST_F(ProfileResetterTest, FeedbackSerializtionTest) {
@@ -743,9 +752,18 @@ TEST_F(ProfileResetterTest, FeedbackSerializtionTest) {
ProfileResetter::HOMEPAGE |
ProfileResetter::STARTUP_PAGES, kDistributionConfig);
+ scoped_refptr<Extension> ext = CreateExtension(
+ "example",
+ base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
+ Manifest::INVALID_LOCATION,
+ extensions::Manifest::TYPE_EXTENSION,
+ false);
+ ASSERT_TRUE(ext);
+ service_->AddExtension(ext.get());
+
const ResettableSettingsSnapshot nonorganic_snap(profile());
- COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 31,
+ COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 63,
expand_this_test);
for (int field_mask = 0; field_mask <= ResettableSettingsSnapshot::ALL_FIELDS;
++field_mask) {
@@ -764,6 +782,7 @@ TEST_F(ProfileResetterTest, FeedbackSerializtionTest) {
std::string homepage;
bool homepage_is_ntp = true;
std::string default_search_engine;
+ ListValue* extensions;
EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::STARTUP_URLS),
dict->GetList("startup_urls", &startup_urls));
@@ -775,6 +794,8 @@ TEST_F(ProfileResetterTest, FeedbackSerializtionTest) {
dict->GetBoolean("homepage_is_ntp", &homepage_is_ntp));
EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::DSE_URL),
dict->GetString("default_search_engine", &default_search_engine));
+ EXPECT_EQ(!!(field_mask & ResettableSettingsSnapshot::EXTENSIONS),
+ dict->GetList("enabled_extensions", &extensions));
}
}
diff --git a/chrome/browser/profile_resetter/resettable_settings_snapshot.cc b/chrome/browser/profile_resetter/resettable_settings_snapshot.cc
index f6892ba..0542727 100644
--- a/chrome/browser/profile_resetter/resettable_settings_snapshot.cc
+++ b/chrome/browser/profile_resetter/resettable_settings_snapshot.cc
@@ -6,6 +6,7 @@
#include "base/json/json_writer.h"
#include "base/prefs/pref_service.h"
+#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/feedback/feedback_data.h"
#include "chrome/browser/feedback/feedback_util.h"
#include "chrome/browser/profiles/profile.h"
@@ -20,6 +21,7 @@ const char kProfileResetFeedbackBucket[] = "ProfileResetReport";
// Dictionary keys for feedback report.
const char kDefaultSearchEnginePath[] = "default_search_engine";
+const char kEnabledExtensions[] = "enabled_extensions";
const char kHomepageIsNewTabPage[] = "homepage_is_ntp";
const char kHomepagePath[] = "homepage";
const char kStartupTypePath[] = "startup_type";
@@ -43,11 +45,23 @@ ResettableSettingsSnapshot::ResettableSettingsSnapshot(Profile* profile)
TemplateURL* dse = service->GetDefaultSearchProvider();
if (dse)
dse_url_ = dse->url();
+
+ ExtensionService* extension_service = profile->GetExtensionService();
+ DCHECK(extension_service);
+ const ExtensionSet* enabled_ext = extension_service->extensions();
+ enabled_extensions_.reserve(enabled_ext->size());
+
+ for (ExtensionSet::const_iterator it = enabled_ext->begin();
+ it != enabled_ext->end(); ++it)
+ enabled_extensions_.push_back((*it)->id());
+
+ // ExtensionSet is sorted but it seems to be an implementation detail.
+ std::sort(enabled_extensions_.begin(), enabled_extensions_.end());
}
ResettableSettingsSnapshot::~ResettableSettingsSnapshot() {}
-void ResettableSettingsSnapshot::SubtractStartupURLs(
+void ResettableSettingsSnapshot::Subtract(
const ResettableSettingsSnapshot& snapshot) {
std::vector<GURL> urls;
std::set_difference(startup_.urls.begin(), startup_.urls.end(),
@@ -55,6 +69,13 @@ void ResettableSettingsSnapshot::SubtractStartupURLs(
snapshot.startup_.urls.end(),
std::back_inserter(urls));
startup_.urls.swap(urls);
+
+ std::vector<std::string> extensions;
+ std::set_difference(enabled_extensions_.begin(), enabled_extensions_.end(),
+ snapshot.enabled_extensions_.begin(),
+ snapshot.enabled_extensions_.end(),
+ std::back_inserter(extensions));
+ enabled_extensions_.swap(extensions);
}
int ResettableSettingsSnapshot::FindDifferentFields(
@@ -77,7 +98,10 @@ int ResettableSettingsSnapshot::FindDifferentFields(
if (dse_url_ != snapshot.dse_url_)
bit_mask |= DSE_URL;
- COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 31,
+ if (enabled_extensions_ != snapshot.enabled_extensions_)
+ bit_mask |= EXTENSIONS;
+
+ COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 63,
add_new_field_here);
return bit_mask;
@@ -108,7 +132,16 @@ std::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot,
if (field_mask & ResettableSettingsSnapshot::DSE_URL)
dict.SetString(kDefaultSearchEnginePath, snapshot.dse_url());
- COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 31,
+ if (field_mask & ResettableSettingsSnapshot::EXTENSIONS) {
+ ListValue* list = new ListValue;
+ const std::vector<std::string>& extensions = snapshot.enabled_extensions();
+ for (std::vector<std::string>::const_iterator i = extensions.begin();
+ i != extensions.end(); ++i)
+ list->AppendString(*i);
+ dict.Set(kEnabledExtensions, list);
+ }
+
+ COMPILE_ASSERT(ResettableSettingsSnapshot::ALL_FIELDS == 63,
serialize_new_field_here);
std::string json;
diff --git a/chrome/browser/profile_resetter/resettable_settings_snapshot.h b/chrome/browser/profile_resetter/resettable_settings_snapshot.h
index 93aaf48..9fcf1cb 100644
--- a/chrome/browser/profile_resetter/resettable_settings_snapshot.h
+++ b/chrome/browser/profile_resetter/resettable_settings_snapshot.h
@@ -19,9 +19,10 @@ class ResettableSettingsSnapshot {
HOMEPAGE = 1 << 2,
HOMEPAGE_IS_NTP = 1 << 3,
DSE_URL = 1 << 4,
+ EXTENSIONS = 1 << 5,
ALL_FIELDS = STARTUP_URLS | STARTUP_TYPE | HOMEPAGE |
- HOMEPAGE_IS_NTP | DSE_URL,
+ HOMEPAGE_IS_NTP | DSE_URL | EXTENSIONS,
};
explicit ResettableSettingsSnapshot(Profile* profile);
@@ -38,8 +39,14 @@ class ResettableSettingsSnapshot {
const std::string& dse_url() const { return dse_url_; }
+ const std::vector<std::string>& enabled_extensions() const {
+ return enabled_extensions_;
+ }
+
// Substitutes |startup_.urls| with |startup_.urls|\|snapshot.startup_.urls|.
- void SubtractStartupURLs(const ResettableSettingsSnapshot& snapshot);
+ // Substitutes |enabled_extensions_| with
+ // |enabled_extensions_|\|snapshot.enabled_extensions_|.
+ void Subtract(const ResettableSettingsSnapshot& snapshot);
// For each member 'm' compares |this->m| with |snapshot.m| and sets the
// corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of
@@ -58,6 +65,9 @@ class ResettableSettingsSnapshot {
// Default search engine.
std::string dse_url_;
+ // Enabled extension ids. Always sorted.
+ std::vector<std::string> enabled_extensions_;
+
DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot);
};
diff --git a/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc b/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc
index 6222f91..a726a26 100644
--- a/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc
+++ b/chrome/browser/ui/webui/options/reset_profile_settings_handler.cc
@@ -95,7 +95,7 @@ void ResetProfileSettingsHandler::OnResetProfileSettingsDone() {
ResettableSettingsSnapshot current_snapshot(profile);
int difference = setting_snapshot_->FindDifferentFields(current_snapshot);
if (difference) {
- setting_snapshot_->SubtractStartupURLs(current_snapshot);
+ setting_snapshot_->Subtract(current_snapshot);
std::string report = SerializeSettingsReport(*setting_snapshot_,
difference);
SendSettingsFeedback(report, profile);