OLD | NEW |
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_expanded_state_tracker.h" | 5 #include "chrome/browser/bookmarks/bookmark_expanded_state_tracker.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 | 13 |
13 BookmarkExpandedStateTracker::BookmarkExpandedStateTracker( | 14 BookmarkExpandedStateTracker::BookmarkExpandedStateTracker( |
14 Profile* profile, | 15 Profile* profile, |
15 const char* path, | 16 const char* path, |
16 BookmarkModel* bookmark_model) | 17 BookmarkModel* bookmark_model) |
17 : profile_(profile), | 18 : profile_(profile), |
18 pref_path_(path) { | 19 pref_path_(path) { |
19 bookmark_model->AddObserver(this); | 20 bookmark_model->AddObserver(this); |
20 } | 21 } |
21 | 22 |
22 BookmarkExpandedStateTracker::~BookmarkExpandedStateTracker() { | 23 BookmarkExpandedStateTracker::~BookmarkExpandedStateTracker() { |
23 } | 24 } |
24 | 25 |
25 void BookmarkExpandedStateTracker::SetExpandedNodes(const Nodes& nodes) { | 26 void BookmarkExpandedStateTracker::SetExpandedNodes(const Nodes& nodes) { |
26 UpdatePrefs(nodes); | 27 UpdatePrefs(nodes); |
27 } | 28 } |
28 | 29 |
29 BookmarkExpandedStateTracker::Nodes | 30 BookmarkExpandedStateTracker::Nodes |
30 BookmarkExpandedStateTracker::GetExpandedNodes() { | 31 BookmarkExpandedStateTracker::GetExpandedNodes() { |
31 Nodes nodes; | 32 Nodes nodes; |
32 BookmarkModel* model = profile_->GetBookmarkModel(); | 33 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile_); |
33 if (!model->IsLoaded()) | 34 if (!model->IsLoaded()) |
34 return nodes; | 35 return nodes; |
35 | 36 |
36 PrefService* prefs = profile_->GetPrefs(); | 37 PrefService* prefs = profile_->GetPrefs(); |
37 if (!prefs) | 38 if (!prefs) |
38 return nodes; | 39 return nodes; |
39 | 40 |
40 const ListValue* value = prefs->GetList(pref_path_); | 41 const ListValue* value = prefs->GetList(pref_path_); |
41 if (!value) | 42 if (!value) |
42 return nodes; | 43 return nodes; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 if (!profile_->GetPrefs()) | 92 if (!profile_->GetPrefs()) |
92 return; | 93 return; |
93 | 94 |
94 ListValue values; | 95 ListValue values; |
95 for (Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i) { | 96 for (Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i) { |
96 values.Set(values.GetSize(), | 97 values.Set(values.GetSize(), |
97 new StringValue(base::Int64ToString((*i)->id()))); | 98 new StringValue(base::Int64ToString((*i)->id()))); |
98 } | 99 } |
99 profile_->GetPrefs()->Set(pref_path_, values); | 100 profile_->GetPrefs()->Set(pref_path_, values); |
100 } | 101 } |
OLD | NEW |