diff options
Diffstat (limited to 'chrome/browser/bookmarks')
| -rw-r--r-- | chrome/browser/bookmarks/bookmark_expanded_state_tracker.cc | 12 | ||||
| -rw-r--r-- | chrome/browser/bookmarks/bookmark_expanded_state_tracker.h | 6 | ||||
| -rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc | 17 | ||||
| -rw-r--r-- | chrome/browser/bookmarks/bookmark_model.h | 12 | ||||
| -rw-r--r-- | chrome/browser/bookmarks/bookmark_model_factory.cc | 58 | ||||
| -rw-r--r-- | chrome/browser/bookmarks/bookmark_model_factory.h | 39 |
6 files changed, 118 insertions, 26 deletions
diff --git a/chrome/browser/bookmarks/bookmark_expanded_state_tracker.cc b/chrome/browser/bookmarks/bookmark_expanded_state_tracker.cc index 1b5d870..f23aca1 100644 --- a/chrome/browser/bookmarks/bookmark_expanded_state_tracker.cc +++ b/chrome/browser/bookmarks/bookmark_expanded_state_tracker.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -10,15 +10,16 @@ #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" -BookmarkExpandedStateTracker::BookmarkExpandedStateTracker(Profile* profile, - const char* path) +BookmarkExpandedStateTracker::BookmarkExpandedStateTracker( + Profile* profile, + const char* path, + BookmarkModel* bookmark_model) : profile_(profile), pref_path_(path) { - profile_->GetBookmarkModel()->AddObserver(this); + bookmark_model->AddObserver(this); } BookmarkExpandedStateTracker::~BookmarkExpandedStateTracker() { - profile_->GetBookmarkModel()->RemoveObserver(this); } void BookmarkExpandedStateTracker::SetExpandedNodes(const Nodes& nodes) { @@ -71,6 +72,7 @@ void BookmarkExpandedStateTracker::BookmarkModelChanged() { void BookmarkExpandedStateTracker::BookmarkModelBeingDeleted( BookmarkModel* model) { + model->RemoveObserver(this); } void BookmarkExpandedStateTracker::BookmarkNodeRemoved( diff --git a/chrome/browser/bookmarks/bookmark_expanded_state_tracker.h b/chrome/browser/bookmarks/bookmark_expanded_state_tracker.h index 0ed9bbb..2edf720 100644 --- a/chrome/browser/bookmarks/bookmark_expanded_state_tracker.h +++ b/chrome/browser/bookmarks/bookmark_expanded_state_tracker.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -20,7 +20,9 @@ class BookmarkExpandedStateTracker : public BaseBookmarkModelObserver { public: typedef std::set<const BookmarkNode*> Nodes; - BookmarkExpandedStateTracker(Profile* profile, const char* path); + BookmarkExpandedStateTracker(Profile* profile, + const char* path, + BookmarkModel* bookmark_model); virtual ~BookmarkExpandedStateTracker(); // The set of expanded nodes. diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index fcb608c..ac38bd4 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -152,21 +152,12 @@ BookmarkModel::~BookmarkModel() { } } -// static -void BookmarkModel::RegisterUserPrefs(PrefService* prefs) { - // Don't sync this, as otherwise, due to a limitation in sync, it - // will cause a deadlock (see http://crbug.com/97955). If we truly - // want to sync the expanded state of folders, it should be part of - // bookmark sync itself (i.e., a property of the sync folder nodes). - prefs->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, new ListValue, - PrefService::UNSYNCABLE_PREF); -} - -void BookmarkModel::Cleanup() { +void BookmarkModel::Shutdown() { if (loaded_) return; - // See comment in Profile shutdown code where this is invoked for details. + // See comment in HistoryService::ShutdownOnUIThread where this is invoked for + // details. It is also called when the BookmarkModel is deleted. loaded_signal_.Signal(); } @@ -179,7 +170,7 @@ void BookmarkModel::Load() { } expanded_state_tracker_.reset(new BookmarkExpandedStateTracker( - profile_, prefs::kBookmarkEditorExpandedNodes)); + profile_, prefs::kBookmarkEditorExpandedNodes, this)); // Listen for changes to favicons so that we can update the favicon of the // node appropriately. diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 91cd1c8..7ec957c 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -21,6 +21,7 @@ #include "chrome/browser/cancelable_request.h" #include "chrome/browser/favicon/favicon_service.h" #include "chrome/browser/history/history.h" +#include "chrome/browser/profiles/profile_keyed_service.h" #include "content/public/browser/notification_registrar.h" #include "googleurl/src/gurl.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -192,19 +193,18 @@ class BookmarkPermanentNode : public BookmarkNode { // An observer may be attached to observe relevant events. // // You should NOT directly create a BookmarkModel, instead go through the -// Profile. +// BookmarkModelFactory. class BookmarkModel : public content::NotificationObserver, - public BookmarkService { + public BookmarkService, + public ProfileKeyedService { public: explicit BookmarkModel(Profile* profile); virtual ~BookmarkModel(); - static void RegisterUserPrefs(PrefService* prefs); - // Invoked prior to destruction to release any necessary resources. - void Cleanup(); + virtual void Shutdown() OVERRIDE; - // Loads the bookmarks. This is called by Profile upon creation of the + // Loads the bookmarks. This is called upon creation of the // BookmarkModel. You need not invoke this directly. void Load(); diff --git a/chrome/browser/bookmarks/bookmark_model_factory.cc b/chrome/browser/bookmarks/bookmark_model_factory.cc new file mode 100644 index 0000000..536eb70 --- /dev/null +++ b/chrome/browser/bookmarks/bookmark_model_factory.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2012 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/bookmarks/bookmark_model_factory.h" + +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/history/history_service_factory.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profiles/profile_dependency_manager.h" +#include "chrome/common/pref_names.h" + +// static +BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { + return static_cast<BookmarkModel*>( + GetInstance()->GetServiceForProfile(profile, true)); +} + +BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { + return static_cast<BookmarkModel*>( + GetInstance()->GetServiceForProfile(profile, false)); +} + +// static +BookmarkModelFactory* BookmarkModelFactory::GetInstance() { + return Singleton<BookmarkModelFactory>::get(); +} + +BookmarkModelFactory::BookmarkModelFactory() + : ProfileKeyedServiceFactory("BookmarkModelFactory", + ProfileDependencyManager::GetInstance()) { +} + +BookmarkModelFactory::~BookmarkModelFactory() {} + +ProfileKeyedService* BookmarkModelFactory::BuildServiceInstanceFor( + Profile* profile) const { + BookmarkModel* bookmark_model = new BookmarkModel(profile); + bookmark_model->Load(); + return bookmark_model; +} + +void BookmarkModelFactory::RegisterUserPrefs(PrefService* prefs) { + // Don't sync this, as otherwise, due to a limitation in sync, it + // will cause a deadlock (see http://crbug.com/97955). If we truly + // want to sync the expanded state of folders, it should be part of + // bookmark sync itself (i.e., a property of the sync folder nodes). + prefs->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, new ListValue, + PrefService::UNSYNCABLE_PREF); +} + +bool BookmarkModelFactory::ServiceRedirectedInIncognito() { + return true; +} + +bool BookmarkModelFactory::ServiceIsNULLWhileTesting() { + return true; +} diff --git a/chrome/browser/bookmarks/bookmark_model_factory.h b/chrome/browser/bookmarks/bookmark_model_factory.h new file mode 100644 index 0000000..7312788 --- /dev/null +++ b/chrome/browser/bookmarks/bookmark_model_factory.h @@ -0,0 +1,39 @@ +// Copyright (c) 2012 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_BOOKMARKS_BOOKMARK_MODEL_FACTORY_H_ +#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_FACTORY_H_ +#pragma once + +#include "base/memory/singleton.h" +#include "chrome/browser/profiles/profile_keyed_service_factory.h" + +class Profile; +class BookmarkModel; + +// Singleton that owns all BookmarkModel and associates them with +// Profiles. +class BookmarkModelFactory : public ProfileKeyedServiceFactory { + public: + static BookmarkModel* GetForProfile(Profile* profile); + + static BookmarkModel* GetForProfileIfExists(Profile* profile); + + static BookmarkModelFactory* GetInstance(); + + private: + friend struct DefaultSingletonTraits<BookmarkModelFactory>; + + BookmarkModelFactory(); + virtual ~BookmarkModelFactory(); + + // ProfileKeyedServiceFactory: + virtual ProfileKeyedService* BuildServiceInstanceFor( + Profile* profile) const OVERRIDE; + virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE; + virtual bool ServiceRedirectedInIncognito() OVERRIDE; + virtual bool ServiceIsNULLWhileTesting() OVERRIDE; +}; + +#endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_MODEL_FACTORY_H_ |
