summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-15 01:19:11 +0000
committertim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-15 01:19:11 +0000
commit48352c11fe849f7f786c43bdfe293dc2c58d12c5 (patch)
tree57708d7e211d7cbcf2b81b1395740f5859a62aa1
parent20cc723d102acb16b61789714bbf443ba3d7d1f5 (diff)
downloadchromium_src-48352c11fe849f7f786c43bdfe293dc2c58d12c5.zip
chromium_src-48352c11fe849f7f786c43bdfe293dc2c58d12c5.tar.gz
chromium_src-48352c11fe849f7f786c43bdfe293dc2c58d12c5.tar.bz2
Some personalization cleanup:
- Removes ProfilePersonalization (which is why the CL appears huge) - Makes Profile do the work ProfilePersonalization did for creating PSS - cloudy:stats > about:sync - Removes the cloudy:// scheme and uses chrome:// for resources. (Note SyncResourcesSource is a straight copy of CloudyResourceSource). - Moves prefs and switches to pref_names and chrome_switches. BUG=none TEST=ProfileSyncServiceTest, LiveBookmarkSyncTests, SyncSetupWizardTest Review URL: http://codereview.chromium.org/164544 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23505 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_profile_impl.h4
-rw-r--r--chrome/browser/browser_about_handler.cc6
-rw-r--r--chrome/browser/dom_ui/chrome_url_data_manager.cc17
-rw-r--r--chrome/browser/dom_ui/new_tab_page_sync_handler.cc11
-rw-r--r--chrome/browser/dom_ui/new_tab_ui.cc2
-rw-r--r--chrome/browser/gtk/options/options_window_gtk.cc10
-rw-r--r--chrome/browser/profile.cc38
-rw-r--r--chrome/browser/profile.h17
-rw-r--r--chrome/browser/sync/personalization.cc195
-rw-r--r--chrome/browser/sync/personalization.h58
-rw-r--r--chrome/browser/sync/profile_sync_service.cc58
-rw-r--r--chrome/browser/sync/profile_sync_service.h14
-rw-r--r--chrome/browser/sync/profile_sync_service_unittest.cc12
-rw-r--r--chrome/browser/sync/resources/setup_flow.html4
-rw-r--r--chrome/browser/sync/sync_status_ui_helper.cc3
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc12
-rw-r--r--chrome/browser/views/options/content_page_view.cc14
-rw-r--r--chrome/browser/views/sync/sync_setup_flow.cc5
-rw-r--r--chrome/browser/views/sync/sync_setup_flow.h2
-rw-r--r--chrome/browser/views/sync/sync_setup_wizard.cc66
-rw-r--r--chrome/browser/views/sync/sync_setup_wizard_unittest.cc31
-rw-r--r--chrome/browser/views/toolbar_view.cc5
-rw-r--r--chrome/common/chrome_switches.cc3
-rw-r--r--chrome/common/chrome_switches.h2
-rw-r--r--chrome/common/pref_names.cc6
-rw-r--r--chrome/common/pref_names.h3
-rw-r--r--chrome/common/url_constants.cc6
-rw-r--r--chrome/common/url_constants.h7
-rw-r--r--chrome/test/live_sync/live_bookmarks_sync_test.cc5
-rw-r--r--chrome/test/live_sync/live_bookmarks_sync_test.h7
-rw-r--r--chrome/test/live_sync/profile_sync_service_test_harness.cc4
-rw-r--r--chrome/test/testing_profile.h4
32 files changed, 229 insertions, 402 deletions
diff --git a/chrome/browser/automation/automation_profile_impl.h b/chrome/browser/automation/automation_profile_impl.h
index 0af0371..2262d68 100644
--- a/chrome/browser/automation/automation_profile_impl.h
+++ b/chrome/browser/automation/automation_profile_impl.h
@@ -152,8 +152,8 @@ class AutomationProfileImpl : public Profile {
}
#ifdef CHROME_PERSONALIZATION
- virtual ProfilePersonalization* GetProfilePersonalization() {
- return original_profile_->GetProfilePersonalization();
+ virtual ProfileSyncService* GetProfileSyncService() {
+ return original_profile_->GetProfileSyncService();
}
#endif
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc
index 4b8da31..505f2b3 100644
--- a/chrome/browser/browser_about_handler.cc
+++ b/chrome/browser/browser_about_handler.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/net/dns_global.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/sync/personalization.h"
#include "chrome/common/histogram_synchronizer.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/pref_names.h"
@@ -64,6 +65,7 @@ const char kVersionPath[] = "version";
const char kCreditsPath[] = "credits";
const char kTermsPath[] = "terms";
const char kLinuxSplash[] = "linux-splash";
+const char kSyncPath[] = "sync";
// Points to the singleton AboutSource object, if any.
ChromeURLDataManager::DataSource* about_source = NULL;
@@ -436,6 +438,10 @@ void AboutSource::StartDataRequest(const std::string& path_raw,
response = AboutCredits();
} else if (path == kTermsPath) {
response = AboutTerms();
+ } else if (path == kSyncPath) {
+#ifdef CHROME_PERSONALIZATION
+ response = Personalization::AboutSync();
+#endif
}
#if defined(OS_LINUX)
else if (path == kLinuxSplash) {
diff --git a/chrome/browser/dom_ui/chrome_url_data_manager.cc b/chrome/browser/dom_ui/chrome_url_data_manager.cc
index dfc08ce..d605fe3 100644
--- a/chrome/browser/dom_ui/chrome_url_data_manager.cc
+++ b/chrome/browser/dom_ui/chrome_url_data_manager.cc
@@ -12,12 +12,6 @@
#include "base/thread.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
-#ifdef CHROME_PERSONALIZATION
-// TODO(timsteele): Remove all CHROME_PERSONALIZATION code in this file.
-// It is only temporarily needed to configure some personalization data sources
-// that will go away soon.
-#include "chrome/browser/sync/personalization.h"
-#endif
#include "chrome/common/chrome_paths.h"
#include "chrome/common/ref_counted_util.h"
#include "chrome/common/url_constants.h"
@@ -118,11 +112,6 @@ void RegisterURLRequestChromeJob() {
&ChromeURLDataManager::Factory);
URLRequest::RegisterProtocolFactory(chrome::kPrintScheme,
&ChromeURLDataManager::Factory);
-#ifdef CHROME_PERSONALIZATION
- url_util::AddStandardScheme(kPersonalizationScheme);
- URLRequest::RegisterProtocolFactory(kPersonalizationScheme,
- &ChromeURLDataManager::Factory);
-#endif
}
void UnregisterURLRequestChromeJob() {
@@ -137,13 +126,7 @@ void UnregisterURLRequestChromeJob() {
void ChromeURLDataManager::URLToRequest(const GURL& url,
std::string* source_name,
std::string* path) {
-#ifdef CHROME_PERSONALIZATION
- DCHECK(url.SchemeIs(kChromeURLScheme) ||
- url.SchemeIs(kPersonalizationScheme) ||
- url.SchemeIs(chrome::kPrintScheme));
-#else
DCHECK(url.SchemeIs(kChromeURLScheme) || url.SchemeIs(chrome::kPrintScheme));
-#endif
if (!url.is_valid()) {
NOTREACHED();
diff --git a/chrome/browser/dom_ui/new_tab_page_sync_handler.cc b/chrome/browser/dom_ui/new_tab_page_sync_handler.cc
index b2220fa..83bca5e 100644
--- a/chrome/browser/dom_ui/new_tab_page_sync_handler.cc
+++ b/chrome/browser/dom_ui/new_tab_page_sync_handler.cc
@@ -76,9 +76,8 @@ NewTabPageSyncHandler::~NewTabPageSyncHandler() {
}
DOMMessageHandler* NewTabPageSyncHandler::Attach(DOMUI* dom_ui) {
- Profile* p = dom_ui->GetProfile();
- sync_service_ = p->GetProfilePersonalization()->sync_service();
- DCHECK(sync_service_);
+ sync_service_ = dom_ui->GetProfile()->GetProfileSyncService();
+ DCHECK(sync_service_); // This shouldn't get called by an incognito NTP.
sync_service_->AddObserver(this);
return DOMMessageHandler::Attach(dom_ui);
}
@@ -101,7 +100,7 @@ void NewTabPageSyncHandler::HandleResizeP13N(const Value* value) {
void NewTabPageSyncHandler::BuildAndSendSyncStatus() {
DCHECK(!waiting_for_initial_page_load_);
- if (!sync_service_->IsSyncEnabledByUser() &&
+ if (!sync_service_->HasSyncSetupCompleted() &&
!sync_service_->SetupInProgress()) {
// Clear the page status, without showing the promotion or sync ui.
// TODO(timsteele): This is fine, but if the page is refreshed or another
@@ -130,7 +129,7 @@ void NewTabPageSyncHandler::BuildAndSendSyncStatus() {
void NewTabPageSyncHandler::HandleGetSyncMessage(const Value* value) {
waiting_for_initial_page_load_ = false;
- if (!sync_service_->IsSyncEnabledByUser() &&
+ if (!sync_service_->HasSyncSetupCompleted() &&
!sync_service_->SetupInProgress()) {
if (Personalization::IsGoogleGAIACookieInstalled()) {
// Sync has not been enabled, and the user has logged in to GAIA.
@@ -145,7 +144,7 @@ void NewTabPageSyncHandler::HandleGetSyncMessage(const Value* value) {
void NewTabPageSyncHandler::HandleSyncLinkClicked(const Value* value) {
DCHECK(!waiting_for_initial_page_load_);
- if (sync_service_->IsSyncEnabledByUser()) {
+ if (sync_service_->HasSyncSetupCompleted()) {
// User clicked 'Login again' link to re-authenticate.
sync_service_->ShowLoginDialog();
} else {
diff --git a/chrome/browser/dom_ui/new_tab_ui.cc b/chrome/browser/dom_ui/new_tab_ui.cc
index fae0081..b3e246e 100644
--- a/chrome/browser/dom_ui/new_tab_ui.cc
+++ b/chrome/browser/dom_ui/new_tab_ui.cc
@@ -1551,7 +1551,7 @@ NewTabUI::NewTabUI(TabContents* contents)
}
#ifdef CHROME_PERSONALIZATION
- if (Personalization::IsSyncEnabled(GetProfile())) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSync)) {
AddMessageHandler(Personalization::CreateNewTabPageHandler(this));
}
#endif
diff --git a/chrome/browser/gtk/options/options_window_gtk.cc b/chrome/browser/gtk/options/options_window_gtk.cc
index 23dd38e..8473b9d 100644
--- a/chrome/browser/gtk/options/options_window_gtk.cc
+++ b/chrome/browser/gtk/options/options_window_gtk.cc
@@ -116,16 +116,6 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile)
gtk_label_new(
l10n_util::GetStringUTF8(IDS_OPTIONS_CONTENT_TAB_LABEL).c_str()));
-#ifdef CHROME_PERSONALIZATION
- if (Personalization::IsSyncEnabled(profile)) {
- gtk_notebook_append_page(
- GTK_NOTEBOOK(notebook_),
- gtk_label_new("TODO personalization"),
- gtk_label_new(
- l10n_util::GetStringUTF8(IDS_OPTIONS_USER_DATA_TAB_LABEL).c_str()));
- }
-#endif
-
gtk_notebook_append_page(
GTK_NOTEBOOK(notebook_),
advanced_page_.get_page_widget(),
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 6186394..94b4e60 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -31,6 +31,7 @@
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/browser/spellchecker.h"
#include "chrome/browser/ssl/ssl_host_state.h"
+#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/thumbnail_store.h"
#include "chrome/browser/visitedlink_master.h"
#include "chrome/browser/visitedlink_event_listener.h"
@@ -380,11 +381,9 @@ class OffTheRecordProfileImpl : public Profile,
return profile_->GetBookmarkModel();
}
-#ifdef CHROME_PERSONALIZATION
- virtual ProfilePersonalization* GetProfilePersonalization() {
- return profile_->GetProfilePersonalization();
+ virtual ProfileSyncService* GetProfileSyncService() {
+ return NULL;
}
-#endif
virtual bool IsSameProfile(Profile* profile) {
if (profile == static_cast<Profile*>(this))
@@ -516,11 +515,6 @@ ProfileImpl::ProfileImpl(const FilePath& path)
prefs->AddPrefObserver(prefs::kEnableSpellCheck, this);
prefs->AddPrefObserver(prefs::kEnableAutoSpellCorrect, this);
-#ifdef CHROME_PERSONALIZATION
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSync))
- personalization_.reset(Personalization::CreateProfilePersonalization(this));
-#endif
-
if (CommandLine::ForCurrentProcess()->
HasSwitch(switches::kPrivacyBlacklist)) {
std::wstring option = CommandLine::ForCurrentProcess()->GetSwitchValue(
@@ -541,6 +535,10 @@ ProfileImpl::ProfileImpl(const FilePath& path)
// Listen for theme installation.
registrar_.Add(this, NotificationType::THEME_INSTALLED,
NotificationService::AllSources());
+
+ // Listen for bookmark model load, to bootstrap the sync service.
+ registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
+ Source<Profile>(this));
}
void ProfileImpl::InitExtensions() {
@@ -633,7 +631,7 @@ ProfileImpl::~ProfileImpl() {
prefs->RemovePrefObserver(prefs::kEnableAutoSpellCorrect, this);
#ifdef CHROME_PERSONALIZATION
- personalization_.reset();
+ sync_service_.reset();
#endif
// Both HistoryService and WebDataService maintain threads for background
@@ -1210,6 +1208,10 @@ void ProfileImpl::Observe(NotificationType type,
} else if (NotificationType::THEME_INSTALLED == type) {
Extension* extension = Details<Extension>(details).ptr();
SetTheme(extension);
+ } else if (NotificationType::BOOKMARK_MODEL_LOADED == type) {
+ GetProfileSyncService(); // Causes lazy-load if sync is enabled.
+ registrar_.Remove(this, NotificationType::BOOKMARK_MODEL_LOADED,
+ Source<Profile>(this));
}
}
@@ -1217,8 +1219,20 @@ void ProfileImpl::StopCreateSessionServiceTimer() {
create_session_service_timer_.Stop();
}
+ProfileSyncService* ProfileImpl::GetProfileSyncService() {
#ifdef CHROME_PERSONALIZATION
-ProfilePersonalization* ProfileImpl::GetProfilePersonalization() {
- return personalization_.get();
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSync)) {
+ if (!sync_service_.get())
+ InitSyncService();
+ return sync_service_.get();
+ }
+#endif
+ return NULL;
}
+
+void ProfileImpl::InitSyncService() {
+#ifdef CHROME_PERSONALIZATION
+ sync_service_.reset(new ProfileSyncService(this));
+ sync_service_->Initialize();
#endif
+}
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index a305888..318c6e2 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -15,9 +15,6 @@
#include "base/file_path.h"
#include "base/scoped_ptr.h"
#include "base/timer.h"
-#ifdef CHROME_PERSONALIZATION
-#include "chrome/browser/sync/personalization.h"
-#endif
#include "chrome/browser/web_resource/web_resource_service.h"
#include "chrome/common/notification_registrar.h"
@@ -37,6 +34,7 @@ class HistoryService;
class NavigationController;
class PasswordStore;
class PrefService;
+class ProfileSyncService;
class SessionService;
class SpellChecker;
class SSLHostState;
@@ -258,9 +256,8 @@ class Profile {
// Returns the BookmarkModel, creating if not yet created.
virtual BookmarkModel* GetBookmarkModel() = 0;
-#ifdef CHROME_PERSONALIZATION
- virtual ProfilePersonalization* GetProfilePersonalization() = 0;
-#endif
+ // Returns the ProfileSyncService, creating if not yet created.
+ virtual ProfileSyncService* GetProfileSyncService() = 0;
// Return whether 2 profiles are the same. 2 profiles are the same if they
// represent the same profile. This can happen if there is pointer equality
@@ -383,9 +380,9 @@ class ProfileImpl : public Profile,
virtual void MarkAsCleanShutdown();
virtual void InitExtensions();
virtual void InitWebResources();
-#ifdef CHROME_PERSONALIZATION
- virtual ProfilePersonalization* GetProfilePersonalization();
-#endif
+ virtual ProfileSyncService* GetProfileSyncService();
+ void InitSyncService();
+
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
@@ -436,7 +433,7 @@ class ProfileImpl : public Profile,
scoped_refptr<WebResourceService> web_resource_service_;
#ifdef CHROME_PERSONALIZATION
- scoped_ptr<ProfilePersonalization> personalization_;
+ scoped_ptr<ProfileSyncService> sync_service_;
#endif
ChromeURLRequestContext* request_context_;
diff --git a/chrome/browser/sync/personalization.cc b/chrome/browser/sync/personalization.cc
index 8f0fc76..866149f 100644
--- a/chrome/browser/sync/personalization.cc
+++ b/chrome/browser/sync/personalization.cc
@@ -17,18 +17,19 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/browser_url_handler.h"
#include "chrome/browser/command_updater.h"
+#include "chrome/browser/dom_ui/new_tab_page_sync_handler.h"
#include "chrome/browser/options_window.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/profile_manager.h"
+#include "chrome/browser/sync/auth_error_state.h"
+#include "chrome/browser/sync/personalization_strings.h"
+#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_service.h"
-#include "chrome/browser/dom_ui/new_tab_page_sync_handler.h"
-#include "chrome/browser/sync/personalization_strings.h"
-#include "chrome/browser/sync/auth_error_state.h"
-#include "chrome/browser/sync/profile_sync_service.h"
+#include "chrome/common/url_constants.h"
#include "googleurl/src/gurl.h"
#include "grit/app_resources.h"
#include "grit/browser_resources.h"
@@ -36,34 +37,6 @@
using sync_api::SyncManager;
-// TODO(ncarter): Move these switches into chrome_switches. They are here
-// now because we want to keep them secret during early development.
-namespace switches {
- const wchar_t kSyncServiceURL[] = L"sync-url";
- const wchar_t kSyncServicePort[] = L"sync-port";
- const wchar_t kSyncUserForTest[] = L"sync-user-for-test";
- const wchar_t kSyncPasswordForTest[] = L"sync-password-for-test";
-}
-
-// TODO(munjal): Move these preferences to common/pref_names.h.
-// Names of various preferences.
-namespace prefs {
- const wchar_t kSyncPath[] = L"sync";
- const wchar_t kSyncLastSyncedTime[] = L"sync.last_synced_time";
- const wchar_t kSyncUserName[] = L"sync.username";
- const wchar_t kSyncHasSetupCompleted[] = L"sync.has_setup_completed";
-}
-
-// Top-level path for our network layer DataSource.
-static const char kCloudyResourcesPath[] = "resources";
-// Path for cloudy:stats page.
-static const char kCloudyStatsPath[] = "stats";
-// Path for the gaia sync login dialog.
-static const char kCloudyGaiaLoginPath[] = "gaialogin";
-static const char kCloudyMergeAndSyncPath[] = "mergeandsync";
-static const char kCloudyThrobberPath[] = "throbber.png";
-static const char kCloudySetupFlowPath[] = "setup";
-
namespace Personalization {
static std::wstring MakeAuthErrorText(AuthErrorState state) {
@@ -79,58 +52,13 @@ static std::wstring MakeAuthErrorText(AuthErrorState state) {
}
}
-bool IsSyncEnabled(Profile* profile) {
- const CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (!command_line->HasSwitch(switches::kEnableSync))
- return false;
- return profile && profile->GetProfilePersonalization() != NULL;
-}
-
bool NeedsDOMUI(const GURL& url) {
- return url.SchemeIs(kPersonalizationScheme) &&
- (url.path().find(kCloudyGaiaLoginPath) != std::string::npos) ||
- (url.path().find(kCloudySetupFlowPath) != std::string::npos) ||
- (url.path().find(kCloudyMergeAndSyncPath) != std::string::npos);
+ return url.SchemeIs(chrome::kChromeUIScheme) &&
+ (url.path().find(chrome::kSyncGaiaLoginPath) != std::string::npos) ||
+ (url.path().find(chrome::kSyncSetupFlowPath) != std::string::npos) ||
+ (url.path().find(chrome::kSyncMergeAndSyncPath) != std::string::npos);
}
-class CloudyResourceSource : public ChromeURLDataManager::DataSource {
- public:
- CloudyResourceSource()
- : DataSource(kCloudyResourcesPath, MessageLoop::current()) {
- }
- virtual ~CloudyResourceSource() { }
-
- virtual void StartDataRequest(const std::string& path, int request_id);
-
- virtual std::string GetMimeType(const std::string& path) const {
- if (path == kCloudyThrobberPath)
- return "image/png";
- else
- return "text/html";
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(CloudyResourceSource);
-};
-
-class CloudyStatsSource : public ChromeURLDataManager::DataSource {
- public:
- CloudyStatsSource() : DataSource(kCloudyStatsPath, MessageLoop::current()) {
- }
- virtual ~CloudyStatsSource() { }
- virtual void StartDataRequest(const std::string& path, int request_id) {
- std::string response(MakeCloudyStats());
- scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
- html_bytes->data.resize(response.size());
- std::copy(response.begin(), response.end(), html_bytes->data.begin());
- SendResponse(request_id, html_bytes);
- }
- virtual std::string GetMimeType(const std::string& path) const {
- return "text/html";
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(CloudyStatsSource);
-};
-
DOMMessageHandler* CreateNewTabPageHandler(DOMUI* dom_ui) {
return (new NewTabPageSyncHandler())->Attach(dom_ui);
}
@@ -154,9 +82,10 @@ void HandleMenuItemClick(Profile* p) {
// The menu item is enabled either when the sync is not enabled by the user
// or when it's enabled but the user name is empty. In the former case enable
// sync. In the latter case, show the login dialog.
- ProfileSyncService* service = p->GetProfilePersonalization()->sync_service();
- DCHECK(service);
- if (service->IsSyncEnabledByUser()) {
+ ProfileSyncService* service = p->GetProfileSyncService();
+ if (!service)
+ return; // Incognito has no sync service (or TestingProfile, etc).
+ if (service->HasSyncSetupCompleted()) {
ShowOptionsWindow(OPTIONS_PAGE_CONTENT, OPTIONS_GROUP_NONE, p);
} else {
service->EnableForUser();
@@ -166,99 +95,8 @@ void HandleMenuItemClick(Profile* p) {
} // namespace Personalization
-class ProfilePersonalizationImpl : public ProfilePersonalization,
- public NotificationObserver {
- public:
- explicit ProfilePersonalizationImpl(Profile *p)
- : profile_(p) {
- // g_browser_process and/or io_thread may not exist during testing.
- if (g_browser_process && g_browser_process->io_thread()) {
- // Add our network layer data source for 'cloudy' URLs.
- // TODO(timsteele): This one belongs in BrowserAboutHandler.
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(&chrome_url_data_manager,
- &ChromeURLDataManager::AddDataSource,
- new Personalization::CloudyStatsSource()));
- g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(&chrome_url_data_manager,
- &ChromeURLDataManager::AddDataSource,
- new Personalization::CloudyResourceSource()));
- }
-
- registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
- Source<Profile>(profile_));
- }
- virtual ~ProfilePersonalizationImpl() {}
-
- // ProfilePersonalization implementation
- virtual ProfileSyncService* sync_service() {
- if (!sync_service_.get())
- InitSyncService();
- return sync_service_.get();
- }
-
- // NotificationObserver implementation.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
- DCHECK_EQ(type.value, NotificationType::BOOKMARK_MODEL_LOADED);
- if (!sync_service_.get())
- InitSyncService();
- registrar_.RemoveAll();
- }
-
- void InitSyncService() {
- sync_service_.reset(new ProfileSyncService(profile_));
- sync_service_->Initialize();
- }
-
- private:
- Profile* profile_;
- NotificationRegistrar registrar_;
- scoped_ptr<ProfileSyncService> sync_service_;
- DISALLOW_COPY_AND_ASSIGN(ProfilePersonalizationImpl);
-};
-
namespace Personalization {
-void CloudyResourceSource::StartDataRequest(const std::string& path_raw,
- int request_id) {
- scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
- if (path_raw == kCloudyThrobberPath) {
- ResourceBundle::GetSharedInstance().LoadImageResourceBytes(IDR_THROBBER,
- &html_bytes->data);
- SendResponse(request_id, html_bytes);
- return;
- }
-
- std::string response;
- if (path_raw == kCloudyGaiaLoginPath) {
- static const StringPiece html(ResourceBundle::GetSharedInstance()
- .GetRawDataResource(IDR_GAIA_LOGIN_HTML));
- response = html.as_string();
- } else if (path_raw == kCloudyMergeAndSyncPath) {
- static const StringPiece html(ResourceBundle::GetSharedInstance()
- .GetRawDataResource(IDR_MERGE_AND_SYNC_HTML));
- response = html.as_string();
- } else if (path_raw == kCloudySetupFlowPath) {
- static const StringPiece html(ResourceBundle::GetSharedInstance()
- .GetRawDataResource(IDR_SYNC_SETUP_FLOW_HTML));
- response = html.as_string();
- }
- // Send the response.
- html_bytes->data.resize(response.size());
- std::copy(response.begin(), response.end(), html_bytes->data.begin());
- SendResponse(request_id, html_bytes);
-}
-
-ProfilePersonalization* CreateProfilePersonalization(Profile* p) {
- return new ProfilePersonalizationImpl(p);
-}
-
-void CleanupProfilePersonalization(ProfilePersonalization* p) {
- if (p) delete p;
-}
-
static void AddBoolDetail(ListValue* details, const std::wstring& stat_name,
bool stat_value) {
DictionaryValue* val = new DictionaryValue;
@@ -275,17 +113,16 @@ static void AddIntDetail(ListValue* details, const std::wstring& stat_name,
details->Append(val);
}
-std::string MakeCloudyStats() {
+std::string AboutSync() {
FilePath user_data_dir;
if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir))
return std::string();
ProfileManager* profile_manager = g_browser_process->profile_manager();
Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
- ProfilePersonalization* p13n_profile = profile->GetProfilePersonalization();
- ProfileSyncService* service = p13n_profile->sync_service();
+ ProfileSyncService* service = profile->GetProfileSyncService();
DictionaryValue strings;
- if (!service->IsSyncEnabledByUser()) {
+ if (!service || !service->HasSyncSetupCompleted()) {
strings.SetString(L"summary", L"SYNC DISABLED");
} else {
SyncManager::Status full_status(service->QueryDetailedSyncStatus());
diff --git a/chrome/browser/sync/personalization.h b/chrome/browser/sync/personalization.h
index f278d28d..fb6a4ed 100644
--- a/chrome/browser/sync/personalization.h
+++ b/chrome/browser/sync/personalization.h
@@ -27,58 +27,15 @@ class ProfileSyncServiceObserver;
namespace views { class View; }
-// TODO(ncarter): Move these switches into chrome_switches. They are here
-// now because we want to keep them secret during early development.
-namespace switches {
-extern const wchar_t kSyncServiceURL[];
-extern const wchar_t kSyncServicePort[];
-extern const wchar_t kSyncUserForTest[];
-extern const wchar_t kSyncPasswordForTest[];
-}
-
-// Names of various preferences.
-// TODO(munjal): Move these preferences to common/pref_names.h.
-namespace prefs {
-extern const wchar_t kSyncPath[];
-extern const wchar_t kSyncLastSyncedTime[];
-extern const wchar_t kSyncUserName[];
-extern const wchar_t kSyncHasSetupCompleted[];
-}
-
-// Contains a profile sync service, which is initialized at profile creation.
-// A pointer to this class is passed as a handle.
-class ProfilePersonalization {
- public:
- ProfilePersonalization() {}
- virtual ~ProfilePersonalization() {}
-
- virtual ProfileSyncService* sync_service() = 0;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ProfilePersonalization);
-};
-
// Contains methods to perform Personalization-related tasks on behalf of the
// caller.
namespace Personalization {
-// Checks if P13N is globally disabled or not, and that |profile| has a valid
-// ProfilePersonalization member (it can be NULL for TestingProfiles).
-bool IsSyncEnabled(Profile* profile);
-
// Returns whether |url| should be loaded in a DOMUI.
bool NeedsDOMUI(const GURL& url);
-// Construct a new ProfilePersonalization and return it so the caller can take
-// ownership.
-ProfilePersonalization* CreateProfilePersonalization(Profile* p);
-
-// The caller of Create...() above should call this when the returned
-// ProfilePersonalization object should be deleted.
-void CleanupProfilePersonalization(ProfilePersonalization* p);
-
-// Handler for "cloudy:stats"
-std::string MakeCloudyStats();
+// Handler for "about:sync"
+std::string AboutSync();
// Construct a new DOMMessageHandler for the new tab page |dom_ui|.
DOMMessageHandler* CreateNewTabPageHandler(DOMUI* dom_ui);
@@ -94,16 +51,5 @@ std::wstring GetMenuItemInfoText(Browser* browser);
void HandleMenuItemClick(Profile* p);
} // namespace Personalization
-// The internal scheme used to retrieve HTML resources for personalization
-// related code (e.g cloudy:stats, GAIA login page).
-// We need to ensure the GAIA login HTML is loaded into an HTMLDialogContents.
-// Outside of p13n (for the time being) only "gears://" gives this (see
-// HtmlDialogContents::IsHtmlDialogUrl) for the application shortcut dialog.
-// TODO(timsteele): We should have a robust way to handle this to allow more
-// reuse of our HTML dialog code, perhaps by using a dedicated "dialog-resource"
-// scheme (chrome-resource is coupled to DOM_UI). Figure out if that is the best
-// course of action / pitch this idea to chromium-dev.
-static const char kPersonalizationScheme[] = "cloudy";
-
#endif // CHROME_BROWSER_SYNC_PERSONALIZATION_H_
#endif // CHROME_PERSONALIZATION
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
index 7e89449..4de8f38 100644
--- a/chrome/browser/sync/profile_sync_service.cc
+++ b/chrome/browser/sync/profile_sync_service.cc
@@ -25,6 +25,7 @@
#include "chrome/browser/sync/personalization.h"
#include "chrome/browser/sync/personalization_strings.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
#include "chrome/common/time_format.h"
#include "views/window/window.h"
@@ -32,8 +33,8 @@
using browser_sync::ModelAssociator;
using browser_sync::SyncBackendHost;
-// Default sync server URL.
-static const char kSyncServerUrl[] = "https://clients4.google.com/chrome-sync";
+// Default sync server URL.
+static const char kSyncServerUrl[] = "https://clients4.google.com/chrome-sync";
ProfileSyncService::ProfileSyncService(Profile* profile)
: last_auth_error_(AUTH_ERROR_NONE),
@@ -77,46 +78,18 @@ void ProfileSyncService::InitSettings() {
}
}
}
-
- if (command_line.HasSwitch(switches::kSyncServicePort)) {
- std::string port_str = WideToUTF8(command_line.GetSwitchValue(
- switches::kSyncServicePort));
- if (!port_str.empty()) {
- GURL::Replacements replacements;
- replacements.SetPortStr(port_str);
- sync_service_url_ = sync_service_url_.ReplaceComponents(replacements);
- }
- }
}
void ProfileSyncService::RegisterPreferences() {
PrefService* pref_service = profile_->GetPrefs();
- if (pref_service->IsPrefRegistered(prefs::kSyncUserName))
+ if (pref_service->IsPrefRegistered(prefs::kSyncLastSyncedTime))
return;
- pref_service->RegisterStringPref(prefs::kSyncUserName, std::wstring());
- pref_service->RegisterStringPref(prefs::kSyncLastSyncedTime, std::wstring());
+ pref_service->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0);
pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false);
}
-void ProfileSyncService::LoadPreferences() {
- PrefService* pref_service = profile_->GetPrefs();
- std::wstring last_synced_time_string =
- pref_service->GetString(prefs::kSyncLastSyncedTime);
- if (!last_synced_time_string.empty()) {
- int64 last_synced_time;
- bool success = StringToInt64(WideToUTF16(last_synced_time_string),
- &last_synced_time);
- if (success) {
- last_synced_time_ = base::Time::FromInternalValue(last_synced_time);
- } else {
- NOTREACHED();
- }
- }
-}
-
void ProfileSyncService::ClearPreferences() {
PrefService* pref_service = profile_->GetPrefs();
- pref_service->ClearPref(prefs::kSyncUserName);
pref_service->ClearPref(prefs::kSyncLastSyncedTime);
pref_service->ClearPref(prefs::kSyncHasSetupCompleted);
@@ -132,7 +105,8 @@ void ProfileSyncService::StartUp() {
if (backend_.get())
return;
- LoadPreferences();
+ last_synced_time_ = base::Time::FromInternalValue(
+ profile_->GetPrefs()->GetInt64(prefs::kSyncLastSyncedTime));
backend_.reset(new SyncBackendHost(this, profile_->GetPath()));
@@ -291,14 +265,21 @@ bool ProfileSyncService::MergeAndSyncAcceptanceNeeded() const {
model_associator_->SyncModelHasUserCreatedNodes();
}
-bool ProfileSyncService::IsSyncEnabledByUser() const {
+bool ProfileSyncService::HasSyncSetupCompleted() const {
return profile_->GetPrefs()->GetBoolean(prefs::kSyncHasSetupCompleted);
}
+void ProfileSyncService::SetSyncSetupCompleted() {
+ PrefService* prefs = profile()->GetPrefs();
+ prefs->SetBoolean(prefs::kSyncHasSetupCompleted, true);
+ prefs->ScheduleSavePersistentPrefs();
+}
+
void ProfileSyncService::UpdateLastSyncedTime() {
last_synced_time_ = base::Time::Now();
- profile_->GetPrefs()->SetString(prefs::kSyncLastSyncedTime,
- Int64ToWString(last_synced_time_.ToInternalValue()));
+ profile_->GetPrefs()->SetInt64(prefs::kSyncLastSyncedTime,
+ last_synced_time_.ToInternalValue());
+ profile_->GetPrefs()->ScheduleSavePersistentPrefs();
}
void ProfileSyncService::BookmarkNodeAdded(BookmarkModel* model,
@@ -519,11 +500,6 @@ int ProfileSyncService::CalculateBookmarkModelInsertionIndex(
void ProfileSyncService::OnBackendInitialized() {
backend_initialized_ = true;
-
- PrefService* pref_service = profile_->GetPrefs();
- DCHECK(pref_service->IsPrefRegistered(prefs::kSyncUserName));
- pref_service->SetString(prefs::kSyncUserName,
- UTF16ToWide(backend_->GetAuthenticatedUsername()));
StartProcessingChangesIfReady();
// The very first time the backend initializes is effectively the first time
diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h
index 0301647..a2f956b 100644
--- a/chrome/browser/sync/profile_sync_service.h
+++ b/chrome/browser/sync/profile_sync_service.h
@@ -88,7 +88,8 @@ class ProfileSyncService : public BookmarkModelObserver,
virtual void DisableForUser();
// Whether sync is enabled by user or not.
- bool IsSyncEnabledByUser() const;
+ bool HasSyncSetupCompleted() const;
+ void SetSyncSetupCompleted();
// BookmarkModelObserver implementation.
virtual void Loaded(BookmarkModel* model);
@@ -146,7 +147,7 @@ class ProfileSyncService : public BookmarkModelObserver,
// occurred preventing the action. We make it the duty of ProfileSyncService
// to open the dialog to easily ensure only one is ever showing.
bool SetupInProgress() const {
- return !IsSyncEnabledByUser() && WizardIsVisible();
+ return !HasSyncSetupCompleted() && WizardIsVisible();
}
bool WizardIsVisible() const { return wizard_.IsVisible(); }
void ShowLoginDialog();
@@ -221,6 +222,10 @@ class ProfileSyncService : public BookmarkModelObserver,
// |sync_disabled| indicates if syncing is being disabled or not.
void Shutdown(bool sync_disabled);
+ // Methods to register and remove preferences.
+ void RegisterPreferences();
+ void ClearPreferences();
+
// Tests need to override this.
virtual void InitializeBackend();
@@ -253,11 +258,6 @@ class ProfileSyncService : public BookmarkModelObserver,
// Initializes the various settings from the command line.
void InitSettings();
- // Methods to register, load and remove preferences.
- void RegisterPreferences();
- void LoadPreferences();
- void ClearPreferences();
-
// Treat the |index|th child of |parent| as a newly added node, and create a
// corresponding node in the sync domain using |trans|. All properties
// will be transferred to the new node. A node corresponding to |parent|
diff --git a/chrome/browser/sync/profile_sync_service_unittest.cc b/chrome/browser/sync/profile_sync_service_unittest.cc
index 5fc79f4..cc7f4c6 100644
--- a/chrome/browser/sync/profile_sync_service_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_unittest.cc
@@ -18,7 +18,7 @@
#include "chrome/browser/sync/engine/syncapi.h"
#include "chrome/browser/sync/glue/model_associator.h"
#include "chrome/browser/sync/profile_sync_service.h"
-#include "chrome/common/pref_service.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/test/testing_profile.h"
using std::vector;
@@ -68,12 +68,8 @@ class TestProfileSyncService : public ProfileSyncService {
public:
explicit TestProfileSyncService(Profile* profile)
: ProfileSyncService(profile) {
- PrefService* pref_service = profile->GetPrefs();
- if (pref_service->IsPrefRegistered(prefs::kSyncUserName))
- return;
- pref_service->RegisterStringPref(prefs::kSyncUserName, string16());
- pref_service->RegisterStringPref(prefs::kSyncLastSyncedTime, string16());
- pref_service->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, true);
+ RegisterPreferences();
+ SetSyncSetupCompleted();
}
virtual ~TestProfileSyncService() {
}
@@ -284,7 +280,7 @@ class ProfileSyncServiceTest : public testing::Test {
}
// The service may have already started sync automatically if it's already
// enabled by user once.
- if (!service_->IsSyncEnabledByUser())
+ if (!service_->HasSyncSetupCompleted())
service_->EnableForUser();
}
void StopSyncService(SaveOption save) {
diff --git a/chrome/browser/sync/resources/setup_flow.html b/chrome/browser/sync/resources/setup_flow.html
index 82db8a9..f818787 100644
--- a/chrome/browser/sync/resources/setup_flow.html
+++ b/chrome/browser/sync/resources/setup_flow.html
@@ -12,8 +12,8 @@
</HEAD>
<BODY style="margin:0; border:0;">
<iframe id="login" frameborder="0" width="100%" scrolling="no" height="100%"
- src="cloudy://resources/gaialogin"></iframe>
+ src="chrome://syncresources/gaialogin"></iframe>
<iframe id="merge" frameborder="0" width="100%" scrolling="no" height="100%"
- src="cloudy://resources/mergeandsync" style="display:none"></iframe>
+ src="chrome://syncresources/mergeandsync" style="display:none"></iframe>
</BODY>
</HTML>
diff --git a/chrome/browser/sync/sync_status_ui_helper.cc b/chrome/browser/sync/sync_status_ui_helper.cc
index 586cd6f..d16068f 100644
--- a/chrome/browser/sync/sync_status_ui_helper.cc
+++ b/chrome/browser/sync/sync_status_ui_helper.cc
@@ -60,9 +60,8 @@ SyncStatusUIHelper::MessageType SyncStatusUIHelper::GetLabels(
ProfileSyncService* service, std::wstring* status_label,
std::wstring* link_label) {
MessageType result_type(SYNCED);
- bool sync_enabled = service->IsSyncEnabledByUser();
- if (sync_enabled) {
+ if (service->HasSyncSetupCompleted()) {
ProfileSyncService::Status status(service->QueryDetailedSyncStatus());
AuthErrorState auth_error(service->GetAuthErrorState());
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 1889e9a..28bdec8 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -409,12 +409,10 @@ BookmarkBarView::BookmarkBarView(Profile* profile, Browser* browser)
browser_(browser),
throbbing_view_(NULL) {
#ifdef CHROME_PERSONALIZATION
- // Obtain a pointer to the profile sync service and add our instance as an
- // observer.
- ProfilePersonalization* profile_p13n = profile->GetProfilePersonalization();
- if (profile_p13n) {
- sync_service_ = profile_p13n->sync_service();
- DCHECK(sync_service_);
+ if (profile->GetProfileSyncService()) {
+ // Obtain a pointer to the profile sync service and add our instance as an
+ // observer.
+ sync_service_ = profile->GetProfileSyncService();
sync_service_->AddObserver(this);
}
#endif
@@ -1862,7 +1860,7 @@ void BookmarkBarView::UpdateButtonColors() {
// not the re-login indicator button should be visible.
bool BookmarkBarView::ShouldShowSyncErrorButton() {
bool show_sync_error_button(false);
- if (sync_service_ && sync_service_->IsSyncEnabledByUser()) {
+ if (sync_service_ && sync_service_->HasSyncSetupCompleted()) {
std::wstring status_text;
std::wstring link_text;
SyncStatusUIHelper::MessageType sync_status;
diff --git a/chrome/browser/views/options/content_page_view.cc b/chrome/browser/views/options/content_page_view.cc
index af2a4df..4a1c932 100644
--- a/chrome/browser/views/options/content_page_view.cc
+++ b/chrome/browser/views/options/content_page_view.cc
@@ -69,13 +69,11 @@ ContentPageView::ContentPageView(Profile* profile)
#endif
OptionsPageView(profile) {
#ifdef CHROME_PERSONALIZATION
- ProfilePersonalization* profile_p13n = profile->GetProfilePersonalization();
- if (profile_p13n) {
- sync_service_ = profile_p13n->sync_service();
- DCHECK(sync_service_);
+ if (profile->GetProfileSyncService()) {
+ sync_service_ = profile->GetProfileSyncService();
sync_service_->AddObserver(this);
- }
#endif
+ }
}
ContentPageView::~ContentPageView() {
@@ -135,7 +133,7 @@ void ContentPageView::ButtonPressed(views::Button* sender) {
#ifdef CHROME_PERSONALIZATION
} else if (sender == sync_start_stop_button_) {
DCHECK(sync_service_);
- if (sync_service_->IsSyncEnabledByUser()) {
+ if (sync_service_->HasSyncSetupCompleted()) {
sync_service_->DisableForUser();
ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
} else {
@@ -457,10 +455,10 @@ void ContentPageView::UpdateSyncControls() {
std::wstring status_label;
std::wstring link_label;
std::wstring button_label;
- bool sync_enabled = sync_service_->IsSyncEnabledByUser();
+ bool sync_setup_completed = sync_service_->HasSyncSetupCompleted();
bool status_has_error = SyncStatusUIHelper::GetLabels(sync_service_,
&status_label, &link_label) == SyncStatusUIHelper::SYNC_ERROR;
- button_label = sync_enabled ? kStopSyncButtonLabel :
+ button_label = sync_setup_completed ? kStopSyncButtonLabel :
sync_service_->SetupInProgress() ? UTF8ToWide(kSettingUpText)
: kStartSyncButtonLabel;
diff --git a/chrome/browser/views/sync/sync_setup_flow.cc b/chrome/browser/views/sync/sync_setup_flow.cc
index c0386a3..5eb2423 100644
--- a/chrome/browser/views/sync/sync_setup_flow.cc
+++ b/chrome/browser/views/sync/sync_setup_flow.cc
@@ -16,7 +16,6 @@
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/sync/sync_setup_flow.h"
-#include "chrome/common/pref_service.h"
static const int kSyncDialogWidth = 270;
static const int kSyncDialogHeight = 369;
@@ -139,9 +138,7 @@ void SyncSetupFlow::OnDialogClosed(const std::string& json_retval) {
DCHECK(json_retval.empty());
container_->set_flow(NULL); // Sever ties from the wizard.
if (current_state_ == SyncSetupWizard::DONE) {
- PrefService* prefs = service_->profile()->GetPrefs();
- prefs->SetBoolean(prefs::kSyncHasSetupCompleted, true);
- prefs->ScheduleSavePersistentPrefs();
+ service_->SetSyncSetupCompleted();
}
// Record the state at which the user cancelled the signon dialog.
diff --git a/chrome/browser/views/sync/sync_setup_flow.h b/chrome/browser/views/sync/sync_setup_flow.h
index 6412a74..1e22cf0 100644
--- a/chrome/browser/views/sync/sync_setup_flow.h
+++ b/chrome/browser/views/sync/sync_setup_flow.h
@@ -44,7 +44,7 @@ class SyncSetupFlow : public HtmlDialogUIDelegate {
// HtmlDialogUIDelegate implementation.
// Get the HTML file path for the content to load in the dialog.
virtual GURL GetDialogContentURL() const {
- return GURL("cloudy://resources/setup");
+ return GURL("chrome://syncresources/setup");
}
// HtmlDialogUIDelegate implementation.
diff --git a/chrome/browser/views/sync/sync_setup_wizard.cc b/chrome/browser/views/sync/sync_setup_wizard.cc
index 18ef7b8..2e86bfd 100644
--- a/chrome/browser/views/sync/sync_setup_wizard.cc
+++ b/chrome/browser/views/sync/sync_setup_wizard.cc
@@ -6,12 +6,78 @@
#include "chrome/browser/views/sync/sync_setup_wizard.h"
+#include "app/resource_bundle.h"
+#include "base/message_loop.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/dom_ui/chrome_url_data_manager.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/views/sync/sync_setup_flow.h"
+#include "chrome/common/url_constants.h"
+#include "grit/app_resources.h"
+#include "grit/browser_resources.h"
+
+class SyncResourcesSource : public ChromeURLDataManager::DataSource {
+ public:
+ SyncResourcesSource()
+ : DataSource(chrome::kSyncResourcesPath, MessageLoop::current()) {
+ }
+ virtual ~SyncResourcesSource() { }
+
+ virtual void StartDataRequest(const std::string& path, int request_id);
+
+ virtual std::string GetMimeType(const std::string& path) const {
+ if (path == chrome::kSyncThrobberPath)
+ return "image/png";
+ else
+ return "text/html";
+ }
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SyncResourcesSource);
+};
+
+void SyncResourcesSource::StartDataRequest(const std::string& path_raw,
+ int request_id) {
+ scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
+ if (path_raw == chrome::kSyncThrobberPath) {
+ ResourceBundle::GetSharedInstance().LoadImageResourceBytes(IDR_THROBBER,
+ &html_bytes->data);
+ SendResponse(request_id, html_bytes);
+ return;
+ }
+
+ std::string response;
+ if (path_raw == chrome::kSyncGaiaLoginPath) {
+ static const StringPiece html(ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_GAIA_LOGIN_HTML));
+ response = html.as_string();
+ } else if (path_raw == chrome::kSyncMergeAndSyncPath) {
+ static const StringPiece html(ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_MERGE_AND_SYNC_HTML));
+ response = html.as_string();
+ } else if (path_raw == chrome::kSyncSetupFlowPath) {
+ static const StringPiece html(ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_SYNC_SETUP_FLOW_HTML));
+ response = html.as_string();
+ }
+ // Send the response.
+ html_bytes->data.resize(response.size());
+ std::copy(response.begin(), response.end(), html_bytes->data.begin());
+ SendResponse(request_id, html_bytes);
+}
SyncSetupWizard::SyncSetupWizard(ProfileSyncService* service)
: service_(service), flow_container_(new SyncSetupFlowContainer()) {
+ // Register data sources for HTML content we require.
+ // g_browser_process and/or io_thread may not exist during testing.
+ if (g_browser_process && g_browser_process->io_thread()) {
+ // Add our network layer data source for 'cloudy' URLs.
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableMethod(&chrome_url_data_manager,
+ &ChromeURLDataManager::AddDataSource,
+ new SyncResourcesSource()));
+ }
}
SyncSetupWizard::~SyncSetupWizard() {
diff --git a/chrome/browser/views/sync/sync_setup_wizard_unittest.cc b/chrome/browser/views/sync/sync_setup_wizard_unittest.cc
index 75afa11..88dae75 100644
--- a/chrome/browser/views/sync/sync_setup_wizard_unittest.cc
+++ b/chrome/browser/views/sync/sync_setup_wizard_unittest.cc
@@ -14,6 +14,8 @@
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/views/sync/sync_setup_flow.h"
#include "chrome/browser/views/sync/sync_setup_wizard.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
#include "chrome/test/browser_with_test_window_test.h"
#include "chrome/test/testing_profile.h"
#include "chrome/test/test_browser_window.h"
@@ -27,6 +29,7 @@ class ProfileSyncServiceForWizardTest : public ProfileSyncService {
explicit ProfileSyncServiceForWizardTest(Profile* profile)
: ProfileSyncService(profile), user_accepted_merge_and_sync_(false),
user_cancelled_dialog_(false) {
+ RegisterPreferences();
}
virtual ~ProfileSyncServiceForWizardTest() { }
@@ -68,27 +71,17 @@ class ProfileSyncServiceForWizardTest : public ProfileSyncService {
DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest);
};
-class ProfilePersonalizationTestImpl : public ProfilePersonalization {
+class TestingProfileWithSyncService : public TestingProfile {
public:
- explicit ProfilePersonalizationTestImpl(Profile* p)
- : sync_service_(new ProfileSyncServiceForWizardTest(p)) {
+ TestingProfileWithSyncService() {
+ sync_service_.reset(new ProfileSyncServiceForWizardTest(this));
}
- virtual ProfileSyncService* sync_service() { return sync_service_.get(); }
- private:
- scoped_ptr<ProfileSyncService> sync_service_;
-};
-class TestingProfileWithPersonalization : public TestingProfile {
- public:
- TestingProfileWithPersonalization() {
- personalization_.reset(new ProfilePersonalizationTestImpl(this));
- }
-
- virtual ProfilePersonalization* GetProfilePersonalization() {
- return personalization_.get();
+ virtual ProfileSyncService* GetProfileSyncService() {
+ return sync_service_.get();
}
private:
- scoped_ptr<ProfilePersonalization> personalization_;
+ scoped_ptr<ProfileSyncService> sync_service_;
};
class TestBrowserWindowForWizardTest : public TestBrowserWindow {
@@ -154,19 +147,17 @@ class SyncSetupWizardTest : public BrowserWithTestWindowTest {
SyncSetupWizardTest() : test_window_(NULL), wizard_(NULL) { }
virtual ~SyncSetupWizardTest() { }
virtual void SetUp() {
- set_profile(new TestingProfileWithPersonalization());
+ set_profile(new TestingProfileWithSyncService());
profile()->CreateBookmarkModel(false);
// Wait for the bookmarks model to load.
profile()->BlockUntilBookmarkModelLoaded();
- profile()->GetPrefs()->RegisterBooleanPref(prefs::kSyncHasSetupCompleted,
- false);
set_browser(new Browser(Browser::TYPE_NORMAL, profile()));
test_window_ = new TestBrowserWindowForWizardTest(browser());
set_window(test_window_);
browser()->set_window(window());
BrowserList::SetLastActive(browser());
service_ = static_cast<ProfileSyncServiceForWizardTest*>(
- profile()->GetProfilePersonalization()->sync_service());
+ profile()->GetProfileSyncService());
wizard_.reset(new SyncSetupWizard(service_));
}
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index dce39b1..6d0b8cf 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -1085,9 +1085,8 @@ void ToolbarView::CreateAppMenu() {
IDS_SHOW_DOWNLOADS);
app_menu_contents_->AddSeparator();
#ifdef CHROME_PERSONALIZATION
- if (Personalization::IsSyncEnabled(profile_)) {
- app_menu_contents_->AddItem(
- IDC_P13N_INFO,
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableSync)) {
+ app_menu_contents_->AddItem(IDC_P13N_INFO,
Personalization::GetMenuItemInfoText(browser()));
}
#endif
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index 9331f66..6c8d381 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -572,4 +572,7 @@ const wchar_t kEnableDatabases[] = L"enable-databases";
// Enable ApplicationCache. Still mostly not there.
const wchar_t kEnableApplicationCache[] = L"enable-application-cache";
+
+// Override the default server used for profile sync.
+const wchar_t kSyncServiceURL[] = L"sync-url";
} // namespace switches
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index d109593..976d88a 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -225,6 +225,8 @@ extern const wchar_t kGoogleInternalCrashReporting[];
extern const wchar_t kEnableDatabases[];
extern const wchar_t kEnableApplicationCache[];
+
+extern const wchar_t kSyncServiceURL[];
} // namespace switches
#endif // CHROME_COMMON_CHROME_SWITCHES_H_
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index c86671f..bf6af12 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -566,4 +566,10 @@ const wchar_t kDevToolsOpenDocked[] = L"devtools.open_docked";
// Integer location of the split bar in the browser view.
const wchar_t kDevToolsSplitLocation[] = L"devtools.split_location";
+// 64-bit integer serialization of the base::Time when the last sync occured.
+const wchar_t kSyncLastSyncedTime[] = L"sync.last_synced_time";
+
+// Boolean specifying whether the user finished setting up sync.
+const wchar_t kSyncHasSetupCompleted[] = L"sync.has_setup_completed";
+
} // namespace prefs
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 94e8a5e..be1403e 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -211,6 +211,9 @@ extern const wchar_t kNTPShownSections[];
extern const wchar_t kDevToolsOpenDocked[];
extern const wchar_t kDevToolsSplitLocation[];
+
+extern const wchar_t kSyncLastSyncedTime[];
+extern const wchar_t kSyncHasSetupCompleted[];
}
#endif // CHROME_COMMON_PREF_NAMES_H_
diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc
index ca9f9b5..65b87ae 100644
--- a/chrome/common/url_constants.cc
+++ b/chrome/common/url_constants.cc
@@ -55,4 +55,10 @@ const char kChromeUINewTabHost[] = "newtab";
const char kChromeUIThumbnailPath[] = "thumb";
const char kChromeUIThemePath[] = "theme";
+const char kSyncResourcesPath[] = "syncresources";
+const char kSyncGaiaLoginPath[] = "gaialogin";
+const char kSyncMergeAndSyncPath[] = "mergeandsync";
+const char kSyncThrobberPath[] = "throbber.png";
+const char kSyncSetupFlowPath[] = "setup";
+
} // namespace chrome
diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h
index 12d7651..4b33679 100644
--- a/chrome/common/url_constants.h
+++ b/chrome/common/url_constants.h
@@ -62,6 +62,13 @@ extern const char kChromeUINewTabHost[];
extern const char kChromeUIThumbnailPath[];
extern const char kChromeUIThemePath[];
+// Sync related URL components.
+extern const char kSyncResourcesPath[];
+extern const char kSyncGaiaLoginPath[];
+extern const char kSyncMergeAndSyncPath[];
+extern const char kSyncThrobberPath[];
+extern const char kSyncSetupFlowPath[];
+
} // namespace chrome
#endif // CHROME_COMMON_URL_CONSTANTS_H_
diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.cc b/chrome/test/live_sync/live_bookmarks_sync_test.cc
index 43c1db0..3737cc3 100644
--- a/chrome/test/live_sync/live_bookmarks_sync_test.cc
+++ b/chrome/test/live_sync/live_bookmarks_sync_test.cc
@@ -15,6 +15,11 @@
#include "chrome/browser/profile_manager.h"
#include "chrome/test/ui_test_utils.h"
+namespace switches {
+const wchar_t kSyncUserForTest[] = L"sync-user-for-test";
+const wchar_t kSyncPasswordForTest[] = L"sync-password-for-test";
+}
+
// BookmarkLoadObserver is used when blocking until the BookmarkModel
// finishes loading. As soon as the BookmarkModel finishes loading the message
// loop is quit.
diff --git a/chrome/test/live_sync/live_bookmarks_sync_test.h b/chrome/test/live_sync/live_bookmarks_sync_test.h
index 0c603802..368eeb1 100644
--- a/chrome/test/live_sync/live_bookmarks_sync_test.h
+++ b/chrome/test/live_sync/live_bookmarks_sync_test.h
@@ -20,6 +20,11 @@ class BookmarkModel;
class BookmarkNode;
class Profile;
+namespace switches {
+extern const wchar_t kSyncUserForTest[];
+extern const wchar_t kSyncPasswordForTest[];
+}
+
// TODO(timsteele): This should be moved out of personalization_unit_tests into
// its own project that doesn't get run by default on the standard buildbot
// without a valid sync server set up.
@@ -59,7 +64,7 @@ class LiveBookmarksSyncTest : public InProcessBrowserTest {
protected:
std::string username_;
std::string password_;
-
+
private:
DISALLOW_COPY_AND_ASSIGN(LiveBookmarksSyncTest);
};
diff --git a/chrome/test/live_sync/profile_sync_service_test_harness.cc b/chrome/test/live_sync/profile_sync_service_test_harness.cc
index 57ceeb6..debb782 100644
--- a/chrome/test/live_sync/profile_sync_service_test_harness.cc
+++ b/chrome/test/live_sync/profile_sync_service_test_harness.cc
@@ -116,8 +116,8 @@ ProfileSyncServiceTestHarness::ProfileSyncServiceTestHarness(
}
bool ProfileSyncServiceTestHarness::SetupSync() {
- service_ = profile_->GetProfilePersonalization()->sync_service();
- profile_->GetPrefs()->SetBoolean(prefs::kSyncHasSetupCompleted, true);
+ service_ = profile_->GetProfileSyncService();
+ service_->SetSyncSetupCompleted();
service_->EnableForUser();
// Needed to avoid showing the login dialog. Well aware this is egregious.
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index e8a2c7a..bfd0249 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -228,11 +228,9 @@ class TestingProfile : public Profile {
// history service processes all pending requests.
void BlockUntilHistoryProcessesPendingRequests();
-#ifdef CHROME_PERSONALIZATION
- virtual ProfilePersonalization* GetProfilePersonalization() {
+ virtual ProfileSyncService* GetProfileSyncService() {
return NULL;
}
-#endif
protected:
// The path of the profile; the various database and other files are relative