Added GCDApiFlowInterface for simpler testing.

Added empty PrivetV3HTTPClient and implementation.
Reordered LocalDiscoveryUIHandler member to match dependency.

BUG=372843
TBR=noamsml

Review URL: https://codereview.chromium.org/318283002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275742 0039d316-1c4b-4281-b951-d872f2087c98
parent 12eb772f
...@@ -23,7 +23,7 @@ CloudDeviceList::CloudDeviceList(CloudDeviceListDelegate* delegate) ...@@ -23,7 +23,7 @@ CloudDeviceList::CloudDeviceList(CloudDeviceListDelegate* delegate)
CloudDeviceList::~CloudDeviceList() { CloudDeviceList::~CloudDeviceList() {
} }
void CloudDeviceList::OnGCDAPIFlowError(GCDApiFlow::Status status) { void CloudDeviceList::OnGCDAPIFlowError(GCDApiFlowInterface::Status status) {
delegate_->OnDeviceListUnavailable(); delegate_->OnDeviceListUnavailable();
} }
......
...@@ -21,7 +21,7 @@ class CloudDeviceList : public GCDApiFlowRequest { ...@@ -21,7 +21,7 @@ class CloudDeviceList : public GCDApiFlowRequest {
explicit CloudDeviceList(CloudDeviceListDelegate* delegate); explicit CloudDeviceList(CloudDeviceListDelegate* delegate);
virtual ~CloudDeviceList(); virtual ~CloudDeviceList();
virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE; virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete( virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE; const base::DictionaryValue& value) OVERRIDE;
......
...@@ -19,7 +19,8 @@ CloudPrintPrinterList::CloudPrintPrinterList(CloudDeviceListDelegate* delegate) ...@@ -19,7 +19,8 @@ CloudPrintPrinterList::CloudPrintPrinterList(CloudDeviceListDelegate* delegate)
CloudPrintPrinterList::~CloudPrintPrinterList() { CloudPrintPrinterList::~CloudPrintPrinterList() {
} }
void CloudPrintPrinterList::OnGCDAPIFlowError(GCDApiFlow::Status status) { void CloudPrintPrinterList::OnGCDAPIFlowError(
GCDApiFlowInterface::Status status) {
delegate_->OnDeviceListUnavailable(); delegate_->OnDeviceListUnavailable();
} }
......
...@@ -18,7 +18,7 @@ class CloudPrintPrinterList : public CloudPrintApiFlowRequest { ...@@ -18,7 +18,7 @@ class CloudPrintPrinterList : public CloudPrintApiFlowRequest {
explicit CloudPrintPrinterList(CloudDeviceListDelegate* delegate); explicit CloudPrintPrinterList(CloudDeviceListDelegate* delegate);
virtual ~CloudPrintPrinterList(); virtual ~CloudPrintPrinterList();
virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE; virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete( virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE; const base::DictionaryValue& value) OVERRIDE;
......
...@@ -23,37 +23,42 @@ namespace { ...@@ -23,37 +23,42 @@ namespace {
const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s"; const char kCloudPrintOAuthHeaderFormat[] = "Authorization: Bearer %s";
} }
GCDApiFlow::Request::Request() { GCDApiFlowInterface::Request::Request() {
} }
GCDApiFlow::Request::~Request() { GCDApiFlowInterface::Request::~Request() {
} }
net::URLFetcher::RequestType GCDApiFlow::Request::GetRequestType() { net::URLFetcher::RequestType GCDApiFlowInterface::Request::GetRequestType() {
return net::URLFetcher::GET; return net::URLFetcher::GET;
} }
void GCDApiFlow::Request::GetUploadData(std::string* upload_type, void GCDApiFlowInterface::Request::GetUploadData(std::string* upload_type,
std::string* upload_data) { std::string* upload_data) {
*upload_type = std::string(); *upload_type = std::string();
*upload_data = std::string(); *upload_data = std::string();
} }
GCDApiFlowInterface::GCDApiFlowInterface() {
}
GCDApiFlowInterface::~GCDApiFlowInterface() {
}
GCDApiFlow::GCDApiFlow(net::URLRequestContextGetter* request_context, GCDApiFlow::GCDApiFlow(net::URLRequestContextGetter* request_context,
OAuth2TokenService* token_service, OAuth2TokenService* token_service,
const std::string& account_id, const std::string& account_id)
scoped_ptr<Request> delegate)
: OAuth2TokenService::Consumer("cloud_print"), : OAuth2TokenService::Consumer("cloud_print"),
request_context_(request_context), request_context_(request_context),
token_service_(token_service), token_service_(token_service),
account_id_(account_id), account_id_(account_id) {
request_(delegate.Pass()) {
} }
GCDApiFlow::~GCDApiFlow() { GCDApiFlow::~GCDApiFlow() {
} }
void GCDApiFlow::Start() { void GCDApiFlow::Start(scoped_ptr<Request> request) {
request_ = request.Pass();
OAuth2TokenService::ScopeSet oauth_scopes; OAuth2TokenService::ScopeSet oauth_scopes;
oauth_scopes.insert(request_->GetOAuthScope()); oauth_scopes.insert(request_->GetOAuthScope());
oauth_request_ = oauth_request_ =
......
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
namespace local_discovery { namespace local_discovery {
// API flow for communicating with cloud print and cloud devices. // API flow for communicating with cloud print and cloud devices.
class GCDApiFlow : public net::URLFetcherDelegate, class GCDApiFlowInterface {
public OAuth2TokenService::Consumer {
public: public:
// TODO(noamsml): Better error model for this class. // TODO(noamsml): Better error model for this class.
enum Status { enum Status {
...@@ -57,15 +56,27 @@ class GCDApiFlow : public net::URLFetcherDelegate, ...@@ -57,15 +56,27 @@ class GCDApiFlow : public net::URLFetcherDelegate,
DISALLOW_COPY_AND_ASSIGN(Request); DISALLOW_COPY_AND_ASSIGN(Request);
}; };
GCDApiFlowInterface();
virtual ~GCDApiFlowInterface();
virtual void Start(scoped_ptr<Request> request) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(GCDApiFlowInterface);
};
class GCDApiFlow : public GCDApiFlowInterface,
public net::URLFetcherDelegate,
public OAuth2TokenService::Consumer {
public:
// Create an OAuth2-based confirmation. // Create an OAuth2-based confirmation.
GCDApiFlow(net::URLRequestContextGetter* request_context, GCDApiFlow(net::URLRequestContextGetter* request_context,
OAuth2TokenService* token_service, OAuth2TokenService* token_service,
const std::string& account_id, const std::string& account_id);
scoped_ptr<Request> request);
virtual ~GCDApiFlow(); virtual ~GCDApiFlow();
void Start(); virtual void Start(scoped_ptr<Request> request) OVERRIDE;
// net::URLFetcherDelegate implementation: // net::URLFetcherDelegate implementation:
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
...@@ -86,10 +97,11 @@ class GCDApiFlow : public net::URLFetcherDelegate, ...@@ -86,10 +97,11 @@ class GCDApiFlow : public net::URLFetcherDelegate,
OAuth2TokenService* token_service_; OAuth2TokenService* token_service_;
std::string account_id_; std::string account_id_;
scoped_ptr<Request> request_; scoped_ptr<Request> request_;
DISALLOW_COPY_AND_ASSIGN(GCDApiFlow); DISALLOW_COPY_AND_ASSIGN(GCDApiFlow);
}; };
class GCDApiFlowRequest : public GCDApiFlow::Request { class GCDApiFlowRequest : public GCDApiFlowInterface::Request {
public: public:
GCDApiFlowRequest(); GCDApiFlowRequest();
virtual ~GCDApiFlowRequest(); virtual ~GCDApiFlowRequest();
...@@ -102,7 +114,7 @@ class GCDApiFlowRequest : public GCDApiFlow::Request { ...@@ -102,7 +114,7 @@ class GCDApiFlowRequest : public GCDApiFlow::Request {
DISALLOW_COPY_AND_ASSIGN(GCDApiFlowRequest); DISALLOW_COPY_AND_ASSIGN(GCDApiFlowRequest);
}; };
class CloudPrintApiFlowRequest : public GCDApiFlow::Request { class CloudPrintApiFlowRequest : public GCDApiFlowInterface::Request {
public: public:
CloudPrintApiFlowRequest(); CloudPrintApiFlowRequest();
virtual ~CloudPrintApiFlowRequest(); virtual ~CloudPrintApiFlowRequest();
......
...@@ -59,11 +59,9 @@ class GCDApiFlowTest : public testing::Test { ...@@ -59,11 +59,9 @@ class GCDApiFlowTest : public testing::Test {
EXPECT_CALL(*mock_delegate_, GetURL()) EXPECT_CALL(*mock_delegate_, GetURL())
.WillRepeatedly(Return( .WillRepeatedly(Return(
GURL("https://www.google.com/cloudprint/confirm?token=SomeToken"))); GURL("https://www.google.com/cloudprint/confirm?token=SomeToken")));
gcd_flow_.reset(new GCDApiFlow(request_context_.get(), gcd_flow_.reset(
&token_service_, new GCDApiFlow(request_context_.get(), &token_service_, account_id_));
account_id_, gcd_flow_->Start(delegate.PassAs<GCDApiFlow::Request>());
delegate.PassAs<GCDApiFlow::Request>()));
gcd_flow_->Start();
} }
base::MessageLoopForUI loop_; base::MessageLoopForUI loop_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
......
...@@ -38,7 +38,7 @@ net::URLFetcher::RequestType GCDRegistrationTicketRequest::GetRequestType() { ...@@ -38,7 +38,7 @@ net::URLFetcher::RequestType GCDRegistrationTicketRequest::GetRequestType() {
} }
void GCDRegistrationTicketRequest::OnGCDAPIFlowError( void GCDRegistrationTicketRequest::OnGCDAPIFlowError(
GCDApiFlow::Status status) { GCDApiFlowInterface::Status status) {
callback_.Run(std::string()); callback_.Run(std::string());
} }
......
...@@ -26,7 +26,7 @@ class GCDRegistrationTicketRequest : public GCDApiFlowRequest { ...@@ -26,7 +26,7 @@ class GCDRegistrationTicketRequest : public GCDApiFlowRequest {
virtual void GetUploadData(std::string* upload_type, virtual void GetUploadData(std::string* upload_type,
std::string* upload_data) OVERRIDE; std::string* upload_data) OVERRIDE;
virtual net::URLFetcher::RequestType GetRequestType() OVERRIDE; virtual net::URLFetcher::RequestType GetRequestType() OVERRIDE;
virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE; virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete( virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE; const base::DictionaryValue& value) OVERRIDE;
virtual GURL GetURL() OVERRIDE; virtual GURL GetURL() OVERRIDE;
......
...@@ -33,7 +33,8 @@ PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow( ...@@ -33,7 +33,8 @@ PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() { PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
} }
void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(GCDApiFlow::Status status) { void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(
GCDApiFlowInterface::Status status) {
callback_.Run(status); callback_.Run(status);
} }
...@@ -42,14 +43,14 @@ void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete( ...@@ -42,14 +43,14 @@ void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete(
bool success = false; bool success = false;
if (!value.GetBoolean(cloud_print::kSuccessValue, &success)) { if (!value.GetBoolean(cloud_print::kSuccessValue, &success)) {
callback_.Run(GCDApiFlow::ERROR_MALFORMED_RESPONSE); callback_.Run(GCDApiFlowInterface::ERROR_MALFORMED_RESPONSE);
return; return;
} }
if (success) { if (success) {
callback_.Run(GCDApiFlow::SUCCESS); callback_.Run(GCDApiFlowInterface::SUCCESS);
} else { } else {
callback_.Run(GCDApiFlow::ERROR_FROM_SERVER); callback_.Run(GCDApiFlowInterface::ERROR_FROM_SERVER);
} }
} }
......
...@@ -16,7 +16,8 @@ namespace local_discovery { ...@@ -16,7 +16,8 @@ namespace local_discovery {
// API call flow for server-side communication with CloudPrint for registration. // API call flow for server-side communication with CloudPrint for registration.
class PrivetConfirmApiCallFlow : public CloudPrintApiFlowRequest { class PrivetConfirmApiCallFlow : public CloudPrintApiFlowRequest {
public: public:
typedef base::Callback<void(GCDApiFlow::Status /*success*/)> ResponseCallback; typedef base::Callback<void(GCDApiFlowInterface::Status /*success*/)>
ResponseCallback;
// Create an OAuth2-based confirmation // Create an OAuth2-based confirmation
PrivetConfirmApiCallFlow(const std::string& token, PrivetConfirmApiCallFlow(const std::string& token,
...@@ -24,7 +25,7 @@ class PrivetConfirmApiCallFlow : public CloudPrintApiFlowRequest { ...@@ -24,7 +25,7 @@ class PrivetConfirmApiCallFlow : public CloudPrintApiFlowRequest {
virtual ~PrivetConfirmApiCallFlow(); virtual ~PrivetConfirmApiCallFlow();
virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE; virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete( virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE; const base::DictionaryValue& value) OVERRIDE;
virtual net::URLFetcher::RequestType GetRequestType() OVERRIDE; virtual net::URLFetcher::RequestType GetRequestType() OVERRIDE;
......
...@@ -38,21 +38,22 @@ TEST(PrivetConfirmApiFlowTest, Params) { ...@@ -38,21 +38,22 @@ TEST(PrivetConfirmApiFlowTest, Params) {
class MockDelegate { class MockDelegate {
public: public:
MOCK_METHOD1(Callback, void(GCDApiFlow::Status)); MOCK_METHOD1(Callback, void(GCDApiFlowInterface::Status));
}; };
TEST(CloudPrintPrinterListTest, Parsing) { TEST(CloudPrintPrinterListTest, Parsing) {
StrictMock<MockDelegate> delegate; StrictMock<MockDelegate> delegate;
PrivetConfirmApiCallFlow confirmation( PrivetConfirmApiCallFlow confirmation(
"123", base::Bind(&MockDelegate::Callback, base::Unretained(&delegate))); "123", base::Bind(&MockDelegate::Callback, base::Unretained(&delegate)));
EXPECT_CALL(delegate, Callback(GCDApiFlow::SUCCESS)).Times(1); EXPECT_CALL(delegate, Callback(GCDApiFlowInterface::SUCCESS)).Times(1);
scoped_ptr<base::Value> value(base::JSONReader::Read(kSampleConfirmResponse)); scoped_ptr<base::Value> value(base::JSONReader::Read(kSampleConfirmResponse));
const base::DictionaryValue* dictionary = NULL; const base::DictionaryValue* dictionary = NULL;
ASSERT_TRUE(value->GetAsDictionary(&dictionary)); ASSERT_TRUE(value->GetAsDictionary(&dictionary));
confirmation.OnGCDAPIFlowComplete(*dictionary); confirmation.OnGCDAPIFlowComplete(*dictionary);
EXPECT_CALL(delegate, Callback(GCDApiFlow::ERROR_FROM_SERVER)).Times(1); EXPECT_CALL(delegate, Callback(GCDApiFlowInterface::ERROR_FROM_SERVER))
.Times(1);
value.reset(base::JSONReader::Read(kFailedConfirmResponse)); value.reset(base::JSONReader::Read(kFailedConfirmResponse));
ASSERT_TRUE(value->GetAsDictionary(&dictionary)); ASSERT_TRUE(value->GetAsDictionary(&dictionary));
......
...@@ -11,8 +11,19 @@ namespace local_discovery { ...@@ -11,8 +11,19 @@ namespace local_discovery {
// static // static
scoped_ptr<PrivetV1HTTPClient> PrivetV1HTTPClient::CreateDefault( scoped_ptr<PrivetV1HTTPClient> PrivetV1HTTPClient::CreateDefault(
scoped_ptr<PrivetHTTPClient> info_client) { scoped_ptr<PrivetHTTPClient> info_client) {
if (!info_client)
return scoped_ptr<PrivetV1HTTPClient>();
return make_scoped_ptr<PrivetV1HTTPClient>( return make_scoped_ptr<PrivetV1HTTPClient>(
new PrivetV1HTTPClientImpl(info_client.Pass())).Pass(); new PrivetV1HTTPClientImpl(info_client.Pass())).Pass();
} }
// static
scoped_ptr<PrivetV3HTTPClient> PrivetV3HTTPClient::CreateDefault(
scoped_ptr<PrivetHTTPClient> info_client) {
if (!info_client)
return scoped_ptr<PrivetV3HTTPClient>();
return make_scoped_ptr<PrivetV3HTTPClient>(
new PrivetV3HTTPClientImpl(info_client.Pass())).Pass();
}
} // namespace local_discovery } // namespace local_discovery
...@@ -185,12 +185,12 @@ class PrivetV1HTTPClient { ...@@ -185,12 +185,12 @@ class PrivetV1HTTPClient {
public: public:
virtual ~PrivetV1HTTPClient() {} virtual ~PrivetV1HTTPClient() {}
// A name for the HTTP client, e.g. the device name for the privet device.
virtual const std::string& GetName() = 0;
static scoped_ptr<PrivetV1HTTPClient> CreateDefault( static scoped_ptr<PrivetV1HTTPClient> CreateDefault(
scoped_ptr<PrivetHTTPClient> info_client); scoped_ptr<PrivetHTTPClient> info_client);
// A name for the HTTP client, e.g. the device name for the privet device.
virtual const std::string& GetName() = 0;
// Creates operation to query basic information about local device. // Creates operation to query basic information about local device.
virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation( virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation(
const PrivetJSONOperation::ResultCallback& callback) = 0; const PrivetJSONOperation::ResultCallback& callback) = 0;
...@@ -219,5 +219,21 @@ class PrivetV1HTTPClient { ...@@ -219,5 +219,21 @@ class PrivetV1HTTPClient {
const PrivetDataReadOperation::ResultCallback& callback) = 0; const PrivetDataReadOperation::ResultCallback& callback) = 0;
}; };
// Privet HTTP client. Must outlive the operations it creates.
class PrivetV3HTTPClient {
public:
virtual ~PrivetV3HTTPClient() {}
static scoped_ptr<PrivetV3HTTPClient> CreateDefault(
scoped_ptr<PrivetHTTPClient> info_client);
// A name for the HTTP client, e.g. the device name for the privet device.
virtual const std::string& GetName() = 0;
// Creates operation to query basic information about local device.
virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation(
const PrivetJSONOperation::ResultCallback& callback) = 0;
};
} // namespace local_discovery } // namespace local_discovery
#endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_H_ #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_H_
...@@ -949,4 +949,21 @@ PrivetV1HTTPClientImpl::CreateStorageReadOperation( ...@@ -949,4 +949,21 @@ PrivetV1HTTPClientImpl::CreateStorageReadOperation(
info_client(), kPrivetStorageContentPath, url_param, callback)); info_client(), kPrivetStorageContentPath, url_param, callback));
} }
PrivetV3HTTPClientImpl::PrivetV3HTTPClientImpl(
scoped_ptr<PrivetHTTPClient> info_client)
: info_client_(info_client.Pass()) {
}
PrivetV3HTTPClientImpl::~PrivetV3HTTPClientImpl() {
}
const std::string& PrivetV3HTTPClientImpl::GetName() {
return info_client()->GetName();
}
scoped_ptr<PrivetJSONOperation> PrivetV3HTTPClientImpl::CreateInfoOperation(
const PrivetJSONOperation::ResultCallback& callback) {
return info_client()->CreateInfoOperation(callback);
}
} // namespace local_discovery } // namespace local_discovery
...@@ -346,5 +346,22 @@ class PrivetV1HTTPClientImpl : public PrivetV1HTTPClient { ...@@ -346,5 +346,22 @@ class PrivetV1HTTPClientImpl : public PrivetV1HTTPClient {
DISALLOW_COPY_AND_ASSIGN(PrivetV1HTTPClientImpl); DISALLOW_COPY_AND_ASSIGN(PrivetV1HTTPClientImpl);
}; };
class PrivetV3HTTPClientImpl : public PrivetV3HTTPClient {
public:
explicit PrivetV3HTTPClientImpl(scoped_ptr<PrivetHTTPClient> info_client);
virtual ~PrivetV3HTTPClientImpl();
virtual const std::string& GetName() OVERRIDE;
virtual scoped_ptr<PrivetJSONOperation> CreateInfoOperation(
const PrivetJSONOperation::ResultCallback& callback) OVERRIDE;
private:
PrivetHTTPClient* info_client() { return info_client_.get(); }
scoped_ptr<PrivetHTTPClient> info_client_;
DISALLOW_COPY_AND_ASSIGN(PrivetV3HTTPClientImpl);
};
} // namespace local_discovery } // namespace local_discovery
#endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_ #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_
...@@ -15,7 +15,7 @@ PrivetV3Session::Delegate::~Delegate() { ...@@ -15,7 +15,7 @@ PrivetV3Session::Delegate::~Delegate() {
PrivetV3Session::Request::~Request() { PrivetV3Session::Request::~Request() {
} }
PrivetV3Session::PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, PrivetV3Session::PrivetV3Session(scoped_ptr<PrivetV3HTTPClient> client,
Delegate* delegate) { Delegate* delegate) {
} }
......
...@@ -16,7 +16,7 @@ class DictionaryValue; ...@@ -16,7 +16,7 @@ class DictionaryValue;
namespace local_discovery { namespace local_discovery {
class PrivetHTTPClient; class PrivetV3HTTPClient;
// Manages secure communication between browser and local Privet device. // Manages secure communication between browser and local Privet device.
class PrivetV3Session { class PrivetV3Session {
...@@ -52,7 +52,7 @@ class PrivetV3Session { ...@@ -52,7 +52,7 @@ class PrivetV3Session {
virtual void Start() = 0; virtual void Start() = 0;
}; };
PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate); PrivetV3Session(scoped_ptr<PrivetV3HTTPClient> client, Delegate* delegate);
~PrivetV3Session(); ~PrivetV3Session();
// Establishes a session, will call |OnSetupConfirmationNeeded| and then // Establishes a session, will call |OnSetupConfirmationNeeded| and then
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "chrome/browser/local_discovery/gcd_api_flow.h" #include "chrome/browser/local_discovery/gcd_api_flow.h"
#include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h"
namespace local_discovery { namespace local_discovery {
...@@ -26,11 +25,13 @@ class PrivetV3SetupFlow { ...@@ -26,11 +25,13 @@ class PrivetV3SetupFlow {
typedef base::Callback<void(const std::string& ssid, typedef base::Callback<void(const std::string& ssid,
const std::string& key)> CredentialsCallback; const std::string& key)> CredentialsCallback;
typedef base::Callback<void(scoped_ptr<PrivetV3HTTPClient>)>
PrivetClientCallback;
virtual ~Delegate(); virtual ~Delegate();
// Creates |GCDApiFlow| for making requests to GCD server. // Creates |GCDApiFlow| for making requests to GCD server.
virtual scoped_ptr<GCDApiFlow> CreateApiFlow( virtual scoped_ptr<GCDApiFlowInterface> CreateApiFlow() = 0;
scoped_ptr<GCDApiFlow::Request> request) = 0;
// Requests WiFi credentials. // Requests WiFi credentials.
virtual void GetWiFiCredentials(const CredentialsCallback& callback) = 0; virtual void GetWiFiCredentials(const CredentialsCallback& callback) = 0;
...@@ -40,10 +41,9 @@ class PrivetV3SetupFlow { ...@@ -40,10 +41,9 @@ class PrivetV3SetupFlow {
virtual void SwitchToSetupWiFi(const ResultCallback& callback) = 0; virtual void SwitchToSetupWiFi(const ResultCallback& callback) = 0;
// Starts device resolution that should callback with ready // Starts device resolution that should callback with ready
// |PrivetHTTPClient|. // |PrivetV3HTTPClient|.
virtual scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP( virtual void CreatePrivetV3Client(const std::string& service_name,
const std::string& service_name, const PrivetClientCallback& callback) = 0;
const PrivetHTTPAsynchronousFactory::ResultCallback& callback) = 0;
// Requests client to prompt user to check |confirmation_code|. // Requests client to prompt user to check |confirmation_code|.
virtual void ConfirmSecurityCode(const std::string& confirmation_code, virtual void ConfirmSecurityCode(const std::string& confirmation_code,
......
...@@ -239,18 +239,21 @@ void LocalDiscoveryUIHandler::HandleRequestDeviceList( ...@@ -239,18 +239,21 @@ void LocalDiscoveryUIHandler::HandleRequestDeviceList(
succeded_list_count_ = 0; succeded_list_count_ = 0;
cloud_devices_.clear(); cloud_devices_.clear();
cloud_print_printer_list_ = CreateApiFlow( cloud_print_printer_list_ = CreateApiFlow();
scoped_ptr<GCDApiFlow::Request>(new CloudPrintPrinterList(this)));
if (CommandLine::ForCurrentProcess()->HasSwitch( if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableCloudDevices)) { switches::kEnableCloudDevices)) {
cloud_device_list_ = CreateApiFlow( cloud_device_list_ = CreateApiFlow();
scoped_ptr<GCDApiFlow::Request>(new CloudDeviceList(this)));
} }
if (cloud_print_printer_list_) if (cloud_print_printer_list_) {
cloud_print_printer_list_->Start(); cloud_print_printer_list_->Start(
if (cloud_device_list_) make_scoped_ptr<GCDApiFlowInterface::Request>(
cloud_device_list_->Start(); new CloudPrintPrinterList(this)));
}
if (cloud_device_list_) {
cloud_device_list_->Start(make_scoped_ptr<GCDApiFlowInterface::Request>(
new CloudDeviceList(this)));
}
CheckListingDone(); CheckListingDone();
} }
...@@ -310,16 +313,16 @@ void LocalDiscoveryUIHandler::OnPrivetRegisterClaimToken( ...@@ -310,16 +313,16 @@ void LocalDiscoveryUIHandler::OnPrivetRegisterClaimToken(
return; return;
} }
confirm_api_call_flow_ = CreateApiFlow( confirm_api_call_flow_ = CreateApiFlow();
scoped_ptr<GCDApiFlow::Request>(new PrivetConfirmApiCallFlow(
token,
base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone,
base::Unretained(this)))));
if (!confirm_api_call_flow_) { if (!confirm_api_call_flow_) {
SendRegisterError(); SendRegisterError();
return; return;
} }
confirm_api_call_flow_->Start(); confirm_api_call_flow_->Start(make_scoped_ptr<GCDApiFlowInterface::Request>(
new PrivetConfirmApiCallFlow(
token,
base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone,
base::Unretained(this)))));
} }
void LocalDiscoveryUIHandler::OnPrivetRegisterError( void LocalDiscoveryUIHandler::OnPrivetRegisterError(
...@@ -480,7 +483,7 @@ std::string LocalDiscoveryUIHandler::GetSyncAccount() { ...@@ -480,7 +483,7 @@ std::string LocalDiscoveryUIHandler::GetSyncAccount() {
// TODO(noamsml): Create master object for registration flow. // TODO(noamsml): Create master object for registration flow.
void LocalDiscoveryUIHandler::ResetCurrentRegistration() { void LocalDiscoveryUIHandler::ResetCurrentRegistration() {
if (current_register_operation_.get()) { if (current_register_operation_) {
current_register_operation_->Cancel(); current_register_operation_->Cancel();
current_register_operation_.reset(); current_register_operation_.reset();
} }
...@@ -528,24 +531,22 @@ void LocalDiscoveryUIHandler::CheckListingDone() { ...@@ -528,24 +531,22 @@ void LocalDiscoveryUIHandler::CheckListingDone() {
cloud_device_list_.reset(); cloud_device_list_.reset();
} }
scoped_ptr<GCDApiFlow> LocalDiscoveryUIHandler::CreateApiFlow( scoped_ptr<GCDApiFlowInterface> LocalDiscoveryUIHandler::CreateApiFlow() {
scoped_ptr<GCDApiFlow::Request> request) {
Profile* profile = Profile::FromWebUI(web_ui()); Profile* profile = Profile::FromWebUI(web_ui());
if (!profile) if (!profile)
return scoped_ptr<GCDApiFlow>(); return scoped_ptr<GCDApiFlowInterface>();
ProfileOAuth2TokenService* token_service = ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile); ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
if (!token_service) if (!token_service)
return scoped_ptr<GCDApiFlow>(); return scoped_ptr<GCDApiFlowInterface>();
SigninManagerBase* signin_manager = SigninManagerBase* signin_manager =
SigninManagerFactory::GetInstance()->GetForProfile(profile); SigninManagerFactory::GetInstance()->GetForProfile(profile);
if (!signin_manager) if (!signin_manager)
return scoped_ptr<GCDApiFlow>(); return scoped_ptr<GCDApiFlowInterface>();
return make_scoped_ptr( return make_scoped_ptr<GCDApiFlowInterface>(
new GCDApiFlow(profile->GetRequestContext(), new GCDApiFlow(profile->GetRequestContext(),
token_service, token_service,
signin_manager->GetAuthenticatedAccountId(), signin_manager->GetAuthenticatedAccountId()));
request.Pass()));
} }
#if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
......
...@@ -52,20 +52,17 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -52,20 +52,17 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// WebUIMessageHandler implementation. // WebUIMessageHandler implementation.
virtual void RegisterMessages() OVERRIDE; virtual void RegisterMessages() OVERRIDE;
// PrivetRegisterOperation::Delegate implementation. // PrivetRegisterOperation::Delegate implementation.
virtual void OnPrivetRegisterClaimToken( virtual void OnPrivetRegisterClaimToken(
PrivetRegisterOperation* operation, PrivetRegisterOperation* operation,
const std::string& token, const std::string& token,
const GURL& url) OVERRIDE; const GURL& url) OVERRIDE;
virtual void OnPrivetRegisterError( virtual void OnPrivetRegisterError(
PrivetRegisterOperation* operation, PrivetRegisterOperation* operation,
const std::string& action, const std::string& action,
PrivetRegisterOperation::FailureReason reason, PrivetRegisterOperation::FailureReason reason,
int printer_http_code, int printer_http_code,
const base::DictionaryValue* json) OVERRIDE; const base::DictionaryValue* json) OVERRIDE;
virtual void OnPrivetRegisterDone( virtual void OnPrivetRegisterDone(
PrivetRegisterOperation* operation, PrivetRegisterOperation* operation,
const std::string& device_id) OVERRIDE; const std::string& device_id) OVERRIDE;
...@@ -74,9 +71,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -74,9 +71,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
virtual void DeviceChanged(bool added, virtual void DeviceChanged(bool added,
const std::string& name, const std::string& name,
const DeviceDescription& description) OVERRIDE; const DeviceDescription& description) OVERRIDE;
virtual void DeviceRemoved(const std::string& name) OVERRIDE; virtual void DeviceRemoved(const std::string& name) OVERRIDE;
virtual void DeviceCacheFlushed() OVERRIDE; virtual void DeviceCacheFlushed() OVERRIDE;
// CloudDeviceListDelegate implementation. // CloudDeviceListDelegate implementation.
...@@ -86,7 +81,6 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -86,7 +81,6 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// SigninManagerBase::Observer implementation. // SigninManagerBase::Observer implementation.
virtual void GoogleSigninSucceeded(const std::string& username, virtual void GoogleSigninSucceeded(const std::string& username,
const std::string& password) OVERRIDE; const std::string& password) OVERRIDE;
virtual void GoogleSignedOut(const std::string& username) OVERRIDE; virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
private: private:
...@@ -120,7 +114,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -120,7 +114,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// For when the confirm operation on the cloudprint server has finished // For when the confirm operation on the cloudprint server has finished
// executing. // executing.
void OnConfirmDone(GCDApiFlow::Status status); void OnConfirmDone(GCDApiFlowInterface::Status status);
// Signal to the web interface an error has ocurred while registering. // Signal to the web interface an error has ocurred while registering.
void SendRegisterError(); void SendRegisterError();
...@@ -147,7 +141,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -147,7 +141,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
void CheckListingDone(); void CheckListingDone();
scoped_ptr<GCDApiFlow> CreateApiFlow(scoped_ptr<GCDApiFlow::Request> request); scoped_ptr<GCDApiFlowInterface> CreateApiFlow();
#if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE) #if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
void StartCloudPrintConnector(); void StartCloudPrintConnector();
...@@ -166,17 +160,8 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -166,17 +160,8 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
const wifi::BootstrappingDeviceDescription& description); const wifi::BootstrappingDeviceDescription& description);
#endif #endif
// The current HTTP client (used for the current operation). // A map of current device descriptions provided by the PrivetDeviceLister.
scoped_ptr<PrivetV1HTTPClient> current_http_client_; DeviceDescriptionMap device_descriptions_;
// The current register operation. Only one allowed at any time.
scoped_ptr<PrivetRegisterOperation> current_register_operation_;
// The current confirm call used during the registration flow.
scoped_ptr<GCDApiFlow> confirm_api_call_flow_;
// The device lister used to list devices on the local network.
scoped_ptr<PrivetDeviceLister> privet_lister_;
// The service discovery client used listen for devices on the local network. // The service discovery client used listen for devices on the local network.
scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_; scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_;
...@@ -187,15 +172,24 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler, ...@@ -187,15 +172,24 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// An object representing the resolution process for the privet_http_factory. // An object representing the resolution process for the privet_http_factory.
scoped_ptr<PrivetHTTPResolution> privet_resolution_; scoped_ptr<PrivetHTTPResolution> privet_resolution_;
// A map of current device descriptions provided by the PrivetDeviceLister. // The current HTTP client (used for the current operation).
DeviceDescriptionMap device_descriptions_; scoped_ptr<PrivetV1HTTPClient> current_http_client_;
// The current register operation. Only one allowed at any time.
scoped_ptr<PrivetRegisterOperation> current_register_operation_;
// The current confirm call used during the registration flow.
scoped_ptr<GCDApiFlowInterface> confirm_api_call_flow_;
// The device lister used to list devices on the local network.
scoped_ptr<PrivetDeviceLister> privet_lister_;
// Whether or not the page is marked as visible. // Whether or not the page is marked as visible.
bool is_visible_; bool is_visible_;
// List of printers from cloud print. // List of printers from cloud print.
scoped_ptr<GCDApiFlow> cloud_print_printer_list_; scoped_ptr<GCDApiFlowInterface> cloud_print_printer_list_;
scoped_ptr<GCDApiFlow> cloud_device_list_; scoped_ptr<GCDApiFlowInterface> cloud_device_list_;
std::vector<Device> cloud_devices_; std::vector<Device> cloud_devices_;
int failed_list_count_; int failed_list_count_;
int succeded_list_count_; int succeded_list_count_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment