Index: chrome/browser/sync/test/integration/themes_helper.cc |
diff --git a/chrome/browser/sync/test/integration/themes_helper.cc b/chrome/browser/sync/test/integration/themes_helper.cc |
index 324745e4cecbf77533e6996c0186d3cf03540d33..b9170012cae2d81764f4f1ff0ab519dc2a7df68f 100644 |
--- a/chrome/browser/sync/test/integration/themes_helper.cc |
+++ b/chrome/browser/sync/test/integration/themes_helper.cc |
@@ -4,19 +4,15 @@ |
#include "chrome/browser/sync/test/integration/themes_helper.h" |
-#include "base/callback.h" |
#include "base/logging.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/stringprintf.h" |
#include "chrome/browser/chrome_notification_types.h" |
-#include "chrome/browser/sync/test/integration/status_change_checker.h" |
#include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
#include "chrome/browser/sync/test/integration/sync_extension_helper.h" |
#include "chrome/browser/themes/theme_service.h" |
#include "chrome/browser/themes/theme_service_factory.h" |
#include "components/crx_file/id_util.h" |
-#include "content/public/browser/notification_observer.h" |
-#include "content/public/browser/notification_registrar.h" |
#include "content/public/browser/notification_source.h" |
#include "extensions/common/manifest.h" |
@@ -75,42 +71,25 @@ void UseSystemTheme(Profile* profile) { |
GetThemeService(profile)->UseSystemTheme(); |
} |
-namespace { |
+// Helper function to let us bind this functionality into a base::Callback. |
+bool UsingSystemThemeFunc(ThemeService* theme_service) { |
+ return theme_service->UsingSystemTheme(); |
+} |
-// Helper to wait until the specified theme is pending for install on the |
-// specified profile. |
-// |
-// The themes sync integration tests don't actually install any custom themes, |
-// but they do occasionally check that the ThemeService attempts to install |
-// synced themes. |
-class ThemePendingInstallChecker : public StatusChangeChecker, |
- public content::NotificationObserver { |
- public: |
- ThemePendingInstallChecker(Profile* profile, const std::string& theme); |
- ~ThemePendingInstallChecker() override; |
- |
- // Implementation of StatusChangeChecker. |
- std::string GetDebugMessage() const override; |
- bool IsExitConditionSatisfied() override; |
- |
- // Implementation of content::NotificationObserver. |
- void Observe(int type, |
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) override; |
- |
- // Waits until the condition to be met or a timeout occurs. |
- void Wait(); |
- |
- private: |
- Profile* profile_; |
- const std::string& theme_; |
- |
- content::NotificationRegistrar registrar_; |
-}; |
+// Helper function to let us bind this functionality into a base::Callback. |
+bool UsingDefaultThemeFunc(ThemeService* theme_service) { |
+ return theme_service->UsingDefaultTheme(); |
+} |
+ |
+} // namespace themes_helper |
ThemePendingInstallChecker::ThemePendingInstallChecker(Profile* profile, |
const std::string& theme) |
: profile_(profile), theme_(theme) { |
+ // We'll check to see if the condition is met whenever the extension system |
+ // tries to contact the web store. |
+ registrar_.Add(this, extensions::NOTIFICATION_EXTENSION_UPDATING_STARTED, |
+ content::Source<Profile>(profile_)); |
} |
ThemePendingInstallChecker::~ThemePendingInstallChecker() { |
@@ -122,7 +101,7 @@ std::string ThemePendingInstallChecker::GetDebugMessage() const { |
} |
bool ThemePendingInstallChecker::IsExitConditionSatisfied() { |
- return ThemeIsPendingInstall(profile_, theme_); |
+ return themes_helper::ThemeIsPendingInstall(profile_, theme_); |
} |
void ThemePendingInstallChecker::Observe( |
@@ -133,62 +112,6 @@ void ThemePendingInstallChecker::Observe( |
CheckExitCondition(); |
} |
-void ThemePendingInstallChecker::Wait() { |
- // We'll check to see if the condition is met whenever the extension system |
- // tries to contact the web store. |
- registrar_.Add(this, |
- extensions::NOTIFICATION_EXTENSION_UPDATING_STARTED, |
- content::Source<Profile>(profile_)); |
- |
- if (IsExitConditionSatisfied()) { |
- return; |
- } |
- |
- StartBlockingWait(); |
-} |
- |
-} // namespace |
- |
-bool AwaitThemeIsPendingInstall(Profile* profile, const std::string& theme) { |
- ThemePendingInstallChecker checker(profile, theme); |
- checker.Wait(); |
- return !checker.TimedOut(); |
-} |
- |
-namespace { |
- |
-// Helper to wait until a given condition is met, checking every time the |
-// current theme changes. |
-// |
-// The |exit_condition_| closure may be invoked zero or more times. |
-class ThemeConditionChecker : public StatusChangeChecker, |
- public content::NotificationObserver { |
- public: |
- ThemeConditionChecker(Profile* profile, |
- const std::string& debug_message_, |
- base::Callback<bool(ThemeService*)> exit_condition); |
- ~ThemeConditionChecker() override; |
- |
- // Implementation of StatusChangeChecker. |
- std::string GetDebugMessage() const override; |
- bool IsExitConditionSatisfied() override; |
- |
- // Implementation of content::NotificationObserver. |
- void Observe(int type, |
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) override; |
- |
- // Waits until the condition to be met or a timeout occurs. |
- void Wait(); |
- |
- private: |
- Profile* profile_; |
- const std::string debug_message_; |
- base::Callback<bool(ThemeService*)> exit_condition_; |
- |
- content::NotificationRegistrar registrar_; |
-}; |
- |
ThemeConditionChecker::ThemeConditionChecker( |
Profile* profile, |
const std::string& debug_message, |
@@ -196,6 +119,8 @@ ThemeConditionChecker::ThemeConditionChecker( |
: profile_(profile), |
debug_message_(debug_message), |
exit_condition_(exit_condition) { |
+ registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
+ content::Source<ThemeService>(GetThemeService(profile_))); |
} |
ThemeConditionChecker::~ThemeConditionChecker() { |
@@ -217,46 +142,13 @@ void ThemeConditionChecker::Observe( |
CheckExitCondition(); |
} |
-void ThemeConditionChecker::Wait() { |
- registrar_.Add(this, |
- chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
- content::Source<ThemeService>(GetThemeService(profile_))); |
- |
- if (IsExitConditionSatisfied()) { |
- return; |
- } |
- |
- StartBlockingWait(); |
-} |
- |
-// Helper function to let us bind this functionality into a base::Callback. |
-bool UsingSystemThemeFunc(ThemeService* theme_service) { |
- return theme_service->UsingSystemTheme(); |
-} |
- |
-// Helper function to let us bind this functionality into a base::Callback. |
-bool UsingDefaultThemeFunc(ThemeService* theme_service) { |
- return theme_service->UsingDefaultTheme(); |
-} |
- |
-} // namespace |
- |
-bool AwaitUsingSystemTheme(Profile* profile) { |
- ThemeConditionChecker checker( |
- profile, |
- std::string("Waiting until profile is using system theme"), |
- base::Bind(&UsingSystemThemeFunc)); |
- checker.Wait(); |
- return !checker.TimedOut(); |
-} |
+SystemThemeChecker::SystemThemeChecker(Profile* profile) |
+ : ThemeConditionChecker(profile, |
+ "Waiting until profile is using system theme", |
+ base::Bind(&themes_helper::UsingSystemThemeFunc)) {} |
-bool AwaitUsingDefaultTheme(Profile* profile) { |
- ThemeConditionChecker checker( |
- profile, |
- std::string("Waiting until profile is using default theme"), |
- base::Bind(&UsingDefaultThemeFunc)); |
- checker.Wait(); |
- return !checker.TimedOut(); |
+DefaultThemeChecker::DefaultThemeChecker(Profile* profile) |
+ : ThemeConditionChecker(profile, |
+ "Waiting until profile is using default theme", |
+ base::Bind(&themes_helper::UsingDefaultThemeFunc)) { |
} |
- |
-} // namespace themes_helper |