Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: chrome/browser/bookmarks/bookmark_model_factory.cc

Issue 2901463002: [MD Bookmarks] Add undo/redo functionality to MD Bookmarks. (Closed)
Patch Set: fix DEPS Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/command_manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 5 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/deferred_sequenced_task_runner.h" 8 #include "base/deferred_sequenced_task_runner.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 13 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" 14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
15 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" 15 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h"
16 #include "chrome/browser/profiles/incognito_helpers.h" 16 #include "chrome/browser/profiles/incognito_helpers.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.h"
18 #include "chrome/browser/undo/bookmark_undo_service_factory.h" 19 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "components/bookmarks/browser/bookmark_model.h" 21 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "components/bookmarks/browser/bookmark_utils.h" 22 #include "components/bookmarks/browser/bookmark_utils.h"
22 #include "components/bookmarks/browser/startup_task_runner_service.h" 23 #include "components/bookmarks/browser/startup_task_runner_service.h"
23 #include "components/keyed_service/content/browser_context_dependency_manager.h" 24 #include "components/keyed_service/content/browser_context_dependency_manager.h"
24 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
25 #include "components/undo/bookmark_undo_service.h" 26 #include "components/undo/bookmark_undo_service.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 28
28 using bookmarks::BookmarkModel; 29 using bookmarks::BookmarkModel;
29 30
31 namespace {
32
33 bool IsBookmarkUndoServiceEnabled() {
34 bool register_bookmark_undo_service_as_observer = true;
35 #if !defined(OS_ANDROID)
36 register_bookmark_undo_service_as_observer =
37 base::CommandLine::ForCurrentProcess()->HasSwitch(
38 switches::kEnableBookmarkUndo) ||
39 MdBookmarksUI::IsEnabled();
40 #endif // !defined(OS_ANDROID)
41 return register_bookmark_undo_service_as_observer;
42 }
43
44 } // namespace
45
30 // static 46 // static
31 BookmarkModel* BookmarkModelFactory::GetForBrowserContext( 47 BookmarkModel* BookmarkModelFactory::GetForBrowserContext(
32 content::BrowserContext* context) { 48 content::BrowserContext* context) {
33 return static_cast<BookmarkModel*>( 49 return static_cast<BookmarkModel*>(
34 GetInstance()->GetServiceForBrowserContext(context, true)); 50 GetInstance()->GetServiceForBrowserContext(context, true));
35 } 51 }
36 52
37 // static 53 // static
38 BookmarkModel* BookmarkModelFactory::GetForBrowserContextIfExists( 54 BookmarkModel* BookmarkModelFactory::GetForBrowserContextIfExists(
39 content::BrowserContext* context) { 55 content::BrowserContext* context) {
(...skipping 22 matching lines...) Expand all
62 content::BrowserContext* context) const { 78 content::BrowserContext* context) const {
63 Profile* profile = Profile::FromBrowserContext(context); 79 Profile* profile = Profile::FromBrowserContext(context);
64 BookmarkModel* bookmark_model = 80 BookmarkModel* bookmark_model =
65 new BookmarkModel(base::MakeUnique<ChromeBookmarkClient>( 81 new BookmarkModel(base::MakeUnique<ChromeBookmarkClient>(
66 profile, ManagedBookmarkServiceFactory::GetForProfile(profile))); 82 profile, ManagedBookmarkServiceFactory::GetForProfile(profile)));
67 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), 83 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(),
68 StartupTaskRunnerServiceFactory::GetForProfile(profile) 84 StartupTaskRunnerServiceFactory::GetForProfile(profile)
69 ->GetBookmarkTaskRunner(), 85 ->GetBookmarkTaskRunner(),
70 content::BrowserThread::GetTaskRunnerForThread( 86 content::BrowserThread::GetTaskRunnerForThread(
71 content::BrowserThread::UI)); 87 content::BrowserThread::UI));
72 bool register_bookmark_undo_service_as_observer = true; 88 if (IsBookmarkUndoServiceEnabled())
73 #if !defined(OS_ANDROID)
74 register_bookmark_undo_service_as_observer =
75 base::CommandLine::ForCurrentProcess()->HasSwitch(
76 switches::kEnableBookmarkUndo);
77 #endif // !defined(OS_ANDROID)
78 if (register_bookmark_undo_service_as_observer)
79 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); 89 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model);
80 90
81 return bookmark_model; 91 return bookmark_model;
82 } 92 }
83 93
84 void BookmarkModelFactory::RegisterProfilePrefs( 94 void BookmarkModelFactory::RegisterProfilePrefs(
85 user_prefs::PrefRegistrySyncable* registry) { 95 user_prefs::PrefRegistrySyncable* registry) {
86 bookmarks::RegisterProfilePrefs(registry); 96 bookmarks::RegisterProfilePrefs(registry);
87 } 97 }
88 98
89 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( 99 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse(
90 content::BrowserContext* context) const { 100 content::BrowserContext* context) const {
91 return chrome::GetBrowserContextRedirectedInIncognito(context); 101 return chrome::GetBrowserContextRedirectedInIncognito(context);
92 } 102 }
93 103
94 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { 104 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const {
95 return true; 105 return true;
96 } 106 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/command_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698