Chromium Code Reviews| 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 8a22cbb018025519dd1c09c13deed4ef0016d374..589e514ad0c149c23bb2965c4853b3649a9be875 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,53 @@ 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()) { |
| + std::string code; |
|
Mihai Parparita -not on Chrome
2011/10/27 22:21:05
You don't seem to be using these variables.
asargent_no_longer_on_chrome
2011/10/28 17:09:22
Oops, good catch - I had moved them to be inline i
|
| + std::string error("not_available"); |
| 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 +117,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) { |