NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / undo / bookmark_undo_utils.cc
blob1302b3eb4702b904d48ab9e6e28d5cb0fdc97768
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/undo/bookmark_undo_utils.h"
7 #include "chrome/browser/undo/bookmark_undo_service.h"
8 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
9 #include "chrome/browser/undo/undo_manager.h"
11 namespace {
13 // Utility funciton to safely return an UndoManager if available.
14 UndoManager* GetUndoManager(Profile* profile) {
15 BookmarkUndoService* undo_service = profile ?
16 BookmarkUndoServiceFactory::GetForProfile(profile) : NULL;
17 return undo_service ? undo_service->undo_manager() : NULL;
20 } // namespace
22 // ScopedSuspendBookmarkUndo --------------------------------------------------
24 ScopedSuspendBookmarkUndo::ScopedSuspendBookmarkUndo(Profile* profile)
25 : profile_(profile) {
26 UndoManager* undo_manager = GetUndoManager(profile_);
27 if (undo_manager)
28 undo_manager->SuspendUndoTracking();
31 ScopedSuspendBookmarkUndo::~ScopedSuspendBookmarkUndo() {
32 UndoManager *undo_manager = GetUndoManager(profile_);
33 if (undo_manager)
34 undo_manager->ResumeUndoTracking();
37 // ScopedGroupBookmarkActions -------------------------------------------------
39 ScopedGroupBookmarkActions::ScopedGroupBookmarkActions(Profile* profile)
40 : profile_(profile) {
41 UndoManager *undo_manager = GetUndoManager(profile_);
42 if (undo_manager)
43 undo_manager->StartGroupingActions();
46 ScopedGroupBookmarkActions::~ScopedGroupBookmarkActions() {
47 UndoManager *undo_manager = GetUndoManager(profile_);
48 if (undo_manager)
49 undo_manager->EndGroupingActions();