Commit a9ea2fbe authored by treib's avatar treib Committed by Commit bot

Move ManagedBookmarksTracker from policy/core/browser to (new) bookmarks/managed.

After https://codereview.chromium.org/769153007, it handles more than policy.

BUG=443606

Review URL: https://codereview.chromium.org/961683002

Cr-Commit-Position: refs/heads/master@{#321539}
parent 26fbaa28
......@@ -82,6 +82,7 @@ static_library("browser") {
"//chrome/common/net",
"//components/autofill/core/browser",
"//components/bookmarks/browser",
"//components/bookmarks/managed",
"//components/captive_portal",
"//components/cloud_devices/common",
"//components/component_updater",
......
......@@ -20,6 +20,7 @@ include_rules = [
"+components/autofill/core/common",
"+components/bookmarks/browser",
"+components/bookmarks/common",
"+components/bookmarks/managed",
"+components/bookmarks/test",
"+components/browser_watcher",
"+components/cdm/browser",
......
......@@ -15,6 +15,7 @@
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_node.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/managed/managed_bookmarks_tracker.h"
#include "components/favicon/core/browser/favicon_service.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/browser/url_database.h"
......@@ -29,6 +30,7 @@
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
using bookmarks::BookmarkPermanentNode;
using bookmarks::ManagedBookmarksTracker;
namespace {
......@@ -52,7 +54,7 @@ void LoadInitialContents(BookmarkPermanentNode* node,
// Load the initial contents of the |node| now, and assign it an unused ID.
int64 id = *next_node_id;
node->set_id(id);
*next_node_id = policy::ManagedBookmarksTracker::LoadInitial(
*next_node_id = ManagedBookmarksTracker::LoadInitial(
node, initial_bookmarks, id + 1);
node->set_visible(!node->empty());
}
......@@ -76,13 +78,13 @@ void ChromeBookmarkClient::Init(BookmarkModel* model) {
model_ = model;
model_->AddObserver(this);
managed_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker(
managed_bookmarks_tracker_.reset(new ManagedBookmarksTracker(
model_,
profile_->GetPrefs(),
false,
base::Bind(&ChromeBookmarkClient::GetManagedBookmarksDomain,
base::Unretained(this))));
supervised_bookmarks_tracker_.reset(new policy::ManagedBookmarksTracker(
supervised_bookmarks_tracker_.reset(new ManagedBookmarksTracker(
model_,
profile_->GetPrefs(),
true,
......
......@@ -13,14 +13,20 @@
#include "base/macros.h"
#include "components/bookmarks/browser/base_bookmark_model_observer.h"
#include "components/bookmarks/browser/bookmark_client.h"
#include "components/policy/core/browser/managed_bookmarks_tracker.h"
class GURL;
class HistoryServiceFactory;
class Profile;
namespace base {
class ListValue;
}
namespace bookmarks {
class BookmarkModel;
class BookmarkNode;
class BookmarkPermanentNode;
class ManagedBookmarksTracker;
}
namespace history {
......@@ -107,12 +113,12 @@ class ChromeBookmarkClient : public bookmarks::BookmarkClient,
bookmarks::BookmarkModel* model_;
// Managed bookmarks are defined by an enterprise policy.
scoped_ptr<policy::ManagedBookmarksTracker> managed_bookmarks_tracker_;
scoped_ptr<bookmarks::ManagedBookmarksTracker> managed_bookmarks_tracker_;
// The top-level managed bookmarks folder.
bookmarks::BookmarkPermanentNode* managed_node_;
// Supervised bookmarks are defined by the custodian of a supervised user.
scoped_ptr<policy::ManagedBookmarksTracker> supervised_bookmarks_tracker_;
scoped_ptr<bookmarks::ManagedBookmarksTracker> supervised_bookmarks_tracker_;
// The top-level supervised bookmarks folder.
bookmarks::BookmarkPermanentNode* supervised_node_;
......
......@@ -7,13 +7,15 @@
#include "base/prefs/pref_value_map.h"
#include "base/values.h"
#include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/policy/core/browser/managed_bookmarks_tracker.h"
#include "components/bookmarks/managed/managed_bookmarks_tracker.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
#include "components/url_fixer/url_fixer.h"
#include "policy/policy_constants.h"
#include "url/gurl.h"
using bookmarks::ManagedBookmarksTracker;
namespace policy {
ManagedBookmarksPolicyHandler::ManagedBookmarksPolicyHandler(
......
......@@ -2910,6 +2910,7 @@
'probe_message_proto',
'../components/components.gyp:autofill_core_browser',
'../components/components.gyp:bookmarks_browser',
'../components/components.gyp:bookmarks_managed',
'../components/components.gyp:captive_portal',
'../components/components.gyp:cloud_devices_common',
'../components/components.gyp:component_metrics_proto',
......
......@@ -20,6 +20,7 @@ group("all_components") {
"//components/autofill/content/renderer",
"//components/bookmarks/browser",
"//components/bookmarks/common",
"//components/bookmarks/managed",
"//components/bookmarks/test",
"//components/captive_portal",
"//components/cdm/browser",
......@@ -237,6 +238,7 @@ test("components_unittests") {
"//components/autofill/core/browser:unit_tests",
"//components/autofill/core/common:unit_tests",
"//components/bookmarks/browser:unit_tests",
"//components/bookmarks/managed:unit_tests",
"//components/captive_portal:unit_tests",
"//components/cloud_devices/common:unit_tests",
"//components/content_settings/core/browser:unit_tests",
......
......@@ -95,6 +95,22 @@
'bookmarks/common/bookmark_pref_names.h',
],
},
{
# GN version: //components/bookmarks/managed
'target_name': 'bookmarks_managed',
'type': 'static_library',
'include_dirs': [
'..',
],
'dependencies': [
'bookmarks_browser',
'components_strings.gyp:components_strings',
],
'sources': [
'bookmarks/managed/managed_bookmarks_tracker.cc',
'bookmarks/managed/managed_bookmarks_tracker.h',
],
},
{
# GN version: //components/bookmarks/test
'target_name': 'bookmarks_test_support',
......
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("managed") {
sources = [
"managed_bookmarks_tracker.cc",
"managed_bookmarks_tracker.h",
]
deps = [
"//components/bookmarks/browser",
"//components/strings",
]
}
source_set("unit_tests") {
testonly = true
sources = [
"managed_bookmarks_tracker_unittest.cc",
]
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
deps = [
":managed",
"//components/bookmarks/test",
"//components/strings",
"//testing/gmock",
"//testing/gtest",
]
}
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/policy/core/browser/managed_bookmarks_tracker.h"
#include "components/bookmarks/managed/managed_bookmarks_tracker.h"
#include <string>
......@@ -20,11 +20,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
using bookmarks::BookmarkPermanentNode;
namespace policy {
namespace bookmarks {
const char ManagedBookmarksTracker::kName[] = "name";
const char ManagedBookmarksTracker::kUrl[] = "url";
......@@ -90,8 +86,8 @@ void ManagedBookmarksTracker::Init(BookmarkPermanentNode* managed_node) {
// static
const char* ManagedBookmarksTracker::GetPrefName(bool is_supervised) {
return is_supervised ? bookmarks::prefs::kSupervisedBookmarks
: bookmarks::prefs::kManagedBookmarks;
return is_supervised ? prefs::kSupervisedBookmarks
: prefs::kManagedBookmarks;
}
const char* ManagedBookmarksTracker::GetPrefName() const {
......
......@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_
#define COMPONENTS_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_
#ifndef COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARKS_TRACKER_H_
#define COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARKS_TRACKER_H_
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/prefs/pref_change_registrar.h"
#include "base/strings/string16.h"
#include "components/policy/policy_export.h"
class GURL;
class PrefService;
......@@ -19,18 +18,16 @@ class ListValue;
}
namespace bookmarks {
class BookmarkModel;
class BookmarkNode;
class BookmarkPermanentNode;
}
namespace policy {
// Tracks either the Managed Bookmarks pref (set by policy) or the Supervised
// Bookmarks pref (set for a supervised user by their custodian) and makes the
// managed_node()/supervised_node() in the BookmarkModel follow the
// policy/custodian-defined bookmark tree.
class POLICY_EXPORT ManagedBookmarksTracker {
class ManagedBookmarksTracker {
public:
typedef base::Callback<std::string()> GetManagementDomainCallback;
......@@ -91,7 +88,7 @@ class POLICY_EXPORT ManagedBookmarksTracker {
DISALLOW_COPY_AND_ASSIGN(ManagedBookmarksTracker);
};
} // namespace policy
} // namespace bookmarks
#endif // COMPONENTS_POLICY_CORE_BROWSER_MANAGED_BOOKMARKS_TRACKER_H_
#endif // COMPONENTS_BOOKMARKS_MANAGED_MANAGED_BOOKMARKS_TRACKER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/policy/core/browser/managed_bookmarks_tracker.h"
#include "components/bookmarks/managed/managed_bookmarks_tracker.h"
#include "base/bind.h"
#include "base/files/file_path.h"
......@@ -24,13 +24,10 @@
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
using bookmarks::BookmarkModel;
using bookmarks::BookmarkNode;
using bookmarks::BookmarkPermanentNode;
using testing::Mock;
using testing::_;
namespace policy {
namespace bookmarks {
class ManagedBookmarksTrackerTest : public testing::Test {
public:
......@@ -52,7 +49,7 @@ class ManagedBookmarksTrackerTest : public testing::Test {
void CreateModel(bool is_supervised) {
// Simulate the creation of the managed node by the BookmarkClient.
BookmarkPermanentNode* managed_node = new BookmarkPermanentNode(100);
policy::ManagedBookmarksTracker::LoadInitial(
ManagedBookmarksTracker::LoadInitial(
managed_node,
prefs_.GetList(ManagedBookmarksTracker::GetPrefName(is_supervised)),
101);
......@@ -344,4 +341,4 @@ TEST_F(ManagedBookmarksTrackerTest, RemoveAllUserBookmarksDoesntRemoveManaged) {
Mock::VerifyAndClearExpectations(&observer_);
}
} // namespace policy
} // namespace bookmarks
......@@ -69,6 +69,7 @@
'bookmarks/browser/bookmark_index_unittest.cc',
'bookmarks/browser/bookmark_model_unittest.cc',
'bookmarks/browser/bookmark_utils_unittest.cc',
'bookmarks/managed/managed_bookmarks_tracker_unittest.cc',
],
'browser_watcher_unittest_sources': [
'browser_watcher/endsession_watcher_window_win_unittest.cc',
......@@ -329,7 +330,6 @@
'policy/core/browser/browser_policy_connector_unittest.cc',
'policy/core/browser/configuration_policy_handler_unittest.cc',
'policy/core/browser/configuration_policy_pref_store_unittest.cc',
'policy/core/browser/managed_bookmarks_tracker_unittest.cc',
'policy/core/browser/url_blacklist_policy_handler_unittest.cc',
'policy/core/common/async_policy_provider_unittest.cc',
'policy/core/common/cloud/cloud_policy_client_unittest.cc',
......@@ -658,6 +658,7 @@
'components.gyp:autofill_core_common',
'components.gyp:autofill_core_test_support',
'components.gyp:bookmarks_browser',
'components.gyp:bookmarks_managed',
'components.gyp:bookmarks_test_support',
'components.gyp:captive_portal_test_support',
'components.gyp:cloud_devices_common',
......
......@@ -20,7 +20,7 @@ source_set("browser") {
"//base",
"//base:prefs",
"//base/third_party/dynamic_annotations",
"//components/bookmarks/browser",
"//components/bookmarks/managed",
"//components/keyed_service/core",
"//components/pref_registry",
"//components/strings",
......@@ -45,8 +45,6 @@ source_set("browser") {
"configuration_policy_handler_list.h",
"configuration_policy_pref_store.cc",
"configuration_policy_pref_store.h",
"managed_bookmarks_tracker.cc",
"managed_bookmarks_tracker.h",
"policy_error_map.cc",
"policy_error_map.h",
"url_blacklist_policy_handler.cc",
......
......@@ -11,6 +11,7 @@
'../ui/base/ui_base.gyp:ui_base',
'../url/url.gyp:url_lib',
'bookmarks_browser',
'bookmarks_managed',
'components_strings.gyp:components_strings',
'keyed_service_core',
'pref_registry',
......@@ -55,8 +56,6 @@
'core/browser/configuration_policy_handler_list.h',
'core/browser/configuration_policy_pref_store.cc',
'core/browser/configuration_policy_pref_store.h',
'core/browser/managed_bookmarks_tracker.cc',
'core/browser/managed_bookmarks_tracker.h',
'core/browser/policy_error_map.cc',
'core/browser/policy_error_map.h',
'core/browser/url_blacklist_policy_handler.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment