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

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

Issue 372663002: Fix BookmarkPermanentNode leak in ChromeBookmarkClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Gab's comments. Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/bookmarks/chrome_bookmark_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/leak_annotations.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/values.h" 10 #include "base/values.h"
12 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/favicon/favicon_changed_details.h" 12 #include "chrome/browser/favicon/favicon_changed_details.h"
14 #include "chrome/browser/favicon/favicon_service.h" 13 #include "chrome/browser/favicon/favicon_service.h"
15 #include "chrome/browser/favicon/favicon_service_factory.h" 14 #include "chrome/browser/favicon/favicon_service_factory.h"
16 #include "chrome/browser/history/history_service.h" 15 #include "chrome/browser/history/history_service.h"
17 #include "chrome/browser/history/history_service_factory.h" 16 #include "chrome/browser/history/history_service_factory.h"
18 #include "chrome/browser/policy/profile_policy_connector.h" 17 #include "chrome/browser/policy/profile_policy_connector.h"
19 #include "chrome/browser/policy/profile_policy_connector_factory.h" 18 #include "chrome/browser/policy/profile_policy_connector_factory.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 #endif 157 #endif
159 } 158 }
160 159
161 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) { 160 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) {
162 content::RecordAction(action); 161 content::RecordAction(action);
163 } 162 }
164 163
165 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() { 164 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() {
166 // Create the managed_node now; it will be populated in the LoadExtraNodes 165 // Create the managed_node now; it will be populated in the LoadExtraNodes
167 // callback. 166 // callback.
168 managed_node_ = new BookmarkPermanentNode(0); 167 // The ownership of managed_node_ is in limbo until LoadExtraNodes runs,
169 // The ownership of this object is in limbo until the LoadExtraNodes task 168 // so we leave it in the care of the closure meanwhile.
170 // runs, but in a ProfileBrowserTest this never happens. 169 scoped_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0));
171 // crbug.com/391508 170 managed_node_ = managed.get();
172 ANNOTATE_LEAKING_OBJECT_PTR(managed_node_);
173 171
174 return base::Bind( 172 return base::Bind(
175 &ChromeBookmarkClient::LoadExtraNodes, 173 &ChromeBookmarkClient::LoadExtraNodes,
176 StartupTaskRunnerServiceFactory::GetForProfile(profile_) 174 StartupTaskRunnerServiceFactory::GetForProfile(profile_)
177 ->GetBookmarkTaskRunner(), 175 ->GetBookmarkTaskRunner(),
178 managed_node_, 176 base::Passed(&managed),
179 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks())); 177 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks()));
180 } 178 }
181 179
182 bool ChromeBookmarkClient::CanSetPermanentNodeTitle( 180 bool ChromeBookmarkClient::CanSetPermanentNodeTitle(
183 const BookmarkNode* permanent_node) { 181 const BookmarkNode* permanent_node) {
184 // The |managed_node_| can have its title updated if the user signs in or 182 // The |managed_node_| can have its title updated if the user signs in or
185 // out. 183 // out.
186 return !IsDescendantOfManagedNode(permanent_node) || 184 return !IsDescendantOfManagedNode(permanent_node) ||
187 permanent_node == managed_node_; 185 permanent_node == managed_node_;
188 } 186 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 bool ids_reassigned) { 232 bool ids_reassigned) {
235 // Start tracking the managed bookmarks. This will detect any changes that 233 // Start tracking the managed bookmarks. This will detect any changes that
236 // may have occurred while the initial managed bookmarks were being loaded 234 // may have occurred while the initial managed bookmarks were being loaded
237 // on the background. 235 // on the background.
238 managed_bookmarks_tracker_->Init(managed_node_); 236 managed_bookmarks_tracker_->Init(managed_node_);
239 } 237 }
240 238
241 // static 239 // static
242 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( 240 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes(
243 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner, 241 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner,
244 BookmarkPermanentNode* managed_node, 242 scoped_ptr<BookmarkPermanentNode> managed_node,
245 scoped_ptr<base::ListValue> initial_managed_bookmarks, 243 scoped_ptr<base::ListValue> initial_managed_bookmarks,
246 int64* next_node_id) { 244 int64* next_node_id) {
247 DCHECK(profile_io_runner->RunsTasksOnCurrentThread()); 245 DCHECK(profile_io_runner->RunsTasksOnCurrentThread());
248 // Load the initial contents of the |managed_node| now, and assign it an 246 // Load the initial contents of the |managed_node| now, and assign it an
249 // unused ID. 247 // unused ID.
250 int64 managed_id = *next_node_id; 248 int64 managed_id = *next_node_id;
251 managed_node->set_id(managed_id); 249 managed_node->set_id(managed_id);
252 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial( 250 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial(
253 managed_node, initial_managed_bookmarks.get(), managed_id + 1); 251 managed_node.get(), initial_managed_bookmarks.get(), managed_id + 1);
254 managed_node->set_visible(!managed_node->empty()); 252 managed_node->set_visible(!managed_node->empty());
255 managed_node->SetTitle( 253 managed_node->SetTitle(
256 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); 254 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME));
257 255
258 bookmarks::BookmarkPermanentNodeList extra_nodes; 256 bookmarks::BookmarkPermanentNodeList extra_nodes;
259 extra_nodes.push_back(managed_node); 257 // Ownership of the managed node passed to the caller.
258 extra_nodes.push_back(managed_node.release());
259
260 return extra_nodes.Pass(); 260 return extra_nodes.Pass();
261 } 261 }
262 262
263 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { 263 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() {
264 policy::ProfilePolicyConnector* connector = 264 policy::ProfilePolicyConnector* connector =
265 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); 265 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_);
266 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) 266 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks))
267 return connector->GetManagementDomain(); 267 return connector->GetManagementDomain();
268 return std::string(); 268 return std::string();
269 } 269 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/chrome_bookmark_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698