Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1347)

Unified Diff: chrome/browser/extensions/app_notify_channel_setup.cc

Issue 8400027: Add code to prompt for browser login during app notification setup (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add virtual destructor to interface class Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/app_notify_channel_setup.cc
diff --git a/chrome/browser/extensions/app_notify_channel_setup.cc b/chrome/browser/extensions/app_notify_channel_setup.cc
index f548ce95d136604cc98c06464d6932d4b39f5c34..e990e1a19970d464660b41a72e9ce200b9565914 100644
--- a/chrome/browser/extensions/app_notify_channel_setup.cc
+++ b/chrome/browser/extensions/app_notify_channel_setup.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/extensions/app_notify_channel_setup.h"
+#include "base/bind.h"
#include "base/command_line.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
@@ -20,13 +21,15 @@ AppNotifyChannelSetup::AppNotifyChannelSetup(
const GURL& requestor_url,
int return_route_id,
int callback_id,
+ AppNotifyChannelUI* ui,
base::WeakPtr<AppNotifyChannelSetup::Delegate> delegate)
: profile_(profile),
client_id_(client_id),
requestor_url_(requestor_url),
return_route_id_(return_route_id),
callback_id_(callback_id),
- delegate_(delegate) {}
+ delegate_(delegate),
+ ui_(ui) {}
AppNotifyChannelSetup::~AppNotifyChannelSetup() {}
@@ -52,24 +55,51 @@ static GURL GetChannelServerURL() {
void AppNotifyChannelSetup::Start() {
AddRef(); // Balanced in ReportResult.
- GURL channel_server_url = GetChannelServerURL();
-
// Check if the user is logged in to the browser.
std::string username = profile_->GetPrefs()->GetString(
prefs::kGoogleServicesUsername);
- // TODO(asargent) - If the user is not logged in, we'd like to prompt for
- // login and if then they sign in, continue as normal. But for now just return
- // an error. We do this via PostTask instead of immediately calling back the
+ if (username.empty()) {
+ ui_->PromptSyncSetup(this);
+ return; // We'll get called back in OnSyncSetupResult
+ }
+
+ BeginFetch();
+}
+
+void AppNotifyChannelSetup::OnURLFetchComplete(
+ const content::URLFetcher* source) {
+ CHECK(source);
+ net::URLRequestStatus status = source->GetStatus();
+
+ if (status.status() == net::URLRequestStatus::SUCCESS &&
+ source->GetResponseCode() == 200) {
+ // TODO(asargent) - we need to parse the response from |source| here.
+ ReportResult("dummy_do_not_use", "");
+ } else {
+ ReportResult("", "channel_service_error");
+ }
+}
+
+void AppNotifyChannelSetup::OnSyncSetupResult(bool enabled) {
+ if (enabled) {
+ BeginFetch();
+ } else {
+ ReportResult("", "not_available");
+ }
+}
+
+void AppNotifyChannelSetup::BeginFetch() {
+ GURL channel_server_url = GetChannelServerURL();
+
+ // We return the error via PostTask instead of immediately calling back the
// delegate because it simplifies tests.
- if (!channel_server_url.is_valid() || username.empty()) {
+ if (!channel_server_url.is_valid()) {
BrowserThread::PostTask(
BrowserThread::UI,
FROM_HERE,
- NewRunnableMethod(this,
- &AppNotifyChannelSetup::ReportResult,
- std::string(),
- std::string("not_available")));
+ base::Bind(&AppNotifyChannelSetup::ReportResult, this,
+ std::string(), std::string("not_available")));
return;
}
@@ -85,20 +115,6 @@ void AppNotifyChannelSetup::Start() {
url_fetcher_->Start();
}
-void AppNotifyChannelSetup::OnURLFetchComplete(
- const content::URLFetcher* source) {
- CHECK(source);
- net::URLRequestStatus status = source->GetStatus();
-
- if (status.status() == net::URLRequestStatus::SUCCESS &&
- source->GetResponseCode() == 200) {
- // TODO(asargent) - we need to parse the response from |source| here.
- ReportResult("dummy_do_not_use", "");
- } else {
- ReportResult("", "channel_service_error");
- }
-}
-
void AppNotifyChannelSetup::ReportResult(
const std::string& channel_id,
const std::string& error) {
« no previous file with comments | « chrome/browser/extensions/app_notify_channel_setup.h ('k') | chrome/browser/extensions/app_notify_channel_setup_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698