diff options
-rw-r--r-- | chrome/browser/profiles/bookmark_model_loaded_observer.cc | 29 | ||||
-rw-r--r-- | chrome/browser/profiles/bookmark_model_loaded_observer.h | 28 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.cc | 38 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_impl.h | 11 | ||||
-rw-r--r-- | chrome/browser/profiles/profile_manager.cc | 11 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 |
6 files changed, 86 insertions, 33 deletions
diff --git a/chrome/browser/profiles/bookmark_model_loaded_observer.cc b/chrome/browser/profiles/bookmark_model_loaded_observer.cc new file mode 100644 index 0000000..56c1135 --- /dev/null +++ b/chrome/browser/profiles/bookmark_model_loaded_observer.cc @@ -0,0 +1,29 @@ +// Copyright 2013 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/profiles/bookmark_model_loaded_observer.h" + +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/sync/profile_sync_service_factory.h" + +BookmarkModelLoadedObserver::BookmarkModelLoadedObserver(Profile* profile) + : profile_(profile) { +} + +void BookmarkModelLoadedObserver::BookmarkModelChanged() { +} + +void BookmarkModelLoadedObserver::Loaded(BookmarkModel* model, + bool ids_reassigned) { + // Causes lazy-load if sync is enabled. + ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile_); + model->RemoveObserver(this); + delete this; +} + +void BookmarkModelLoadedObserver::BookmarkModelBeingDeleted( + BookmarkModel* model) { + model->RemoveObserver(this); + delete this; +} diff --git a/chrome/browser/profiles/bookmark_model_loaded_observer.h b/chrome/browser/profiles/bookmark_model_loaded_observer.h new file mode 100644 index 0000000..d40cea8 --- /dev/null +++ b/chrome/browser/profiles/bookmark_model_loaded_observer.h @@ -0,0 +1,28 @@ +// Copyright 2013 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_PROFILES_BOOKMARK_MODEL_LOADED_OBSERVER_H_ +#define CHROME_BROWSER_PROFILES_BOOKMARK_MODEL_LOADED_OBSERVER_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/bookmarks/base_bookmark_model_observer.h" + +class Profile; + +class BookmarkModelLoadedObserver : public BaseBookmarkModelObserver { + public: + explicit BookmarkModelLoadedObserver(Profile* profile); + + private: + virtual void BookmarkModelChanged() OVERRIDE; + virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE; + virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE; + + Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(BookmarkModelLoadedObserver); +}; + +#endif // CHROME_BROWSER_PROFILES_BOOKMARK_MODEL_LOADED_OBSERVER_H_ diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 4c658cd..9af1d83 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -24,6 +24,8 @@ #include "chrome/browser/autocomplete/autocomplete_classifier.h" #include "chrome/browser/background/background_contents_service_factory.h" #include "chrome/browser/background/background_mode_manager.h" +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/cookie_settings.h" #include "chrome/browser/content_settings/host_content_settings_map.h" @@ -55,6 +57,7 @@ #include "chrome/browser/prefs/chrome_pref_service_factory.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/prerender/prerender_manager_factory.h" +#include "chrome/browser/profiles/bookmark_model_loaded_observer.h" #include "chrome/browser/profiles/chrome_version_service.h" #include "chrome/browser/profiles/gaia_info_update_service_factory.h" #include "chrome/browser/profiles/profile_dependency_manager.h" @@ -64,7 +67,6 @@ #include "chrome/browser/search_engines/template_url_fetcher.h" #include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/speech/chrome_speech_recognition_preferences.h" -#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/ui/startup/startup_browser_creator.h" #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" #include "chrome/browser/user_style_sheet_watcher.h" @@ -445,13 +447,6 @@ void ProfileImpl::DoFinalInit(bool is_new_profile) { UpdateProfileUserNameCache(); GAIAInfoUpdateServiceFactory::GetForProfile(this); -#if !defined(OS_CHROMEOS) - // Listen for bookmark model load, to bootstrap the sync service. - // On CrOS sync service will be initialized after sign in. - registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, - content::Source<Profile>(this)); -#endif - PrefService* local_state = g_browser_process->local_state(); ssl_config_service_manager_.reset( SSLConfigServiceManager::CreateDefaultManager(local_state, prefs)); @@ -544,6 +539,18 @@ void ProfileImpl::DoFinalInit(bool is_new_profile) { chrome::NOTIFICATION_PROFILE_CREATED, content::Source<Profile>(this), content::NotificationService::NoDetails()); + +#if !defined(OS_CHROMEOS) + // Listen for bookmark model load, to bootstrap the sync service. + // On CrOS sync service will be initialized after sign in. + if (!g_browser_process->profile_manager()->will_import()) { + // If |will_import()| is true we add the observer in + // ProfileManager::OnImportFinished(). + BookmarkModel* model = BookmarkModelFactory::GetForProfile(this); + model->AddObserver(new BookmarkModelLoadedObserver(this)); + } +#endif + } void ProfileImpl::InitHostZoomMap() { @@ -957,21 +964,6 @@ history::TopSites* ProfileImpl::GetTopSitesWithoutCreating() { return top_sites_; } -void ProfileImpl::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - switch (type) { - case chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED: - // Causes lazy-load if sync is enabled. - ProfileSyncServiceFactory::GetInstance()->GetForProfile(this); - registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, - content::Source<Profile>(this)); - break; - default: - NOTREACHED(); - } -} - void ProfileImpl::OnDefaultZoomLevelChanged() { HostZoomMap::GetForBrowserContext(this)->SetDefaultZoomLevel( pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 849117b..39de398 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -17,8 +17,6 @@ #include "base/timer.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_impl_io_data.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" #include "content/public/browser/host_zoom_map.h" class NetPrefObserver; @@ -51,8 +49,7 @@ class UserCloudPolicyManager; } // The default profile implementation. -class ProfileImpl : public Profile, - public content::NotificationObserver { +class ProfileImpl : public Profile { public: // Value written to prefs when the exit type is EXIT_NORMAL. Public for tests. static const char* const kPrefExitTypeNormal; @@ -152,11 +149,6 @@ class ProfileImpl : public Profile, virtual PrefProxyConfigTracker* GetProxyConfigTracker() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - private: friend class Profile; friend class BetterSessionRestoreCrashTest; @@ -212,7 +204,6 @@ class ProfileImpl : public Profile, FilePath* cache_path, int* max_size); - content::NotificationRegistrar registrar_; content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; PrefChangeRegistrar pref_change_registrar_; diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index d35f186..c74ae1d 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -14,11 +14,14 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/bookmarks/bookmark_model_factory.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/prefs/pref_registry_simple.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" +#include "chrome/browser/profiles/bookmark_model_loaded_observer.h" #include "chrome/browser/profiles/profile_destroyer.h" #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_metrics.h" @@ -664,6 +667,14 @@ void ProfileManager::OnImportFinished(Profile* profile) { will_import_ = false; did_perform_profile_import = true; DCHECK(profile); + +#if !defined(OS_CHROMEOS) + // If the import process was not run, it means this branch was not called, + // and it was handled by ProfileImpl::DoFinalInit(). + BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile); + model->AddObserver(new BookmarkModelLoadedObserver(profile)); +#endif + content::NotificationService::current()->Notify( chrome::NOTIFICATION_IMPORT_FINISHED, content::Source<Profile>(profile), diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index fb51afe..e859c3c 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1616,6 +1616,8 @@ 'browser/profiles/avatar_menu_model.cc', 'browser/profiles/avatar_menu_model.h', 'browser/profiles/avatar_menu_model_observer.h', + 'browser/profiles/bookmark_model_loaded_observer.cc', + 'browser/profiles/bookmark_model_loaded_observer.h', 'browser/profiles/chrome_version_service.cc', 'browser/profiles/chrome_version_service.h', 'browser/profiles/gaia_info_update_service.cc', |