summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 18:29:43 +0000
committerycxiao@chromium.org <ycxiao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 18:29:43 +0000
commit9097419704c0c9366cb6e06fbd721b90ec8c50e6 (patch)
tree4d03aa9471ccd5e05bacd3eb0d62aed546b1f89c /chrome
parentf0fc1060ef17d1df6cca0b27391763d645857ef5 (diff)
downloadchromium_src-9097419704c0c9366cb6e06fbd721b90ec8c50e6.zip
chromium_src-9097419704c0c9366cb6e06fbd721b90ec8c50e6.tar.gz
chromium_src-9097419704c0c9366cb6e06fbd721b90ec8c50e6.tar.bz2
Update the ImporterHost to the new asynchronous CookieMonster API.
Review URL: http://codereview.chromium.org/7290013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92570 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/importer/importer_host.cc44
-rw-r--r--chrome/browser/importer/importer_host.h3
-rw-r--r--chrome/browser/importer/toolbar_importer_utils.cc31
-rw-r--r--chrome/browser/importer/toolbar_importer_utils.h8
4 files changed, 58 insertions, 28 deletions
diff --git a/chrome/browser/importer/importer_host.cc b/chrome/browser/importer/importer_host.cc
index 516c55f..0ea0147 100644
--- a/chrome/browser/importer/importer_host.cc
+++ b/chrome/browser/importer/importer_host.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/importer/importer_host.h"
+#include "base/bind.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_process.h"
@@ -132,23 +133,9 @@ void ImporterHost::StartImportSettings(
// For google toolbar import, we need the user to log in and store their GAIA
// credentials.
if (source_profile.importer_type == importer::GOOGLE_TOOLBAR5) {
- if (!toolbar_importer_utils::IsGoogleGAIACookieInstalled()) {
- ui::MessageBox(
- NULL,
- UTF16ToWide(l10n_util::GetStringUTF16(
- IDS_IMPORTER_GOOGLE_LOGIN_TEXT)).c_str(),
- L"",
- MB_OK | MB_TOPMOST);
-
- GURL url("https://www.google.com/accounts/ServiceLogin");
- BrowserList::GetLastActiveWithProfile(profile_)->AddSelectedTabWithURL(
- url, PageTransition::TYPED);
-
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ImporterHost::OnImportLockDialogEnd, false));
-
- is_source_readable_ = false;
- }
+ toolbar_importer_utils::IsGoogleGAIACookieInstalled(
+ base::Bind(&ImporterHost::OnGoogleGAIACookieChecked, this), profile_);
+ is_source_readable_ = false;
}
#endif
@@ -157,6 +144,29 @@ void ImporterHost::StartImportSettings(
InvokeTaskIfDone();
}
+void ImporterHost::OnGoogleGAIACookieChecked(bool result) {
+#if defined(OS_WIN)
+ if (!result) {
+ ui::MessageBox(
+ NULL,
+ UTF16ToWide(l10n_util::GetStringUTF16(
+ IDS_IMPORTER_GOOGLE_LOGIN_TEXT)).c_str(),
+ L"",
+ MB_OK | MB_TOPMOST);
+
+ GURL url("https://www.google.com/accounts/ServiceLogin");
+ BrowserList::GetLastActive()->AddSelectedTabWithURL(
+ url, PageTransition::TYPED);
+
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &ImporterHost::OnImportLockDialogEnd, false));
+ } else {
+ is_source_readable_ = true;
+ InvokeTaskIfDone();
+ }
+#endif
+}
+
void ImporterHost::Cancel() {
if (importer_)
importer_->Cancel();
diff --git a/chrome/browser/importer/importer_host.h b/chrome/browser/importer/importer_host.h
index a49d1af..6f3984c 100644
--- a/chrome/browser/importer/importer_host.h
+++ b/chrome/browser/importer/importer_host.h
@@ -134,6 +134,9 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>,
// complete.
virtual void InvokeTaskIfDone();
+ // Called when IsGoogleGAIACookieInstalled is done.
+ void OnGoogleGAIACookieChecked(bool result);
+
// BaseBookmarkModelObserver:
virtual void Loaded(BookmarkModel* model, bool ids_reassigned) OVERRIDE;
virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
diff --git a/chrome/browser/importer/toolbar_importer_utils.cc b/chrome/browser/importer/toolbar_importer_utils.cc
index c751e0a..c04073b 100644
--- a/chrome/browser/importer/toolbar_importer_utils.cc
+++ b/chrome/browser/importer/toolbar_importer_utils.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/profiles/profile.h"
#include "googleurl/src/gurl.h"
#include "net/base/cookie_store.h"
+#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
namespace {
@@ -21,23 +22,33 @@ const char kSplitStringToken = ';';
namespace toolbar_importer_utils {
-bool IsGoogleGAIACookieInstalled() {
- net::CookieStore* store =
- Profile::GetDefaultRequestContext()->DONTUSEME_GetCookieStore();
- GURL url(kGoogleDomainUrl);
- net::CookieOptions options;
- options.set_include_httponly(); // The SID cookie might be httponly.
- std::string cookies = store->GetCookiesWithOptions(url, options);
+void OnGetCookies(const base::Callback<void(bool)>& callback,
+ const std::string& cookies) {
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 (0 == position)
- return true;
+ if (position == 0)
+ callback.Run(true);
+ return;
+ }
+ callback.Run(false);
+}
+
+void IsGoogleGAIACookieInstalled(const base::Callback<void(bool)>& callback,
+ Profile* profile) {
+ 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));
}
- return false;
}
} // namespace toolbar_importer_utils
diff --git a/chrome/browser/importer/toolbar_importer_utils.h b/chrome/browser/importer/toolbar_importer_utils.h
index f5b5177..ed04715 100644
--- a/chrome/browser/importer/toolbar_importer_utils.h
+++ b/chrome/browser/importer/toolbar_importer_utils.h
@@ -6,12 +6,18 @@
#define CHROME_BROWSER_IMPORTER_TOOLBAR_IMPORTER_UTILS_H_
#pragma once
+#include "base/bind.h"
+#include "base/callback.h"
+
+class Profile;
+
namespace toolbar_importer_utils {
// Currently the only configuration information we need is to check whether or
// not the user currently has their GAIA cookie. This is done by the function
// exposed through the ToolbarImportUtils namespace.
-bool IsGoogleGAIACookieInstalled();
+void IsGoogleGAIACookieInstalled(const base::Callback<void(bool)>& callback,
+ Profile* profile);
} // namespace toolbar_importer_utils