Chromium Code Reviews| 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/debug/leak_annotations.h" | 9 #include "base/debug/leak_annotations.h" |
|
gab
2014/07/07 18:13:38
Also, rm this include
Sigurður Ásgeirsson
2014/07/07 18:40:19
Done.
| |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/favicon/favicon_changed_details.h" | 13 #include "chrome/browser/favicon/favicon_changed_details.h" |
| 14 #include "chrome/browser/favicon/favicon_service.h" | 14 #include "chrome/browser/favicon/favicon_service.h" |
| 15 #include "chrome/browser/favicon/favicon_service_factory.h" | 15 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 16 #include "chrome/browser/history/history_service.h" | 16 #include "chrome/browser/history/history_service.h" |
| 17 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
| 18 #include "chrome/browser/policy/profile_policy_connector.h" | 18 #include "chrome/browser/policy/profile_policy_connector.h" |
| 19 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 19 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 #endif | 158 #endif |
| 159 } | 159 } |
| 160 | 160 |
| 161 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) { | 161 void ChromeBookmarkClient::RecordAction(const base::UserMetricsAction& action) { |
| 162 content::RecordAction(action); | 162 content::RecordAction(action); |
| 163 } | 163 } |
| 164 | 164 |
| 165 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() { | 165 bookmarks::LoadExtraCallback ChromeBookmarkClient::GetLoadExtraNodesCallback() { |
| 166 // Create the managed_node now; it will be populated in the LoadExtraNodes | 166 // Create the managed_node now; it will be populated in the LoadExtraNodes |
| 167 // callback. | 167 // callback. |
| 168 managed_node_ = new BookmarkPermanentNode(0); | 168 // The ownership of maanaged_node_ is in limbo until LoadExtraNodes runs, |
|
gab
2014/07/07 18:12:47
s/maanaged/managed
Sigurður Ásgeirsson
2014/07/07 18:40:19
Done.
| |
| 169 // The ownership of this object is in limbo until the LoadExtraNodes task | 169 // so we leave it in the care of the closure meanwhile. |
| 170 // runs, but in a ProfileBrowserTest this never happens. | 170 scoped_ptr<BookmarkPermanentNode> managed(new BookmarkPermanentNode(0)); |
| 171 // crbug.com/391508 | 171 managed_node_ = managed.get(); |
|
gab
2014/07/07 18:12:47
So is the only purpose of storing this as a member
Sigurður Ásgeirsson
2014/07/07 18:40:19
The member is used by ChromeBookmarkClient::Bookma
| |
| 172 ANNOTATE_LEAKING_OBJECT_PTR(managed_node_); | |
| 173 | 172 |
| 174 return base::Bind( | 173 return base::Bind( |
| 175 &ChromeBookmarkClient::LoadExtraNodes, | 174 &ChromeBookmarkClient::LoadExtraNodes, |
| 176 StartupTaskRunnerServiceFactory::GetForProfile(profile_) | 175 StartupTaskRunnerServiceFactory::GetForProfile(profile_) |
| 177 ->GetBookmarkTaskRunner(), | 176 ->GetBookmarkTaskRunner(), |
| 178 managed_node_, | 177 base::Passed(&managed), |
| 179 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks())); | 178 base::Passed(managed_bookmarks_tracker_->GetInitialManagedBookmarks())); |
| 180 } | 179 } |
| 181 | 180 |
| 182 bool ChromeBookmarkClient::CanSetPermanentNodeTitle( | 181 bool ChromeBookmarkClient::CanSetPermanentNodeTitle( |
| 183 const BookmarkNode* permanent_node) { | 182 const BookmarkNode* permanent_node) { |
| 184 // The |managed_node_| can have its title updated if the user signs in or | 183 // The |managed_node_| can have its title updated if the user signs in or |
| 185 // out. | 184 // out. |
| 186 return !IsDescendantOfManagedNode(permanent_node) || | 185 return !IsDescendantOfManagedNode(permanent_node) || |
| 187 permanent_node == managed_node_; | 186 permanent_node == managed_node_; |
| 188 } | 187 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 bool ids_reassigned) { | 233 bool ids_reassigned) { |
| 235 // Start tracking the managed bookmarks. This will detect any changes that | 234 // Start tracking the managed bookmarks. This will detect any changes that |
| 236 // may have occurred while the initial managed bookmarks were being loaded | 235 // may have occurred while the initial managed bookmarks were being loaded |
| 237 // on the background. | 236 // on the background. |
| 238 managed_bookmarks_tracker_->Init(managed_node_); | 237 managed_bookmarks_tracker_->Init(managed_node_); |
| 239 } | 238 } |
| 240 | 239 |
| 241 // static | 240 // static |
| 242 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( | 241 bookmarks::BookmarkPermanentNodeList ChromeBookmarkClient::LoadExtraNodes( |
| 243 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner, | 242 const scoped_refptr<base::DeferredSequencedTaskRunner>& profile_io_runner, |
| 244 BookmarkPermanentNode* managed_node, | 243 scoped_ptr<BookmarkPermanentNode> managed_node, |
| 245 scoped_ptr<base::ListValue> initial_managed_bookmarks, | 244 scoped_ptr<base::ListValue> initial_managed_bookmarks, |
| 246 int64* next_node_id) { | 245 int64* next_node_id) { |
| 247 DCHECK(profile_io_runner->RunsTasksOnCurrentThread()); | 246 DCHECK(profile_io_runner->RunsTasksOnCurrentThread()); |
| 248 // Load the initial contents of the |managed_node| now, and assign it an | 247 // Load the initial contents of the |managed_node| now, and assign it an |
| 249 // unused ID. | 248 // unused ID. |
| 250 int64 managed_id = *next_node_id; | 249 int64 managed_id = *next_node_id; |
| 251 managed_node->set_id(managed_id); | 250 managed_node->set_id(managed_id); |
| 252 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial( | 251 *next_node_id = policy::ManagedBookmarksTracker::LoadInitial( |
| 253 managed_node, initial_managed_bookmarks.get(), managed_id + 1); | 252 managed_node.get(), initial_managed_bookmarks.get(), managed_id + 1); |
| 254 managed_node->set_visible(!managed_node->empty()); | 253 managed_node->set_visible(!managed_node->empty()); |
| 255 managed_node->SetTitle( | 254 managed_node->SetTitle( |
| 256 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); | 255 l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME)); |
| 257 | 256 |
| 258 bookmarks::BookmarkPermanentNodeList extra_nodes; | 257 bookmarks::BookmarkPermanentNodeList extra_nodes; |
| 259 extra_nodes.push_back(managed_node); | 258 // Ownership of the managed node passed to the caller. |
| 259 extra_nodes.push_back(managed_node.release()); | |
| 260 | |
| 260 return extra_nodes.Pass(); | 261 return extra_nodes.Pass(); |
| 261 } | 262 } |
| 262 | 263 |
| 263 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { | 264 std::string ChromeBookmarkClient::GetManagedBookmarksDomain() { |
| 264 policy::ProfilePolicyConnector* connector = | 265 policy::ProfilePolicyConnector* connector = |
| 265 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); | 266 policy::ProfilePolicyConnectorFactory::GetForProfile(profile_); |
| 266 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) | 267 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks)) |
| 267 return connector->GetManagementDomain(); | 268 return connector->GetManagementDomain(); |
| 268 return std::string(); | 269 return std::string(); |
| 269 } | 270 } |
| OLD | NEW |