OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/undo/bookmark_undo_utils.h" | 5 #include "chrome/browser/undo/bookmark_undo_utils.h" |
6 | 6 |
7 #include "chrome/browser/undo/bookmark_undo_service.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" | 8 #include "chrome/browser/undo/undo_manager.h" |
10 | 9 |
11 namespace { | |
12 | |
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; | |
18 } | |
19 | |
20 } // namespace | |
21 | |
22 // ScopedSuspendBookmarkUndo -------------------------------------------------- | 10 // ScopedSuspendBookmarkUndo -------------------------------------------------- |
23 | 11 |
24 ScopedSuspendBookmarkUndo::ScopedSuspendBookmarkUndo(Profile* profile) | 12 ScopedSuspendBookmarkUndo::ScopedSuspendBookmarkUndo( |
25 : profile_(profile) { | 13 BookmarkUndoService* bookmark_undo_service) |
26 UndoManager* undo_manager = GetUndoManager(profile_); | 14 : undo_manager_(bookmark_undo_service |
27 if (undo_manager) | 15 ? bookmark_undo_service->undo_manager() |
28 undo_manager->SuspendUndoTracking(); | 16 : nullptr) { |
| 17 if (undo_manager_) |
| 18 undo_manager_->SuspendUndoTracking(); |
29 } | 19 } |
30 | 20 |
31 ScopedSuspendBookmarkUndo::~ScopedSuspendBookmarkUndo() { | 21 ScopedSuspendBookmarkUndo::~ScopedSuspendBookmarkUndo() { |
32 UndoManager *undo_manager = GetUndoManager(profile_); | 22 if (undo_manager_) |
33 if (undo_manager) | 23 undo_manager_->ResumeUndoTracking(); |
34 undo_manager->ResumeUndoTracking(); | |
35 } | 24 } |
OLD | NEW |