summaryrefslogtreecommitdiffstats
path: root/chrome/browser/importer
diff options
context:
space:
mode:
authorycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 17:54:49 +0000
committerycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-21 17:54:49 +0000
commit8c5296a3dfd62201e6a47060ab322ed355a81c61 (patch)
treed199af97cffdf31d7cfd5307bea5ecdb6e512ed3 /chrome/browser/importer
parent9bd3b58cb019f5bb89d66f5a031e0b81b5b19035 (diff)
downloadchromium_src-8c5296a3dfd62201e6a47060ab322ed355a81c61.zip
chromium_src-8c5296a3dfd62201e6a47060ab322ed355a81c61.tar.gz
chromium_src-8c5296a3dfd62201e6a47060ab322ed355a81c61.tar.bz2
Fix a crash caused by a previous CL of toolbar importer utils and add an unit test.
BUG=89752 TEST=XXX Review URL: http://codereview.chromium.org/7471017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93435 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r--chrome/browser/importer/toolbar_importer_utils.cc43
-rw-r--r--chrome/browser/importer/toolbar_importer_utils_browsertest.cc41
2 files changed, 74 insertions, 10 deletions
diff --git a/chrome/browser/importer/toolbar_importer_utils.cc b/chrome/browser/importer/toolbar_importer_utils.cc
index c04073b..45b390b 100644
--- a/chrome/browser/importer/toolbar_importer_utils.cc
+++ b/chrome/browser/importer/toolbar_importer_utils.cc
@@ -7,8 +7,10 @@
#include <string>
#include <vector>
+#include "base/bind.h"
#include "base/string_split.h"
#include "chrome/browser/profiles/profile.h"
+#include "content/browser/browser_thread.h"
#include "googleurl/src/gurl.h"
#include "net/base/cookie_store.h"
#include "net/url_request/url_request_context.h"
@@ -24,30 +26,51 @@ namespace toolbar_importer_utils {
void OnGetCookies(const base::Callback<void(bool)>& callback,
const std::string& cookies) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
std::vector<std::string> cookie_list;
base::SplitString(cookies, kSplitStringToken, &cookie_list);
for (std::vector<std::string>::iterator current = cookie_list.begin();
current != cookie_list.end();
++current) {
size_t position = (*current).find(kGoogleDomainSecureCookieId);
- if (position == 0)
+ if (position == 0) {
callback.Run(true);
- return;
+ return;
+ }
}
callback.Run(false);
}
+void OnFetchComplete(const base::Callback<void(bool)>& callback,
+ const std::string& cookies) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&OnGetCookies, callback, cookies));
+}
+
+void FetchCookiesOnIOThread(
+ const base::Callback<void(bool)>& callback,
+ net::URLRequestContextGetter* context_getter) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ net::CookieStore* store = context_getter->
+ GetURLRequestContext()->cookie_store();
+ GURL url(kGoogleDomainUrl);
+ net::CookieOptions options;
+ options.set_include_httponly(); // The SID cookie might be httponly.
+ store->GetCookiesWithOptionsAsync(
+ url, options,
+ base::Bind(&toolbar_importer_utils::OnFetchComplete, callback));
+}
+
void IsGoogleGAIACookieInstalled(const base::Callback<void(bool)>& callback,
Profile* profile) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (!callback.is_null()) {
- net::CookieStore* store =
- profile->GetRequestContext()->GetURLRequestContext()->cookie_store();
- GURL url(kGoogleDomainUrl);
- net::CookieOptions options;
- options.set_include_httponly(); // The SID cookie might be httponly.
- store->GetCookiesWithOptionsAsync(
- url, options,
- base::Bind(&toolbar_importer_utils::OnGetCookies, callback));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&FetchCookiesOnIOThread,
+ callback, base::Unretained(profile->GetRequestContext())));
}
}
diff --git a/chrome/browser/importer/toolbar_importer_utils_browsertest.cc b/chrome/browser/importer/toolbar_importer_utils_browsertest.cc
new file mode 100644
index 0000000..5179d64
--- /dev/null
+++ b/chrome/browser/importer/toolbar_importer_utils_browsertest.cc
@@ -0,0 +1,41 @@
+// Copyright (c) 2011 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.
+
+#include "base/bind.h"
+#include "base/message_loop.h"
+#include "chrome/browser/importer/toolbar_importer_utils.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+
+namespace {
+
+class ToolbarImporterUtilsTest : public InProcessBrowserTest {
+ public:
+ ToolbarImporterUtilsTest() : did_run_(false) {
+ }
+
+ void Callback(bool result) {
+ DCHECK(!result);
+ did_run_ = true;
+ MessageLoop::current()->Quit();
+ }
+
+ protected:
+ bool did_run_;
+};
+
+IN_PROC_BROWSER_TEST_F(ToolbarImporterUtilsTest, NoCrash) {
+ // Regression test for http://crbug.com/89752
+ toolbar_importer_utils::IsGoogleGAIACookieInstalled(
+ base::Bind(&ToolbarImporterUtilsTest::Callback,
+ base::Unretained(this)),
+ browser()->profile());
+ if (!did_run_) {
+ ui_test_utils::RunMessageLoop();
+ }
+ ASSERT_TRUE(did_run_);
+}
+
+} // namespace