summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-08 11:25:40 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-08 11:25:40 +0000
commit9d51882d2222c2bf221d3ba4449be7916ebf39fc (patch)
treeb14f88c3b7e0ef34149bdd714afca5987f584d5e
parent12eb772f380093bad809409f81e69101b7d7198f (diff)
downloadchromium_src-9d51882d2222c2bf221d3ba4449be7916ebf39fc.zip
chromium_src-9d51882d2222c2bf221d3ba4449be7916ebf39fc.tar.gz
chromium_src-9d51882d2222c2bf221d3ba4449be7916ebf39fc.tar.bz2
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
-rw-r--r--chrome/browser/local_discovery/cloud_device_list.cc2
-rw-r--r--chrome/browser/local_discovery/cloud_device_list.h2
-rw-r--r--chrome/browser/local_discovery/cloud_print_printer_list.cc3
-rw-r--r--chrome/browser/local_discovery/cloud_print_printer_list.h2
-rw-r--r--chrome/browser/local_discovery/gcd_api_flow.cc25
-rw-r--r--chrome/browser/local_discovery/gcd_api_flow.h26
-rw-r--r--chrome/browser/local_discovery/gcd_api_flow_unittest.cc8
-rw-r--r--chrome/browser/local_discovery/gcd_registration_ticket_request.cc2
-rw-r--r--chrome/browser/local_discovery/gcd_registration_ticket_request.h2
-rw-r--r--chrome/browser/local_discovery/privet_confirm_api_flow.cc9
-rw-r--r--chrome/browser/local_discovery/privet_confirm_api_flow.h5
-rw-r--r--chrome/browser/local_discovery/privet_confirm_api_flow_unittest.cc7
-rw-r--r--chrome/browser/local_discovery/privet_http.cc11
-rw-r--r--chrome/browser/local_discovery/privet_http.h22
-rw-r--r--chrome/browser/local_discovery/privet_http_impl.cc17
-rw-r--r--chrome/browser/local_discovery/privet_http_impl.h17
-rw-r--r--chrome/browser/local_discovery/privetv3_session.cc2
-rw-r--r--chrome/browser/local_discovery/privetv3_session.h4
-rw-r--r--chrome/browser/local_discovery/privetv3_setup_flow.h14
-rw-r--r--chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc47
-rw-r--r--chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h40
21 files changed, 171 insertions, 96 deletions
diff --git a/chrome/browser/local_discovery/cloud_device_list.cc b/chrome/browser/local_discovery/cloud_device_list.cc
index 95c2a7f..292932d 100644
--- a/chrome/browser/local_discovery/cloud_device_list.cc
+++ b/chrome/browser/local_discovery/cloud_device_list.cc
@@ -23,7 +23,7 @@ CloudDeviceList::CloudDeviceList(CloudDeviceListDelegate* delegate)
CloudDeviceList::~CloudDeviceList() {
}
-void CloudDeviceList::OnGCDAPIFlowError(GCDApiFlow::Status status) {
+void CloudDeviceList::OnGCDAPIFlowError(GCDApiFlowInterface::Status status) {
delegate_->OnDeviceListUnavailable();
}
diff --git a/chrome/browser/local_discovery/cloud_device_list.h b/chrome/browser/local_discovery/cloud_device_list.h
index 34dcd45..4a1d337 100644
--- a/chrome/browser/local_discovery/cloud_device_list.h
+++ b/chrome/browser/local_discovery/cloud_device_list.h
@@ -21,7 +21,7 @@ class CloudDeviceList : public GCDApiFlowRequest {
explicit CloudDeviceList(CloudDeviceListDelegate* delegate);
virtual ~CloudDeviceList();
- virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE;
+ virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE;
diff --git a/chrome/browser/local_discovery/cloud_print_printer_list.cc b/chrome/browser/local_discovery/cloud_print_printer_list.cc
index a8de56a..97da412 100644
--- a/chrome/browser/local_discovery/cloud_print_printer_list.cc
+++ b/chrome/browser/local_discovery/cloud_print_printer_list.cc
@@ -19,7 +19,8 @@ CloudPrintPrinterList::CloudPrintPrinterList(CloudDeviceListDelegate* delegate)
CloudPrintPrinterList::~CloudPrintPrinterList() {
}
-void CloudPrintPrinterList::OnGCDAPIFlowError(GCDApiFlow::Status status) {
+void CloudPrintPrinterList::OnGCDAPIFlowError(
+ GCDApiFlowInterface::Status status) {
delegate_->OnDeviceListUnavailable();
}
diff --git a/chrome/browser/local_discovery/cloud_print_printer_list.h b/chrome/browser/local_discovery/cloud_print_printer_list.h
index 6f1f270..ce6ab36 100644
--- a/chrome/browser/local_discovery/cloud_print_printer_list.h
+++ b/chrome/browser/local_discovery/cloud_print_printer_list.h
@@ -18,7 +18,7 @@ class CloudPrintPrinterList : public CloudPrintApiFlowRequest {
explicit CloudPrintPrinterList(CloudDeviceListDelegate* delegate);
virtual ~CloudPrintPrinterList();
- virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE;
+ virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE;
diff --git a/chrome/browser/local_discovery/gcd_api_flow.cc b/chrome/browser/local_discovery/gcd_api_flow.cc
index d3ca584..b8ed671 100644
--- a/chrome/browser/local_discovery/gcd_api_flow.cc
+++ b/chrome/browser/local_discovery/gcd_api_flow.cc
@@ -23,37 +23,42 @@ namespace {
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;
}
-void GCDApiFlow::Request::GetUploadData(std::string* upload_type,
- std::string* upload_data) {
+void GCDApiFlowInterface::Request::GetUploadData(std::string* upload_type,
+ std::string* upload_data) {
*upload_type = std::string();
*upload_data = std::string();
}
+GCDApiFlowInterface::GCDApiFlowInterface() {
+}
+
+GCDApiFlowInterface::~GCDApiFlowInterface() {
+}
+
GCDApiFlow::GCDApiFlow(net::URLRequestContextGetter* request_context,
OAuth2TokenService* token_service,
- const std::string& account_id,
- scoped_ptr<Request> delegate)
+ const std::string& account_id)
: OAuth2TokenService::Consumer("cloud_print"),
request_context_(request_context),
token_service_(token_service),
- account_id_(account_id),
- request_(delegate.Pass()) {
+ account_id_(account_id) {
}
GCDApiFlow::~GCDApiFlow() {
}
-void GCDApiFlow::Start() {
+void GCDApiFlow::Start(scoped_ptr<Request> request) {
+ request_ = request.Pass();
OAuth2TokenService::ScopeSet oauth_scopes;
oauth_scopes.insert(request_->GetOAuthScope());
oauth_request_ =
diff --git a/chrome/browser/local_discovery/gcd_api_flow.h b/chrome/browser/local_discovery/gcd_api_flow.h
index 492e178..07c9ce4 100644
--- a/chrome/browser/local_discovery/gcd_api_flow.h
+++ b/chrome/browser/local_discovery/gcd_api_flow.h
@@ -17,8 +17,7 @@
namespace local_discovery {
// API flow for communicating with cloud print and cloud devices.
-class GCDApiFlow : public net::URLFetcherDelegate,
- public OAuth2TokenService::Consumer {
+class GCDApiFlowInterface {
public:
// TODO(noamsml): Better error model for this class.
enum Status {
@@ -57,15 +56,27 @@ class GCDApiFlow : public net::URLFetcherDelegate,
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.
GCDApiFlow(net::URLRequestContextGetter* request_context,
OAuth2TokenService* token_service,
- const std::string& account_id,
- scoped_ptr<Request> request);
+ const std::string& account_id);
virtual ~GCDApiFlow();
- void Start();
+ virtual void Start(scoped_ptr<Request> request) OVERRIDE;
// net::URLFetcherDelegate implementation:
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
@@ -86,10 +97,11 @@ class GCDApiFlow : public net::URLFetcherDelegate,
OAuth2TokenService* token_service_;
std::string account_id_;
scoped_ptr<Request> request_;
+
DISALLOW_COPY_AND_ASSIGN(GCDApiFlow);
};
-class GCDApiFlowRequest : public GCDApiFlow::Request {
+class GCDApiFlowRequest : public GCDApiFlowInterface::Request {
public:
GCDApiFlowRequest();
virtual ~GCDApiFlowRequest();
@@ -102,7 +114,7 @@ class GCDApiFlowRequest : public GCDApiFlow::Request {
DISALLOW_COPY_AND_ASSIGN(GCDApiFlowRequest);
};
-class CloudPrintApiFlowRequest : public GCDApiFlow::Request {
+class CloudPrintApiFlowRequest : public GCDApiFlowInterface::Request {
public:
CloudPrintApiFlowRequest();
virtual ~CloudPrintApiFlowRequest();
diff --git a/chrome/browser/local_discovery/gcd_api_flow_unittest.cc b/chrome/browser/local_discovery/gcd_api_flow_unittest.cc
index a11cef8..ad01295 100644
--- a/chrome/browser/local_discovery/gcd_api_flow_unittest.cc
+++ b/chrome/browser/local_discovery/gcd_api_flow_unittest.cc
@@ -59,11 +59,9 @@ class GCDApiFlowTest : public testing::Test {
EXPECT_CALL(*mock_delegate_, GetURL())
.WillRepeatedly(Return(
GURL("https://www.google.com/cloudprint/confirm?token=SomeToken")));
- gcd_flow_.reset(new GCDApiFlow(request_context_.get(),
- &token_service_,
- account_id_,
- delegate.PassAs<GCDApiFlow::Request>()));
- gcd_flow_->Start();
+ gcd_flow_.reset(
+ new GCDApiFlow(request_context_.get(), &token_service_, account_id_));
+ gcd_flow_->Start(delegate.PassAs<GCDApiFlow::Request>());
}
base::MessageLoopForUI loop_;
content::TestBrowserThread ui_thread_;
diff --git a/chrome/browser/local_discovery/gcd_registration_ticket_request.cc b/chrome/browser/local_discovery/gcd_registration_ticket_request.cc
index e60eb07..b8e1f52 100644
--- a/chrome/browser/local_discovery/gcd_registration_ticket_request.cc
+++ b/chrome/browser/local_discovery/gcd_registration_ticket_request.cc
@@ -38,7 +38,7 @@ net::URLFetcher::RequestType GCDRegistrationTicketRequest::GetRequestType() {
}
void GCDRegistrationTicketRequest::OnGCDAPIFlowError(
- GCDApiFlow::Status status) {
+ GCDApiFlowInterface::Status status) {
callback_.Run(std::string());
}
diff --git a/chrome/browser/local_discovery/gcd_registration_ticket_request.h b/chrome/browser/local_discovery/gcd_registration_ticket_request.h
index bfbb975..41f9e0e 100644
--- a/chrome/browser/local_discovery/gcd_registration_ticket_request.h
+++ b/chrome/browser/local_discovery/gcd_registration_ticket_request.h
@@ -26,7 +26,7 @@ class GCDRegistrationTicketRequest : public GCDApiFlowRequest {
virtual void GetUploadData(std::string* upload_type,
std::string* upload_data) OVERRIDE;
virtual net::URLFetcher::RequestType GetRequestType() OVERRIDE;
- virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE;
+ virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE;
virtual GURL GetURL() OVERRIDE;
diff --git a/chrome/browser/local_discovery/privet_confirm_api_flow.cc b/chrome/browser/local_discovery/privet_confirm_api_flow.cc
index adc4e95..b174128 100644
--- a/chrome/browser/local_discovery/privet_confirm_api_flow.cc
+++ b/chrome/browser/local_discovery/privet_confirm_api_flow.cc
@@ -33,7 +33,8 @@ PrivetConfirmApiCallFlow::PrivetConfirmApiCallFlow(
PrivetConfirmApiCallFlow::~PrivetConfirmApiCallFlow() {
}
-void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(GCDApiFlow::Status status) {
+void PrivetConfirmApiCallFlow::OnGCDAPIFlowError(
+ GCDApiFlowInterface::Status status) {
callback_.Run(status);
}
@@ -42,14 +43,14 @@ void PrivetConfirmApiCallFlow::OnGCDAPIFlowComplete(
bool success = false;
if (!value.GetBoolean(cloud_print::kSuccessValue, &success)) {
- callback_.Run(GCDApiFlow::ERROR_MALFORMED_RESPONSE);
+ callback_.Run(GCDApiFlowInterface::ERROR_MALFORMED_RESPONSE);
return;
}
if (success) {
- callback_.Run(GCDApiFlow::SUCCESS);
+ callback_.Run(GCDApiFlowInterface::SUCCESS);
} else {
- callback_.Run(GCDApiFlow::ERROR_FROM_SERVER);
+ callback_.Run(GCDApiFlowInterface::ERROR_FROM_SERVER);
}
}
diff --git a/chrome/browser/local_discovery/privet_confirm_api_flow.h b/chrome/browser/local_discovery/privet_confirm_api_flow.h
index f3382ed..1544411 100644
--- a/chrome/browser/local_discovery/privet_confirm_api_flow.h
+++ b/chrome/browser/local_discovery/privet_confirm_api_flow.h
@@ -16,7 +16,8 @@ namespace local_discovery {
// API call flow for server-side communication with CloudPrint for registration.
class PrivetConfirmApiCallFlow : public CloudPrintApiFlowRequest {
public:
- typedef base::Callback<void(GCDApiFlow::Status /*success*/)> ResponseCallback;
+ typedef base::Callback<void(GCDApiFlowInterface::Status /*success*/)>
+ ResponseCallback;
// Create an OAuth2-based confirmation
PrivetConfirmApiCallFlow(const std::string& token,
@@ -24,7 +25,7 @@ class PrivetConfirmApiCallFlow : public CloudPrintApiFlowRequest {
virtual ~PrivetConfirmApiCallFlow();
- virtual void OnGCDAPIFlowError(GCDApiFlow::Status status) OVERRIDE;
+ virtual void OnGCDAPIFlowError(GCDApiFlowInterface::Status status) OVERRIDE;
virtual void OnGCDAPIFlowComplete(
const base::DictionaryValue& value) OVERRIDE;
virtual net::URLFetcher::RequestType GetRequestType() OVERRIDE;
diff --git a/chrome/browser/local_discovery/privet_confirm_api_flow_unittest.cc b/chrome/browser/local_discovery/privet_confirm_api_flow_unittest.cc
index b8ce764..5ca364a 100644
--- a/chrome/browser/local_discovery/privet_confirm_api_flow_unittest.cc
+++ b/chrome/browser/local_discovery/privet_confirm_api_flow_unittest.cc
@@ -38,21 +38,22 @@ TEST(PrivetConfirmApiFlowTest, Params) {
class MockDelegate {
public:
- MOCK_METHOD1(Callback, void(GCDApiFlow::Status));
+ MOCK_METHOD1(Callback, void(GCDApiFlowInterface::Status));
};
TEST(CloudPrintPrinterListTest, Parsing) {
StrictMock<MockDelegate> delegate;
PrivetConfirmApiCallFlow confirmation(
"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));
const base::DictionaryValue* dictionary = NULL;
ASSERT_TRUE(value->GetAsDictionary(&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));
ASSERT_TRUE(value->GetAsDictionary(&dictionary));
diff --git a/chrome/browser/local_discovery/privet_http.cc b/chrome/browser/local_discovery/privet_http.cc
index 59d18111..a2c5cb2 100644
--- a/chrome/browser/local_discovery/privet_http.cc
+++ b/chrome/browser/local_discovery/privet_http.cc
@@ -11,8 +11,19 @@ namespace local_discovery {
// static
scoped_ptr<PrivetV1HTTPClient> PrivetV1HTTPClient::CreateDefault(
scoped_ptr<PrivetHTTPClient> info_client) {
+ if (!info_client)
+ return scoped_ptr<PrivetV1HTTPClient>();
return make_scoped_ptr<PrivetV1HTTPClient>(
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
diff --git a/chrome/browser/local_discovery/privet_http.h b/chrome/browser/local_discovery/privet_http.h
index e081466..bba71ae 100644
--- a/chrome/browser/local_discovery/privet_http.h
+++ b/chrome/browser/local_discovery/privet_http.h
@@ -185,12 +185,12 @@ class PrivetV1HTTPClient {
public:
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(
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;
@@ -219,5 +219,21 @@ class PrivetV1HTTPClient {
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
#endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_H_
diff --git a/chrome/browser/local_discovery/privet_http_impl.cc b/chrome/browser/local_discovery/privet_http_impl.cc
index ecdf57c..f73c6d7 100644
--- a/chrome/browser/local_discovery/privet_http_impl.cc
+++ b/chrome/browser/local_discovery/privet_http_impl.cc
@@ -949,4 +949,21 @@ PrivetV1HTTPClientImpl::CreateStorageReadOperation(
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
diff --git a/chrome/browser/local_discovery/privet_http_impl.h b/chrome/browser/local_discovery/privet_http_impl.h
index 2ef4776..fa7b399 100644
--- a/chrome/browser/local_discovery/privet_http_impl.h
+++ b/chrome/browser/local_discovery/privet_http_impl.h
@@ -346,5 +346,22 @@ class PrivetV1HTTPClientImpl : public PrivetV1HTTPClient {
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
#endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_HTTP_IMPL_H_
diff --git a/chrome/browser/local_discovery/privetv3_session.cc b/chrome/browser/local_discovery/privetv3_session.cc
index 64c8d1f..9ff7501 100644
--- a/chrome/browser/local_discovery/privetv3_session.cc
+++ b/chrome/browser/local_discovery/privetv3_session.cc
@@ -15,7 +15,7 @@ PrivetV3Session::Delegate::~Delegate() {
PrivetV3Session::Request::~Request() {
}
-PrivetV3Session::PrivetV3Session(scoped_ptr<PrivetHTTPClient> client,
+PrivetV3Session::PrivetV3Session(scoped_ptr<PrivetV3HTTPClient> client,
Delegate* delegate) {
}
diff --git a/chrome/browser/local_discovery/privetv3_session.h b/chrome/browser/local_discovery/privetv3_session.h
index 1d943f2..5692e13 100644
--- a/chrome/browser/local_discovery/privetv3_session.h
+++ b/chrome/browser/local_discovery/privetv3_session.h
@@ -16,7 +16,7 @@ class DictionaryValue;
namespace local_discovery {
-class PrivetHTTPClient;
+class PrivetV3HTTPClient;
// Manages secure communication between browser and local Privet device.
class PrivetV3Session {
@@ -52,7 +52,7 @@ class PrivetV3Session {
virtual void Start() = 0;
};
- PrivetV3Session(scoped_ptr<PrivetHTTPClient> client, Delegate* delegate);
+ PrivetV3Session(scoped_ptr<PrivetV3HTTPClient> client, Delegate* delegate);
~PrivetV3Session();
// Establishes a session, will call |OnSetupConfirmationNeeded| and then
diff --git a/chrome/browser/local_discovery/privetv3_setup_flow.h b/chrome/browser/local_discovery/privetv3_setup_flow.h
index 81e7b44..ffb5675 100644
--- a/chrome/browser/local_discovery/privetv3_setup_flow.h
+++ b/chrome/browser/local_discovery/privetv3_setup_flow.h
@@ -10,7 +10,6 @@
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/local_discovery/gcd_api_flow.h"
-#include "chrome/browser/local_discovery/privet_http_asynchronous_factory.h"
namespace local_discovery {
@@ -26,11 +25,13 @@ class PrivetV3SetupFlow {
typedef base::Callback<void(const std::string& ssid,
const std::string& key)> CredentialsCallback;
+ typedef base::Callback<void(scoped_ptr<PrivetV3HTTPClient>)>
+ PrivetClientCallback;
+
virtual ~Delegate();
// Creates |GCDApiFlow| for making requests to GCD server.
- virtual scoped_ptr<GCDApiFlow> CreateApiFlow(
- scoped_ptr<GCDApiFlow::Request> request) = 0;
+ virtual scoped_ptr<GCDApiFlowInterface> CreateApiFlow() = 0;
// Requests WiFi credentials.
virtual void GetWiFiCredentials(const CredentialsCallback& callback) = 0;
@@ -40,10 +41,9 @@ class PrivetV3SetupFlow {
virtual void SwitchToSetupWiFi(const ResultCallback& callback) = 0;
// Starts device resolution that should callback with ready
- // |PrivetHTTPClient|.
- virtual scoped_ptr<PrivetHTTPResolution> CreatePrivetHTTP(
- const std::string& service_name,
- const PrivetHTTPAsynchronousFactory::ResultCallback& callback) = 0;
+ // |PrivetV3HTTPClient|.
+ virtual void CreatePrivetV3Client(const std::string& service_name,
+ const PrivetClientCallback& callback) = 0;
// Requests client to prompt user to check |confirmation_code|.
virtual void ConfirmSecurityCode(const std::string& confirmation_code,
diff --git a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc
index e8dd3c9..bfa8bf6 100644
--- a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc
+++ b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.cc
@@ -239,18 +239,21 @@ void LocalDiscoveryUIHandler::HandleRequestDeviceList(
succeded_list_count_ = 0;
cloud_devices_.clear();
- cloud_print_printer_list_ = CreateApiFlow(
- scoped_ptr<GCDApiFlow::Request>(new CloudPrintPrinterList(this)));
+ cloud_print_printer_list_ = CreateApiFlow();
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableCloudDevices)) {
- cloud_device_list_ = CreateApiFlow(
- scoped_ptr<GCDApiFlow::Request>(new CloudDeviceList(this)));
+ cloud_device_list_ = CreateApiFlow();
}
- if (cloud_print_printer_list_)
- cloud_print_printer_list_->Start();
- if (cloud_device_list_)
- cloud_device_list_->Start();
+ if (cloud_print_printer_list_) {
+ cloud_print_printer_list_->Start(
+ make_scoped_ptr<GCDApiFlowInterface::Request>(
+ new CloudPrintPrinterList(this)));
+ }
+ if (cloud_device_list_) {
+ cloud_device_list_->Start(make_scoped_ptr<GCDApiFlowInterface::Request>(
+ new CloudDeviceList(this)));
+ }
CheckListingDone();
}
@@ -310,16 +313,16 @@ void LocalDiscoveryUIHandler::OnPrivetRegisterClaimToken(
return;
}
- confirm_api_call_flow_ = CreateApiFlow(
- scoped_ptr<GCDApiFlow::Request>(new PrivetConfirmApiCallFlow(
- token,
- base::Bind(&LocalDiscoveryUIHandler::OnConfirmDone,
- base::Unretained(this)))));
+ confirm_api_call_flow_ = CreateApiFlow();
if (!confirm_api_call_flow_) {
SendRegisterError();
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(
@@ -480,7 +483,7 @@ std::string LocalDiscoveryUIHandler::GetSyncAccount() {
// TODO(noamsml): Create master object for registration flow.
void LocalDiscoveryUIHandler::ResetCurrentRegistration() {
- if (current_register_operation_.get()) {
+ if (current_register_operation_) {
current_register_operation_->Cancel();
current_register_operation_.reset();
}
@@ -528,24 +531,22 @@ void LocalDiscoveryUIHandler::CheckListingDone() {
cloud_device_list_.reset();
}
-scoped_ptr<GCDApiFlow> LocalDiscoveryUIHandler::CreateApiFlow(
- scoped_ptr<GCDApiFlow::Request> request) {
+scoped_ptr<GCDApiFlowInterface> LocalDiscoveryUIHandler::CreateApiFlow() {
Profile* profile = Profile::FromWebUI(web_ui());
if (!profile)
- return scoped_ptr<GCDApiFlow>();
+ return scoped_ptr<GCDApiFlowInterface>();
ProfileOAuth2TokenService* token_service =
ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
if (!token_service)
- return scoped_ptr<GCDApiFlow>();
+ return scoped_ptr<GCDApiFlowInterface>();
SigninManagerBase* signin_manager =
SigninManagerFactory::GetInstance()->GetForProfile(profile);
if (!signin_manager)
- return scoped_ptr<GCDApiFlow>();
- return make_scoped_ptr(
+ return scoped_ptr<GCDApiFlowInterface>();
+ return make_scoped_ptr<GCDApiFlowInterface>(
new GCDApiFlow(profile->GetRequestContext(),
token_service,
- signin_manager->GetAuthenticatedAccountId(),
- request.Pass()));
+ signin_manager->GetAuthenticatedAccountId()));
}
#if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
diff --git a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h
index e2577be..8d25f36 100644
--- a/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h
+++ b/chrome/browser/ui/webui/local_discovery/local_discovery_ui_handler.h
@@ -52,20 +52,17 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// WebUIMessageHandler implementation.
virtual void RegisterMessages() OVERRIDE;
-
// PrivetRegisterOperation::Delegate implementation.
virtual void OnPrivetRegisterClaimToken(
PrivetRegisterOperation* operation,
const std::string& token,
const GURL& url) OVERRIDE;
-
virtual void OnPrivetRegisterError(
PrivetRegisterOperation* operation,
const std::string& action,
PrivetRegisterOperation::FailureReason reason,
int printer_http_code,
const base::DictionaryValue* json) OVERRIDE;
-
virtual void OnPrivetRegisterDone(
PrivetRegisterOperation* operation,
const std::string& device_id) OVERRIDE;
@@ -74,9 +71,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
virtual void DeviceChanged(bool added,
const std::string& name,
const DeviceDescription& description) OVERRIDE;
-
virtual void DeviceRemoved(const std::string& name) OVERRIDE;
-
virtual void DeviceCacheFlushed() OVERRIDE;
// CloudDeviceListDelegate implementation.
@@ -86,7 +81,6 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// SigninManagerBase::Observer implementation.
virtual void GoogleSigninSucceeded(const std::string& username,
const std::string& password) OVERRIDE;
-
virtual void GoogleSignedOut(const std::string& username) OVERRIDE;
private:
@@ -120,7 +114,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// For when the confirm operation on the cloudprint server has finished
// executing.
- void OnConfirmDone(GCDApiFlow::Status status);
+ void OnConfirmDone(GCDApiFlowInterface::Status status);
// Signal to the web interface an error has ocurred while registering.
void SendRegisterError();
@@ -147,7 +141,7 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
void CheckListingDone();
- scoped_ptr<GCDApiFlow> CreateApiFlow(scoped_ptr<GCDApiFlow::Request> request);
+ scoped_ptr<GCDApiFlowInterface> CreateApiFlow();
#if defined(CLOUD_PRINT_CONNECTOR_UI_AVAILABLE)
void StartCloudPrintConnector();
@@ -166,17 +160,8 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
const wifi::BootstrappingDeviceDescription& description);
#endif
- // The current HTTP client (used for the current operation).
- 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<GCDApiFlow> confirm_api_call_flow_;
-
- // The device lister used to list devices on the local network.
- scoped_ptr<PrivetDeviceLister> privet_lister_;
+ // A map of current device descriptions provided by the PrivetDeviceLister.
+ DeviceDescriptionMap device_descriptions_;
// The service discovery client used listen for devices on the local network.
scoped_refptr<ServiceDiscoverySharedClient> service_discovery_client_;
@@ -187,15 +172,24 @@ class LocalDiscoveryUIHandler : public content::WebUIMessageHandler,
// An object representing the resolution process for the privet_http_factory.
scoped_ptr<PrivetHTTPResolution> privet_resolution_;
- // A map of current device descriptions provided by the PrivetDeviceLister.
- DeviceDescriptionMap device_descriptions_;
+ // The current HTTP client (used for the current operation).
+ 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.
bool is_visible_;
// List of printers from cloud print.
- scoped_ptr<GCDApiFlow> cloud_print_printer_list_;
- scoped_ptr<GCDApiFlow> cloud_device_list_;
+ scoped_ptr<GCDApiFlowInterface> cloud_print_printer_list_;
+ scoped_ptr<GCDApiFlowInterface> cloud_device_list_;
std::vector<Device> cloud_devices_;
int failed_list_count_;
int succeded_list_count_;