CookieStore::DeleteCookieAsync appears unused (outside a few tests), so remove it

Change-Id: I8530a8b376f000e075d57ebeb70401b2092456f6
Reviewed-on: https://chromium-review.googlesource.com/c/1456677
Reviewed-by: Eugene But <eugenebut@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Mohammad Refaat <mrefaat@chromium.org>
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631818}
diff --git a/android_webview/browser/net/aw_cookie_store_wrapper.cc b/android_webview/browser/net/aw_cookie_store_wrapper.cc
index d5cbf30f..afa6edb 100644
--- a/android_webview/browser/net/aw_cookie_store_wrapper.cc
+++ b/android_webview/browser/net/aw_cookie_store_wrapper.cc
@@ -47,12 +47,6 @@
   GetCookieStore()->GetAllCookiesAsync(std::move(callback));
 }
 
-void DeleteCookieAsyncOnCookieThread(const GURL& url,
-                                     const std::string& cookie_name,
-                                     base::OnceClosure callback) {
-  GetCookieStore()->DeleteCookieAsync(url, cookie_name, std::move(callback));
-}
-
 void DeleteCanonicalCookieAsyncOnCookieThread(
     const net::CanonicalCookie& cookie,
     net::CookieStore::DeleteCallback callback) {
@@ -133,15 +127,6 @@
                      CreateWrappedGetCookieListCallback(std::move(callback))));
 }
 
-void AwCookieStoreWrapper::DeleteCookieAsync(const GURL& url,
-                                             const std::string& cookie_name,
-                                             base::OnceClosure callback) {
-  DCHECK(client_task_runner_->RunsTasksInCurrentSequence());
-  PostTaskToCookieStoreTaskRunner(
-      base::BindOnce(&DeleteCookieAsyncOnCookieThread, url, cookie_name,
-                     CreateWrappedClosureCallback(std::move(callback))));
-}
-
 void AwCookieStoreWrapper::DeleteCanonicalCookieAsync(
     const net::CanonicalCookie& cookie,
     DeleteCallback callback) {
diff --git a/android_webview/browser/net/aw_cookie_store_wrapper.h b/android_webview/browser/net/aw_cookie_store_wrapper.h
index bef80a5..dc55e5a 100644
--- a/android_webview/browser/net/aw_cookie_store_wrapper.h
+++ b/android_webview/browser/net/aw_cookie_store_wrapper.h
@@ -55,9 +55,6 @@
                                      const net::CookieOptions& options,
                                      GetCookieListCallback callback) override;
   void GetAllCookiesAsync(GetCookieListCallback callback) override;
-  void DeleteCookieAsync(const GURL& url,
-                         const std::string& cookie_name,
-                         base::OnceClosure callback) override;
   void DeleteCanonicalCookieAsync(const net::CanonicalCookie& cookie,
                                   DeleteCallback callback) override;
   void DeleteAllCreatedInTimeRangeAsync(
diff --git a/ios/net/cookies/cookie_store_ios.h b/ios/net/cookies/cookie_store_ios.h
index ed06499..e7bb38f 100644
--- a/ios/net/cookies/cookie_store_ios.h
+++ b/ios/net/cookies/cookie_store_ios.h
@@ -95,9 +95,6 @@
                                      const net::CookieOptions& options,
                                      GetCookieListCallback callback) override;
   void GetAllCookiesAsync(GetCookieListCallback callback) override;
-  void DeleteCookieAsync(const GURL& url,
-                         const std::string& cookie_name,
-                         base::OnceClosure callback) override;
   void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
                                   DeleteCallback callback) override;
   void DeleteAllCreatedInTimeRangeAsync(
diff --git a/ios/net/cookies/cookie_store_ios.mm b/ios/net/cookies/cookie_store_ios.mm
index 821c1a05..3cbabb6 100644
--- a/ios/net/cookies/cookie_store_ios.mm
+++ b/ios/net/cookies/cookie_store_ios.mm
@@ -385,33 +385,6 @@
                      weak_factory_.GetWeakPtr(), base::Passed(&callback)));
 }
 
-void CookieStoreIOS::DeleteCookieAsync(const GURL& url,
-                                       const std::string& cookie_name,
-                                       base::OnceClosure callback) {
-  DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
-
-  // If cookies are not allowed, a CookieStoreIOS subclass should be used
-  // instead.
-  DCHECK(SystemCookiesAllowed());
-
-  __block base::OnceClosure shared_callback = std::move(callback);
-  base::WeakPtr<SystemCookieStore> weak_system_store =
-      system_store_->GetWeakPtr();
-  system_store_->GetCookiesForURLAsync(
-      url, base::BindOnce(^(NSArray<NSHTTPCookie*>* cookies) {
-        for (NSHTTPCookie* cookie in cookies) {
-          if ([cookie.name
-                  isEqualToString:base::SysUTF8ToNSString(cookie_name)] &&
-              weak_system_store) {
-            weak_system_store->DeleteCookieAsync(
-                cookie, SystemCookieStore::SystemCookieCallback());
-          }
-        }
-        if (!shared_callback.is_null())
-          std::move(shared_callback).Run();
-      }));
-}
-
 void CookieStoreIOS::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
                                                 DeleteCallback callback) {
   DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
diff --git a/ios/net/cookies/cookie_store_ios_persistent.h b/ios/net/cookies/cookie_store_ios_persistent.h
index 617b951..46b5fef 100644
--- a/ios/net/cookies/cookie_store_ios_persistent.h
+++ b/ios/net/cookies/cookie_store_ios_persistent.h
@@ -54,9 +54,6 @@
                                      const net::CookieOptions& options,
                                      GetCookieListCallback callback) override;
   void GetAllCookiesAsync(GetCookieListCallback callback) override;
-  void DeleteCookieAsync(const GURL& url,
-                         const std::string& cookie_name,
-                         base::OnceClosure callback) override;
   void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
                                   DeleteCallback callback) override;
   void DeleteAllCreatedInTimeRangeAsync(
diff --git a/ios/net/cookies/cookie_store_ios_persistent.mm b/ios/net/cookies/cookie_store_ios_persistent.mm
index 00e9fa7..d779f89 100644
--- a/ios/net/cookies/cookie_store_ios_persistent.mm
+++ b/ios/net/cookies/cookie_store_ios_persistent.mm
@@ -98,14 +98,6 @@
   cookie_monster()->GetAllCookiesAsync(std::move(callback));
 }
 
-void CookieStoreIOSPersistent::DeleteCookieAsync(const GURL& url,
-                                                 const std::string& cookie_name,
-                                                 base::OnceClosure callback) {
-  DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
-  cookie_monster()->DeleteCookieAsync(url, cookie_name,
-                                      WrapClosure(std::move(callback)));
-}
-
 void CookieStoreIOSPersistent::DeleteCanonicalCookieAsync(
     const CanonicalCookie& cookie,
     DeleteCallback callback) {
diff --git a/ios/net/cookies/cookie_store_ios_unittest.mm b/ios/net/cookies/cookie_store_ios_unittest.mm
index 45cfe60..bd9cfc4 100644
--- a/ios/net/cookies/cookie_store_ios_unittest.mm
+++ b/ios/net/cookies/cookie_store_ios_unittest.mm
@@ -109,9 +109,6 @@
   net::CookieList cookie_list_;
 };
 
-void IgnoreBoolean(bool ignored) {
-}
-
 void IgnoreList(const net::CookieList& ignored,
                 const net::CookieStatusList& excluded_cookies) {}
 
@@ -295,12 +292,25 @@
   GetCookies(base::BindOnce(&IgnoreList));
   ClearCookies();
   SetCookie("abc=def");
-  EXPECT_EQ(1U, cookies_changed_.size());
-  EXPECT_EQ(1U, cookies_removed_.size());
-  store_->DeleteCookieAsync(kTestCookieURLFooBar, "abc",
-                            base::Bind(&IgnoreBoolean, false));
+  ASSERT_EQ(1U, cookies_changed_.size());
+  ASSERT_EQ(1U, cookies_removed_.size());
+  EXPECT_EQ("abc", cookies_changed_[0].Name());
+  EXPECT_EQ("def", cookies_changed_[0].Value());
+  EXPECT_FALSE(cookies_removed_[0]);
+
+  base::RunLoop run_loop;
+  store_->DeleteAllAsync(base::BindLambdaForTesting([&](uint32_t num_deleted) {
+    EXPECT_EQ(1U, num_deleted);
+    run_loop.Quit();
+  }));
+  run_loop.Run();
   CookieStoreIOS::NotifySystemCookiesChanged();
   base::RunLoop().RunUntilIdle();
+  ASSERT_EQ(2U, cookies_changed_.size());
+  ASSERT_EQ(2U, cookies_removed_.size());
+  EXPECT_EQ("abc", cookies_changed_[1].Name());
+  EXPECT_EQ("def", cookies_changed_[1].Value());
+  EXPECT_TRUE(cookies_removed_[1]);
 }
 
 TEST_F(CookieStoreIOSTest, SameValueDoesNotCallHook) {
diff --git a/net/cookies/cookie_monster.cc b/net/cookies/cookie_monster.cc
index cbec3f9..5adbe4a 100644
--- a/net/cookies/cookie_monster.cc
+++ b/net/cookies/cookie_monster.cc
@@ -110,11 +110,6 @@
     std::move(callback).Run();
 }
 
-void MaybeRunCookieCallback(base::OnceClosure callback) {
-  if (callback)
-    std::move(callback).Run();
-}
-
 template <typename T>
 void MaybeRunCookieCallback(base::OnceCallback<void(const T&)> callback,
                             const T& result) {
@@ -496,19 +491,6 @@
       std::move(callback)));
 }
 
-void CookieMonster::DeleteCookieAsync(const GURL& url,
-                                      const std::string& cookie_name,
-                                      base::OnceClosure callback) {
-  DoCookieCallbackForURL(
-      base::BindOnce(
-          // base::Unretained is safe as DoCookieCallbackForURL stores
-          // the callback on |*this|, so the callback will not outlive
-          // the object.
-          &CookieMonster::DeleteCookie, base::Unretained(this), url,
-          cookie_name, std::move(callback)),
-      url);
-}
-
 void CookieMonster::DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
                                                DeleteCallback callback) {
   DoCookieCallback(base::BindOnce(
@@ -761,53 +743,6 @@
                      !options.exclude_httponly(), std::move(callback));
 }
 
-void CookieMonster::DeleteCookie(const GURL& url,
-                                 const std::string& cookie_name,
-                                 base::OnceClosure callback) {
-  DCHECK(thread_checker_.CalledOnValidThread());
-
-  if (!HasCookieableScheme(url)) {
-    // TODO(rdsmith): Would be good to provide a failure indication here.
-    MaybeRunCookieCallback(std::move(callback));
-    return;
-  }
-
-  CookieOptions options;
-  options.set_include_httponly();
-  options.set_same_site_cookie_mode(
-      CookieOptions::SameSiteCookieMode::INCLUDE_STRICT_AND_LAX);
-  // Get the cookies for this host and its domain(s).
-  std::vector<CanonicalCookie*> cookie_ptrs;
-  std::vector<CanonicalCookie*> included_cookie_ptrs;
-  FindCookiesForRegistryControlledHost(url, &cookie_ptrs);
-  FilterCookiesWithOptions(url, options, &cookie_ptrs, &included_cookie_ptrs,
-                           nullptr);
-  std::set<CanonicalCookie*> matching_cookies;
-
-  for (auto* cookie : included_cookie_ptrs) {
-    DCHECK(cookie->IsOnPath(url.path()));
-    DCHECK(cookie->IsDomainMatch(url.host()));
-    if (cookie->Name() != cookie_name)
-      continue;
-    matching_cookies.insert(cookie);
-  }
-
-  for (auto it = cookies_.begin(); it != cookies_.end();) {
-    auto curit = it;
-    ++it;
-    if (matching_cookies.find(curit->second.get()) != matching_cookies.end()) {
-      InternalDeleteCookie(curit, true, DELETE_COOKIE_EXPLICIT);
-    }
-  }
-
-  FlushStore(base::BindOnce(&MaybeRunDeleteCallback,
-                            weak_ptr_factory_.GetWeakPtr(),
-                            // No callback null check needed as BindOnce
-                            // is not being called and MaybeRunDeleteCallback
-                            // has its own check.
-                            std::move(callback)));
-}
-
 void CookieMonster::DeleteCanonicalCookie(const CanonicalCookie& cookie,
                                           DeleteCallback callback) {
   DCHECK(thread_checker_.CalledOnValidThread());
diff --git a/net/cookies/cookie_monster.h b/net/cookies/cookie_monster.h
index 071d7ff..151511f 100644
--- a/net/cookies/cookie_monster.h
+++ b/net/cookies/cookie_monster.h
@@ -168,9 +168,6 @@
                                      const CookieOptions& options,
                                      GetCookieListCallback callback) override;
   void GetAllCookiesAsync(GetCookieListCallback callback) override;
-  void DeleteCookieAsync(const GURL& url,
-                         const std::string& cookie_name,
-                         base::OnceClosure callback) override;
   void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
                                   DeleteCallback callback) override;
   void DeleteAllCreatedInTimeRangeAsync(
@@ -389,10 +386,6 @@
                             const CookieOptions& options,
                             SetCookiesCallback callback);
 
-  void DeleteCookie(const GURL& url,
-                    const std::string& cookie_name,
-                    base::OnceClosure callback);
-
   void DeleteCanonicalCookie(const CanonicalCookie& cookie,
                              DeleteCallback callback);
 
diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc
index 956d65b..e149d79 100644
--- a/net/cookies/cookie_monster_unittest.cc
+++ b/net/cookies/cookie_monster_unittest.cc
@@ -900,9 +900,6 @@
 
 // TODO(erikwright): When the synchronous helpers 'GetCookies' etc. are removed,
 // rename these, removing the 'Action' suffix.
-ACTION_P4(DeleteCookieAction, cookie_monster, url, name, callback) {
-  cookie_monster->DeleteCookieAsync(url, name, callback->Get());
-}
 ACTION_P4(SetCookieAction, cookie_monster, url, cookie_line, callback) {
   cookie_monster->SetCookieWithOptionsAsync(url, cookie_line, CookieOptions(),
                                             callback->Get());
@@ -1136,26 +1133,6 @@
   loop.Run();
 }
 
-TEST_F(DeferredCookieTaskTest, DeferredDeleteCookie) {
-  MockClosure delete_cookie_callback;
-
-  BeginWithForDomainKey(
-      http_www_foo_.domain(),
-      DeleteCookieAction(&cookie_monster(), http_www_foo_.url(), "A",
-                         &delete_cookie_callback));
-
-  WaitForLoadCall();
-
-  EXPECT_CALL(delete_cookie_callback, Run())
-      .WillOnce(DeleteCookieAction(&cookie_monster(), http_www_foo_.url(), "X",
-                                   &delete_cookie_callback));
-  base::RunLoop loop;
-  EXPECT_CALL(delete_cookie_callback, Run()).WillOnce(QuitRunLoop(&loop));
-
-  CompleteLoading();
-  loop.Run();
-}
-
 TEST_F(DeferredCookieTaskTest, DeferredGetAllCookies) {
   DeclareLoadedCookie(http_www_foo_.url(),
                       "X=1; path=/; expires=Mon, 18-Apr-22 22:50:14 GMT",
@@ -1870,30 +1847,6 @@
   EXPECT_EQ(1u, cookies.size());
 }
 
-TEST_F(CookieMonsterTest, DeleteCookieByName) {
-  std::unique_ptr<CookieMonster> cm(
-      new CookieMonster(nullptr, nullptr, &net_log_));
-
-  EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A1; path=/"));
-  EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A2; path=/foo"));
-  EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "A=A3; path=/bar"));
-  EXPECT_TRUE(SetCookie(cm.get(), http_bar_foo_.url(), "A=A4; path=/foo"));
-  EXPECT_TRUE(SetCookie(cm.get(), http_www_bar_.url(), "A=A5; path=/foo"));
-  EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B1; path=/"));
-  EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B2; path=/foo"));
-  EXPECT_TRUE(SetCookie(cm.get(), http_www_foo_.url(), "B=B3; path=/bar"));
-
-  DeleteCookie(cm.get(), http_www_foo_.AppendPath("foo/bar"), "A");
-
-  CookieList cookies = GetAllCookies(cm.get());
-  size_t expected_size = 6;
-  EXPECT_EQ(expected_size, cookies.size());
-  for (auto it = cookies.begin(); it != cookies.end(); ++it) {
-    EXPECT_NE("A1", it->Value());
-    EXPECT_NE("A2", it->Value());
-  }
-}
-
 // Tests importing from a persistent cookie store that contains duplicate
 // equivalent cookies. This situation should be handled by removing the
 // duplicate cookie (both from the in-memory cache, and from the backing store).
@@ -2100,10 +2053,10 @@
               cookie.http_only, cookie.same_site, cookie.priority),
           cookie.url.SchemeIsCryptographic(), true /*modify_httponly*/));
     }
-    GURL del_url(input_info[INPUT_DELETE]
-                     .url.Resolve(input_info[INPUT_DELETE].path)
-                     .spec());
-    DeleteCookie(cmout.get(), del_url, input_info[INPUT_DELETE].name);
+
+    EXPECT_TRUE(FindAndDeleteCookie(cmout.get(),
+                                    input_info[INPUT_DELETE].domain,
+                                    input_info[INPUT_DELETE].name));
   }
 
   // Create a new cookie monster and make sure that everything is correct
@@ -2731,10 +2684,11 @@
   EXPECT_EQ("A", store->commands()[2].cookie.Name());
   EXPECT_EQ("C", store->commands()[2].cookie.Value());
 
-  // Delete the cookie.
-  DeleteCookie(cm.get(), http_www_foo_.url(), "A");
+  // Delete the cookie. Using .host() here since it's a host and not domain
+  // cookie.
+  EXPECT_TRUE(FindAndDeleteCookie(cm.get(), http_www_foo_.host(), "A"));
   EXPECT_EQ("", GetCookies(cm.get(), http_www_foo_.url()));
-  EXPECT_EQ(4u, store->commands().size());
+  ASSERT_EQ(4u, store->commands().size());
   EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type);
   EXPECT_EQ("A", store->commands()[3].cookie.Name());
   EXPECT_EQ("C", store->commands()[3].cookie.Value());
diff --git a/net/cookies/cookie_store.h b/net/cookies/cookie_store.h
index 7815dd1..b4b4ce4 100644
--- a/net/cookies/cookie_store.h
+++ b/net/cookies/cookie_store.h
@@ -96,11 +96,6 @@
   // longest path, then by earliest creation date.
   virtual void GetAllCookiesAsync(GetCookieListCallback callback) = 0;
 
-  // Deletes all cookies that might apply to |url| that have |cookie_name|.
-  virtual void DeleteCookieAsync(const GURL& url,
-                                 const std::string& cookie_name,
-                                 base::OnceClosure callback) = 0;
-
   // Deletes one specific cookie. |cookie| must have been returned by a previous
   // query on this CookieStore. Invokes |callback| with 1 if a cookie was
   // deleted, 0 otherwise.
diff --git a/net/cookies/cookie_store_test_helpers.cc b/net/cookies/cookie_store_test_helpers.cc
index bc1593c..7261c7c 100644
--- a/net/cookies/cookie_store_test_helpers.cc
+++ b/net/cookies/cookie_store_test_helpers.cc
@@ -162,17 +162,6 @@
   return false;
 }
 
-void DelayedCookieMonster::DeleteCookie(const GURL& url,
-                                        const std::string& cookie_name) {
-  ADD_FAILURE();
-}
-
-void DelayedCookieMonster::DeleteCookieAsync(const GURL& url,
-                                             const std::string& cookie_name,
-                                             base::OnceClosure callback) {
-  ADD_FAILURE();
-}
-
 void DelayedCookieMonster::DeleteCanonicalCookieAsync(
     const CanonicalCookie& cookie,
     DeleteCallback callback) {
diff --git a/net/cookies/cookie_store_test_helpers.h b/net/cookies/cookie_store_test_helpers.h
index 2456814..293425e 100644
--- a/net/cookies/cookie_store_test_helpers.h
+++ b/net/cookies/cookie_store_test_helpers.h
@@ -72,13 +72,6 @@
                                     const std::string& cookie_line,
                                     const CookieOptions& options);
 
-  virtual void DeleteCookie(const GURL& url,
-                            const std::string& cookie_name);
-
-  void DeleteCookieAsync(const GURL& url,
-                         const std::string& cookie_name,
-                         base::OnceClosure callback) override;
-
   void DeleteCanonicalCookieAsync(const CanonicalCookie& cookie,
                                   DeleteCallback callback) override;
 
diff --git a/net/cookies/cookie_store_unittest.h b/net/cookies/cookie_store_unittest.h
index 5c5fb91..e067abf 100644
--- a/net/cookies/cookie_store_unittest.h
+++ b/net/cookies/cookie_store_unittest.h
@@ -243,17 +243,6 @@
     return SetCookieWithOptions(cs, url, cookie_line, options);
   }
 
-  void DeleteCookie(CookieStore* cs,
-                    const GURL& url,
-                    const std::string& cookie_name) {
-    DCHECK(cs);
-    NoResultCookieCallback callback;
-    cs->DeleteCookieAsync(
-        url, cookie_name,
-        base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback)));
-    callback.WaitUntilDone();
-  }
-
   uint32_t DeleteCanonicalCookie(CookieStore* cs,
                                  const CanonicalCookie& cookie) {
     DCHECK(cs);
@@ -1602,31 +1591,6 @@
   ASSERT_TRUE(++it == cookies.end());
 }
 
-TYPED_TEST_P(CookieStoreTest, DeleteCookieAsync) {
-  CookieStore* cs = this->GetCookieStore();
-
-  EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "A=A1; path=/"));
-  EXPECT_TRUE(
-      this->SetCookie(cs, this->http_www_foo_.url(), "A=A2; path=/foo"));
-  EXPECT_TRUE(
-      this->SetCookie(cs, this->http_www_foo_.url(), "A=A3; path=/bar"));
-  EXPECT_TRUE(this->SetCookie(cs, this->http_www_foo_.url(), "B=B1; path=/"));
-  EXPECT_TRUE(
-      this->SetCookie(cs, this->http_www_foo_.url(), "B=B2; path=/foo"));
-  EXPECT_TRUE(
-      this->SetCookie(cs, this->http_www_foo_.url(), "B=B3; path=/bar"));
-
-  this->DeleteCookie(cs, this->http_www_foo_.AppendPath("foo/bar"), "A");
-
-  CookieList cookies = this->GetAllCookies(cs);
-  size_t expected_size = 4;
-  EXPECT_EQ(expected_size, cookies.size());
-  for (const auto& cookie : cookies) {
-    EXPECT_NE("A1", cookie.Value());
-    EXPECT_NE("A2", cookie.Value());
-  }
-}
-
 TYPED_TEST_P(CookieStoreTest, DeleteCanonicalCookieAsync) {
   CookieStore* cs = this->GetCookieStore();
 
@@ -1722,7 +1686,6 @@
                            EmptyName,
                            CookieOrdering,
                            GetAllCookiesAsync,
-                           DeleteCookieAsync,
                            DeleteCanonicalCookieAsync,
                            DeleteSessionCookie);