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/bookmarks/chrome_bookmark_client.h" | 5 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/favicon/favicon_changed_details.h" | 12 #include "chrome/browser/favicon/favicon_changed_details.h" |
13 #include "chrome/browser/favicon/favicon_service.h" | 13 #include "chrome/browser/favicon/favicon_service.h" |
14 #include "chrome/browser/favicon/favicon_service_factory.h" | 14 #include "chrome/browser/favicon/favicon_service_factory.h" |
15 #include "chrome/browser/history/history_service.h" | 15 #include "chrome/browser/history/history_service.h" |
16 #include "chrome/browser/history/history_service_factory.h" | 16 #include "chrome/browser/history/history_service_factory.h" |
17 #include "chrome/browser/policy/profile_policy_connector.h" | 17 #include "chrome/browser/policy/profile_policy_connector.h" |
18 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 18 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/profiles/startup_task_runner_service.h" | |
21 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | |
22 #include "components/bookmarks/browser/bookmark_model.h" | 20 #include "components/bookmarks/browser/bookmark_model.h" |
23 #include "components/bookmarks/browser/bookmark_node.h" | 21 #include "components/bookmarks/browser/bookmark_node.h" |
24 #include "components/history/core/browser/url_database.h" | 22 #include "components/history/core/browser/url_database.h" |
25 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
27 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
28 #include "content/public/browser/user_metrics.h" | 26 #include "content/public/browser/user_metrics.h" |
29 #include "grit/components_strings.h" | 27 #include "grit/components_strings.h" |
30 #include "policy/policy_constants.h" | 28 #include "policy/policy_constants.h" |
31 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() { | 162 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() { |
165 // Create the managed_node now; it will be populated in the LoadExtraNodes | 163 // Create the managed_node now; it will be populated in the LoadExtraNodes |
166 // callback. | 164 // callback. |
167 // The ownership of managed_node_ is in limbo until LoadExtraNodes runs, | 165 // The ownership of managed_node_ is in limbo until LoadExtraNodes runs, |
168 // so we leave it in the care of the closure meanwhile. | 166 // so we leave it in the care of the closure meanwhile. |
169 scoped_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0)); | 167 scoped_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0)); |
170 managed_node_ = managed.get(); | 168 managed_node_ = managed.get(); |
171 | 169 |
172 return base::Bind( | 170 return base::Bind( |
173 &ChromeBookmarkClient::LoadExtraNodes, | 171 &ChromeBookmarkClient::LoadExtraNodes, |
174 StartupTaskRunnerServiceFactory::GetForProfile(profile_) | |
175 ->GetBookmarkTaskRunner(), | |
Joao da Silva
2014/07/09 13:58:16
This is what caused the leak:
- this callback is
| |
176 base::Passed(&managed), | 172 base::Passed(&managed), |
177 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks())); | 173 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks())); |
178 } | 174 } |
179 | 175 |
180 bool ChromeBookmarkClient::CanSetPermanentNodeTitle( | 176 bool ChromeBookmarkClient::CanSetPermanentNodeTitle( |
181 const BookmarkNode* permanent_node) { | 177 const BookmarkNode* permanent_node) { |
182 // The |managed_node_| can have its title updated if the user signs in or | 178 // The |managed_node_| can have its title updated if the user signs in or |
183 // out. | 179 // out. |
184 return !IsDescendantOfManagedNode(permanent_node) || | 180 return !IsDescendantOfManagedNode(permanent_node) || |
185 permanent_node == managed_node_; | 181 permanent_node == managed_node_; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model, | 227 void ChromeBookmarkClient::BookmarkModelLoaded(BookmarkModel* model, |
232 bool ids_reassigned) { | 228 bool ids_reassigned) { |
233 // Start tracking the managed bookmarks. This will detect any changes that | 229 // Start tracking the managed bookmarks. This will detect any changes that |
234 // may have occurred while the initial managed bookmarks were being loaded | 230 // may have occurred while the initial managed bookmarks were being loaded |
235 // on the background. | 231 // on the background. |
236 managed_bookmarks_tracker_->Init(managed_node_); | 232 managed_bookmarks_tracker_->Init(managed_node_); |
237 } | 233 } |
238 | 234 |
239 // static | 235 // static |
240 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( | 236 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( |
241 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner, | |
242 scoped_ptr<BookmarkPermanentNode> managed_node, | 237 scoped_ptr<BookmarkPermanentNode> managed_node, |
243 scoped_ptr<base::ListValue> initial_managed_bookmarks, | 238 scoped_ptr<base::ListValue> initial_managed_bookmarks, |
244 int64* next_node_id) { | 239 int64* next_node_id) { |
245 DCHECK(profile_io_runner->RunsTasksOnCurrentThread()); | |
246 // Load the initial contents of the |managed_node| now, and assign it an | 240 // Load the initial contents of the |managed_node| now, and assign it an |
247 // unused ID. | 241 // unused ID. |
248 int64 managed_id = *next_node_id; | 242 int64 managed_id = *next_node_id; |
249 managed_node->set_id(managed_id); | 243 managed_node->set_id(managed_id); |
250 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial( | 244 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial( |
251 managed_node.get(), initial_managed_bookmarks.get(), managed_id + 1); | 245 managed_node.get(), initial_managed_bookmarks.get(), managed_id + 1); |
252 managed_node->set_visible(!managed_node->empty()); | 246 managed_node->set_visible(!managed_node->empty()); |
253 managed_node->SetTitle( | 247 managed_node->SetTitle( |
254 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); | 248 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); |
255 | 249 |
256 bookmarks::BookmarkPermanentNodeList extra_nodes; | 250 bookmarks::BookmarkPermanentNodeList extra_nodes; |
257 // Ownership of the managed node passed to the caller. | 251 // Ownership of the managed node passed to the caller. |
258 extra_nodes.push_back(managed_node.release()); | 252 extra_nodes.push_back(managed_node.release()); |
259 | 253 |
260 return extra_nodes.Pass(); | 254 return extra_nodes.Pass(); |
261 } | 255 } |
262 | 256 |
263 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { | 257 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { |
264 policy::ProfilePolicyConnector* connector = | 258 policy::ProfilePolicyConnector* connector = |
265 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); | 259 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); |
266 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) | 260 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) |
267 return connector->GetManagementDomain(); | 261 return connector->GetManagementDomain(); |
268 return std::string(); | 262 return std::string(); |
269 } | 263 } |
OLD | NEW |