From 2f2036951fa15033fdfa57759365eaaf945ac8f9 Mon Sep 17 00:00:00 2001 From: "thestig@chromium.org" Date: Sat, 2 Aug 2014 07:34:03 +0000 Subject: [PATCH] ifdef remaining extensions code in chrome/browser/browsing_data. BUG=349436 Review URL: https://codereview.chromium.org/428323002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287172 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/browsing_data/browsing_data_helper.cc | 4 +- .../browser/browsing_data/browsing_data_helper.h | 7 ++- .../browsing_data/browsing_data_helper_unittest.cc | 9 +++- .../browser/browsing_data/browsing_data_remover.cc | 8 ++- .../browser/browsing_data/browsing_data_remover.h | 3 -- chrome/browser/browsing_data/cookies_tree_model.cc | 18 +++++-- chrome/browser/browsing_data/cookies_tree_model.h | 6 ++- .../browsing_data/cookies_tree_model_unittest.cc | 57 +++++++++++++--------- chrome/browser/ui/webui/cookies_tree_model_util.cc | 9 +++- 9 files changed, 75 insertions(+), 46 deletions(-) diff --git a/chrome/browser/browsing_data/browsing_data_helper.cc b/chrome/browser/browsing_data/browsing_data_helper.cc index 0ab604fc43fb..839a5d874294 100644 --- a/chrome/browser/browsing_data/browsing_data_helper.cc +++ b/chrome/browser/browsing_data/browsing_data_helper.cc @@ -6,12 +6,12 @@ #include "base/command_line.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/url_constants.h" #include "content/public/browser/child_process_security_policy.h" #include "extensions/common/constants.h" #include "url/gurl.h" +#include "webkit/browser/quota/special_storage_policy.h" // Static bool BrowsingDataHelper::IsWebScheme(const std::string& scheme) { @@ -48,7 +48,7 @@ bool BrowsingDataHelper::HasExtensionScheme(const GURL& origin) { // Static bool BrowsingDataHelper::DoesOriginMatchMask(const GURL& origin, - int origin_set_mask, ExtensionSpecialStoragePolicy* policy) { + int origin_set_mask, quota::SpecialStoragePolicy* policy) { // Packaged apps and extensions match iff EXTENSION. if (BrowsingDataHelper::HasExtensionScheme(origin.GetOrigin()) && origin_set_mask & EXTENSION) diff --git a/chrome/browser/browsing_data/browsing_data_helper.h b/chrome/browser/browsing_data/browsing_data_helper.h index 1afacdb1147e..353b8732a816 100644 --- a/chrome/browser/browsing_data/browsing_data_helper.h +++ b/chrome/browser/browsing_data/browsing_data_helper.h @@ -11,7 +11,10 @@ #include "base/basictypes.h" -class ExtensionSpecialStoragePolicy; +namespace quota { +class SpecialStoragePolicy; +} + class GURL; class BrowsingDataHelper { @@ -38,7 +41,7 @@ class BrowsingDataHelper { // Returns true if the provided origin matches the provided mask. static bool DoesOriginMatchMask(const GURL& origin, int origin_set_mask, - ExtensionSpecialStoragePolicy* policy); + quota::SpecialStoragePolicy* policy); private: DISALLOW_IMPLICIT_CONSTRUCTORS(BrowsingDataHelper); diff --git a/chrome/browser/browsing_data/browsing_data_helper_unittest.cc b/chrome/browser/browsing_data/browsing_data_helper_unittest.cc index f78f3c4b02e3..853940e03c52 100644 --- a/chrome/browser/browsing_data/browsing_data_helper_unittest.cc +++ b/chrome/browser/browsing_data/browsing_data_helper_unittest.cc @@ -5,13 +5,16 @@ #include "chrome/browser/browsing_data/browsing_data_helper.h" #include "base/strings/stringprintf.h" -#include "chrome/browser/extensions/mock_extension_special_storage_policy.h" #include "chrome/common/url_constants.h" #include "extensions/common/constants.h" #include "testing/gtest/include/gtest/gtest.h" #include "url/gurl.h" #include "url/url_constants.h" +#if defined(ENABLE_EXTENSIONS) +#include "chrome/browser/extensions/mock_extension_special_storage_policy.h" +#endif + namespace { const char kTestOrigin1[] = "http://host1:1/"; @@ -49,7 +52,7 @@ class BrowsingDataHelperTest : public testing::Test { bool Match(const GURL& origin, int mask, - ExtensionSpecialStoragePolicy* policy) { + quota::SpecialStoragePolicy* policy) { return BrowsingDataHelper::DoesOriginMatchMask(origin, mask, policy); } @@ -104,6 +107,7 @@ TEST_F(BrowsingDataHelperTest, ChromeSchemesAreNotAllExtension) { EXPECT_FALSE(IsExtensionScheme(content::kViewSourceScheme)); } +#if defined(ENABLE_EXTENSIONS) TEST_F(BrowsingDataHelperTest, TestMatches) { scoped_refptr mock_policy = new MockExtensionSpecialStoragePolicy; @@ -153,6 +157,7 @@ TEST_F(BrowsingDataHelperTest, TestMatches) { kUnprotected | kProtected | kExtension, mock_policy.get())); } +#endif // If extensions are disabled, there is no policy. TEST_F(BrowsingDataHelperTest, TestNoPolicyMatches) { diff --git a/chrome/browser/browsing_data/browsing_data_remover.cc b/chrome/browser/browsing_data/browsing_data_remover.cc index b0f510d35e99..33b154578113 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.cc +++ b/chrome/browser/browsing_data/browsing_data_remover.cc @@ -20,8 +20,6 @@ #include "chrome/browser/domain_reliability/service_factory.h" #include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_service_factory.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/io_thread.h" @@ -87,6 +85,8 @@ #if defined(ENABLE_EXTENSIONS) #include "chrome/browser/apps/ephemeral_app_service.h" #include "chrome/browser/extensions/activity_log/activity_log.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_special_storage_policy.h" #endif #if defined(ENABLE_WEBRTC) @@ -110,8 +110,7 @@ bool DoesOriginMatchMask(int origin_set_mask, const GURL& origin, quota::SpecialStoragePolicy* special_storage_policy) { return BrowsingDataHelper::DoesOriginMatchMask( - origin, origin_set_mask, - static_cast(special_storage_policy)); + origin, origin_set_mask, special_storage_policy); } BrowsingDataRemover::NotificationDetails::NotificationDetails() @@ -184,7 +183,6 @@ BrowsingDataRemover::BrowsingDataRemover(Profile* profile, base::Time delete_begin, base::Time delete_end) : profile_(profile), - special_storage_policy_(profile->GetExtensionSpecialStoragePolicy()), delete_begin_(delete_begin), delete_end_(delete_end), next_cache_state_(STATE_NONE), diff --git a/chrome/browser/browsing_data/browsing_data_remover.h b/chrome/browser/browsing_data/browsing_data_remover.h index d4b91d7311d3..6ef5822d925b 100644 --- a/chrome/browser/browsing_data/browsing_data_remover.h +++ b/chrome/browser/browsing_data/browsing_data_remover.h @@ -388,9 +388,6 @@ class BrowsingDataRemover // Profile we're to remove from. Profile* profile_; - // 'Protected' origins are not subject to data removal. - scoped_refptr special_storage_policy_; - // Start time to delete from. const base::Time delete_begin_; diff --git a/chrome/browser/browsing_data/cookies_tree_model.cc b/chrome/browser/browsing_data/cookies_tree_model.cc index e326fd3c3ad2..fbeb58d96f88 100644 --- a/chrome/browser/browsing_data/cookies_tree_model.cc +++ b/chrome/browser/browsing_data/cookies_tree_model.cc @@ -16,10 +16,7 @@ #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" #include "chrome/browser/content_settings/cookie_settings.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/extensions/extension_special_storage_policy.h" #include "content/public/common/url_constants.h" -#include "extensions/common/extension_set.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" #include "grit/ui_resources.h" @@ -30,6 +27,11 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/image/image_skia.h" +#if defined(ENABLE_EXTENSIONS) +#include "chrome/browser/extensions/extension_special_storage_policy.h" +#include "extensions/common/extension_set.h" +#endif + namespace { struct NodeTitleComparator { @@ -111,6 +113,7 @@ std::string CanonicalizeHost(const GURL& url) { return retval; } +#if defined(ENABLE_EXTENSIONS) bool TypeIsProtected(CookieTreeNode::DetailedInfo::NodeType type) { switch (type) { case CookieTreeNode::DetailedInfo::TYPE_COOKIE: @@ -138,6 +141,7 @@ bool TypeIsProtected(CookieTreeNode::DetailedInfo::NodeType type) { } return false; } +#endif // This function returns the local data container associated with a leaf tree // node. The app node is assumed to be 3 levels above the leaf because of the @@ -867,7 +871,9 @@ CookiesTreeModel::CookiesTreeModel( bool group_by_cookie_source) : ui::TreeNodeModel(new CookieTreeRootNode(this)), data_container_(data_container), +#if defined(ENABLE_EXTENSIONS) special_storage_policy_(special_storage_policy), +#endif group_by_cookie_source_(group_by_cookie_source), batch_update_(0) { data_container_->Init(this); @@ -963,9 +969,10 @@ void CookiesTreeModel::UpdateSearchResults(const base::string16& filter) { PopulateChannelIDInfoWithFilter(data_container(), ¬ifier, filter); } +#if defined(ENABLE_EXTENSIONS) const extensions::ExtensionSet* CookiesTreeModel::ExtensionsProtectingNode( const CookieTreeNode& cookie_node) { - if (!special_storage_policy_.get()) + if (!special_storage_policy_) return NULL; CookieTreeNode::DetailedInfo info = cookie_node.GetDetailedInfo(); @@ -976,6 +983,7 @@ const extensions::ExtensionSet* CookiesTreeModel::ExtensionsProtectingNode( DCHECK(!info.origin.is_empty()); return special_storage_policy_->ExtensionsProtectingOrigin(info.origin); } +#endif void CookiesTreeModel::AddCookiesTreeObserver(Observer* observer) { cookies_observer_list_.AddObserver(observer); @@ -1015,7 +1023,7 @@ void CookiesTreeModel::PopulateSessionStorageInfo( PopulateSessionStorageInfoWithFilter(container, ¬ifier, base::string16()); } -void CookiesTreeModel::PopulateIndexedDBInfo(LocalDataContainer* container){ +void CookiesTreeModel::PopulateIndexedDBInfo(LocalDataContainer* container) { ScopedBatchUpdateNotifier notifier(this, GetRoot()); PopulateIndexedDBInfoWithFilter(container, ¬ifier, base::string16()); } diff --git a/chrome/browser/browsing_data/cookies_tree_model.h b/chrome/browser/browsing_data/cookies_tree_model.h index 00dcd11ce71d..5493828c33e5 100644 --- a/chrome/browser/browsing_data/cookies_tree_model.h +++ b/chrome/browser/browsing_data/cookies_tree_model.h @@ -428,7 +428,6 @@ class CookieTreeLocalStoragesNode : public CookieTreeNode { } private: - DISALLOW_COPY_AND_ASSIGN(CookieTreeLocalStoragesNode); }; @@ -468,7 +467,6 @@ class CookieTreeSessionStoragesNode : public CookieTreeNode { } private: - DISALLOW_COPY_AND_ASSIGN(CookieTreeSessionStoragesNode); }; @@ -640,12 +638,14 @@ class CookiesTreeModel : public ui::TreeNodeModel { // Filter the origins to only display matched results. void UpdateSearchResults(const base::string16& filter); +#if defined(ENABLE_EXTENSIONS) // Returns the set of extensions which protect the data item represented by // this node from deletion. // Returns NULL if the node doesn't represent a protected data item or the // special storage policy is NULL. const extensions::ExtensionSet* ExtensionsProtectingNode( const CookieTreeNode& cookie_node); +#endif // Manages CookiesTreeModel::Observers. This will also call // TreeNodeModel::AddObserver so that it gets all the proper notifications. @@ -718,8 +718,10 @@ class CookiesTreeModel : public ui::TreeNodeModel { // locally stored data. scoped_ptr data_container_; +#if defined(ENABLE_EXTENSIONS) // The extension special storage policy; see ExtensionsProtectingNode() above. scoped_refptr special_storage_policy_; +#endif // The CookiesTreeModel maintains a separate list of observers that are // specifically of the type CookiesTreeModel::Observer. diff --git a/chrome/browser/browsing_data/cookies_tree_model_unittest.cc b/chrome/browser/browsing_data/cookies_tree_model_unittest.cc index 7aefe78b8adc..1199e9a3a502 100644 --- a/chrome/browser/browsing_data/cookies_tree_model_unittest.cc +++ b/chrome/browser/browsing_data/cookies_tree_model_unittest.cc @@ -8,6 +8,7 @@ #include "base/message_loop/message_loop.h" #include "base/prefs/pref_service.h" +#include "base/strings/utf_string_conversions.h" #include "chrome/browser/browsing_data/mock_browsing_data_appcache_helper.h" #include "chrome/browser/browsing_data/mock_browsing_data_channel_id_helper.h" #include "chrome/browser/browsing_data/mock_browsing_data_cookie_helper.h" @@ -20,7 +21,6 @@ #include "chrome/browser/content_settings/cookie_settings.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/mock_settings_observer.h" -#include "chrome/browser/extensions/extension_special_storage_policy.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_types.h" @@ -29,7 +29,9 @@ #include "net/url_request/url_request_context_getter.h" #include "testing/gtest/include/gtest/gtest.h" -#include "base/strings/utf_string_conversions.h" +#if defined(ENABLE_EXTENSIONS) +#include "chrome/browser/extensions/extension_special_storage_policy.h" +#endif using ::testing::_; using content::BrowserThread; @@ -40,7 +42,9 @@ class CookiesTreeModelTest : public testing::Test { public: virtual ~CookiesTreeModelTest() { // Avoid memory leaks. +#if defined(ENABLE_EXTENSIONS) special_storage_policy_ = NULL; +#endif profile_.reset(); base::MessageLoop::current()->RunUntilIdle(); } @@ -71,8 +75,10 @@ class CookiesTreeModelTest : public testing::Test { scoped_refptr cookie_settings = new CookieSettings(profile_->GetHostContentSettingsMap(), profile_->GetPrefs()); +#if defined(ENABLE_EXTENSIONS) special_storage_policy_ = new ExtensionSpecialStoragePolicy(cookie_settings.get()); +#endif } virtual void TearDown() OVERRIDE { @@ -102,7 +108,7 @@ class CookiesTreeModelTest : public testing::Test { mock_browsing_data_flash_lso_helper_.get()); CookiesTreeModel* cookies_model = - new CookiesTreeModel(container, special_storage_policy_.get(), false); + new CookiesTreeModel(container, special_storage_policy(), false); mock_browsing_data_cookie_helper_-> AddCookieSamples(GURL("http://foo1"), "A=1"); mock_browsing_data_cookie_helper_-> @@ -191,29 +197,28 @@ class CookiesTreeModelTest : public testing::Test { switch (node_type) { case CookieTreeNode::DetailedInfo::TYPE_SESSION_STORAGE: - return node->GetDetailedInfo(). - session_storage_info->origin_url.spec() + ","; + return node->GetDetailedInfo().session_storage_info->origin_url.spec() + + ","; case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: - return node->GetDetailedInfo(). - local_storage_info->origin_url.spec() + ","; + return node->GetDetailedInfo().local_storage_info->origin_url.spec() + + ","; case CookieTreeNode::DetailedInfo::TYPE_DATABASE: return node->GetDetailedInfo().database_info->database_name + ","; case CookieTreeNode::DetailedInfo::TYPE_COOKIE: return node->GetDetailedInfo().cookie->Name() + ","; case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: return node->GetDetailedInfo().appcache_info->manifest_url.spec() + - ","; + ","; case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: return node->GetDetailedInfo().indexed_db_info->origin_.spec() + - ","; + ","; case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: return node->GetDetailedInfo().file_system_info->origin.spec() + - ","; + ","; case CookieTreeNode::DetailedInfo::TYPE_QUOTA: return node->GetDetailedInfo().quota_info->host + ","; case CookieTreeNode::DetailedInfo::TYPE_CHANNEL_ID: - return node->GetDetailedInfo( - ).channel_id->server_identifier() + ","; + return node->GetDetailedInfo().channel_id->server_identifier() + ","; case CookieTreeNode::DetailedInfo::TYPE_FLASH_LSO: return node->GetDetailedInfo().flash_lso_domain + ","; default: @@ -332,6 +337,14 @@ class CookiesTreeModelTest : public testing::Test { } protected: + ExtensionSpecialStoragePolicy* special_storage_policy() { +#if defined(ENABLE_EXTENSIONS) + return special_storage_policy_.get(); +#else + return NULL; +#endif + } + content::TestBrowserThreadBundle thread_bundle_; scoped_ptr profile_; scoped_refptr @@ -355,7 +368,9 @@ class CookiesTreeModelTest : public testing::Test { scoped_refptr mock_browsing_data_flash_lso_helper_; +#if defined(ENABLE_EXTENSIONS) scoped_refptr special_storage_policy_; +#endif }; TEST_F(CookiesTreeModelTest, RemoveAll) { @@ -818,8 +833,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNode) { mock_browsing_data_quota_helper_.get(), mock_browsing_data_channel_id_helper_.get(), mock_browsing_data_flash_lso_helper_.get()); - CookiesTreeModel cookies_model( - container, special_storage_policy_.get(), false); + CookiesTreeModel cookies_model(container, special_storage_policy(), false); mock_browsing_data_cookie_helper_-> AddCookieSamples(GURL("http://foo1"), "A=1"); @@ -907,8 +921,7 @@ TEST_F(CookiesTreeModelTest, RemoveSingleCookieNodeOf3) { mock_browsing_data_quota_helper_.get(), mock_browsing_data_channel_id_helper_.get(), mock_browsing_data_flash_lso_helper_.get()); - CookiesTreeModel cookies_model( - container, special_storage_policy_.get(), false); + CookiesTreeModel cookies_model(container, special_storage_policy(), false); mock_browsing_data_cookie_helper_-> AddCookieSamples(GURL("http://foo1"), "A=1"); @@ -999,8 +1012,7 @@ TEST_F(CookiesTreeModelTest, RemoveSecondOrigin) { mock_browsing_data_quota_helper_.get(), mock_browsing_data_channel_id_helper_.get(), mock_browsing_data_flash_lso_helper_.get()); - CookiesTreeModel cookies_model( - container, special_storage_policy_.get(), false); + CookiesTreeModel cookies_model(container, special_storage_policy(), false); mock_browsing_data_cookie_helper_-> AddCookieSamples(GURL("http://foo1"), "A=1"); @@ -1042,8 +1054,7 @@ TEST_F(CookiesTreeModelTest, OriginOrdering) { mock_browsing_data_quota_helper_.get(), mock_browsing_data_channel_id_helper_.get(), mock_browsing_data_flash_lso_helper_.get()); - CookiesTreeModel cookies_model( - container, special_storage_policy_.get(), false); + CookiesTreeModel cookies_model(container, special_storage_policy(), false); mock_browsing_data_cookie_helper_-> AddCookieSamples(GURL("http://a.foo2.com"), "A=1"); @@ -1090,8 +1101,7 @@ TEST_F(CookiesTreeModelTest, ContentSettings) { mock_browsing_data_quota_helper_.get(), mock_browsing_data_channel_id_helper_.get(), mock_browsing_data_flash_lso_helper_.get()); - CookiesTreeModel cookies_model( - container, special_storage_policy_.get(), false); + CookiesTreeModel cookies_model(container, special_storage_policy(), false); mock_browsing_data_cookie_helper_->AddCookieSamples(host, "A=1"); mock_browsing_data_cookie_helper_->Notify(); @@ -1164,8 +1174,7 @@ TEST_F(CookiesTreeModelTest, CookiesFilter) { mock_browsing_data_quota_helper_.get(), mock_browsing_data_channel_id_helper_.get(), mock_browsing_data_flash_lso_helper_.get()); - CookiesTreeModel cookies_model( - container, special_storage_policy_.get(), false); + CookiesTreeModel cookies_model(container, special_storage_policy(), false); mock_browsing_data_cookie_helper_-> AddCookieSamples(GURL("http://123.com"), "A=1"); diff --git a/chrome/browser/ui/webui/cookies_tree_model_util.cc b/chrome/browser/ui/webui/cookies_tree_model_util.cc index ff1f6108d9e3..83aaf4940fe7 100644 --- a/chrome/browser/ui/webui/cookies_tree_model_util.cc +++ b/chrome/browser/ui/webui/cookies_tree_model_util.cc @@ -15,7 +15,6 @@ #include "base/values.h" #include "chrome/browser/browsing_data/cookies_tree_model.h" #include "content/public/browser/indexed_db_context.h" -#include "extensions/common/extension_set.h" #include "grit/generated_resources.h" #include "net/cookies/canonical_cookie.h" #include "net/ssl/ssl_client_cert_type.h" @@ -23,6 +22,10 @@ #include "ui/base/text/bytes_formatting.h" #include "webkit/common/fileapi/file_system_types.h" +#if defined(ENABLE_EXTENSIONS) +#include "extensions/common/extension_set.h" +#endif + namespace { const char kKeyId[] = "id"; @@ -31,7 +34,9 @@ const char kKeyIcon[] = "icon"; const char kKeyType[] = "type"; const char kKeyHasChildren[] = "hasChildren"; +#if defined(ENABLE_EXTENSIONS) const char kKeyAppsProtectingThis[] = "appsProtectingThis"; +#endif const char kKeyName[] = "name"; const char kKeyContent[] = "content"; const char kKeyDomain[] = "domain"; @@ -269,6 +274,7 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( break; } +#if defined(ENABLE_EXTENSIONS) const extensions::ExtensionSet* protecting_apps = node.GetModel()->ExtensionsProtectingNode(node); if (protecting_apps && !protecting_apps->is_empty()) { @@ -282,6 +288,7 @@ bool CookiesTreeModelUtil::GetCookieTreeNodeDictionary( } dict->Set(kKeyAppsProtectingThis, app_infos); } +#endif return true; } -- 2.11.4.GIT