Revert 194782 "Native api to get OAuth2 access tokens in Print P..."

> Native api to get OAuth2 access tokens in Print Preview Web UI.
> 
> BUG=179229
> 
> Review URL: https://chromiumcodereview.appspot.com/14093016

TBR=vitalybuka@chromium.org
Review URL: https://codereview.chromium.org/13898008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194803 0039d316-1c4b-4281-b951-d872f2087c98
parent fc54a875
......@@ -39,7 +39,6 @@ cr.define('print_preview', function() {
global['updatePrintPreview'] = this.onUpdatePrintPreview_.bind(this);
global['printScalingDisabledForSourcePDF'] =
this.onPrintScalingDisabledForSourcePDF_.bind(this);
global['onDidGetAccessToken'] = this.onDidGetAccessToken_.bind(this);
};
/**
......@@ -48,7 +47,6 @@ cr.define('print_preview', function() {
* @const
*/
NativeLayer.EventType = {
ACCESS_TOKEN_READY: 'print_preview.NativeLayer.ACCESS_TOKEN_READY',
CAPABILITIES_SET: 'print_preview.NativeLayer.CAPABILITIES_SET',
CLOUD_PRINT_ENABLE: 'print_preview.NativeLayer.CLOUD_PRINT_ENABLE',
DESTINATIONS_RELOAD: 'print_preview.NativeLayer.DESTINATIONS_RELOAD',
......@@ -102,14 +100,6 @@ cr.define('print_preview', function() {
NativeLayer.prototype = {
__proto__: cr.EventTarget.prototype,
/**
* Requests access token for cloud print requests.
* @param {string} authType type of access token.
*/
startGetAccessToken: function(authType) {
chrome.send('getAccessToken', [authType]);
},
/** Gets the initial settings to initialize the print preview with. */
startGetInitialSettings: function() {
chrome.send('getInitialSettings');
......@@ -529,20 +519,6 @@ cr.define('print_preview', function() {
this.dispatchEvent(pagePreviewGenEvent);
},
/**
* Notification that access token is ready.
* @param {string} authType Type of access token.
* @param {string} accessToken Access token.
* @private
*/
onDidGetAccessToken_: function(authType, accessToken) {
var getAccessTokenEvent = new cr.Event(
NativeLayer.EventType.ACCESS_TOKEN_READY);
getAccessTokenEvent.authType = authType;
getAccessTokenEvent.accessToken = accessToken;
this.dispatchEvent(getAccessTokenEvent);
},
/**
* Update the print preview when new preview data is available.
* Create the PDF plugin as needed.
......
......@@ -35,8 +35,6 @@
#include "chrome/browser/printing/print_view_manager.h"
#include "chrome/browser/printing/printer_manager_dialog.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/oauth2_token_service.h"
#include "chrome/browser/signin/oauth2_token_service_factory.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
......@@ -78,9 +76,6 @@ using printing::Metafile;
namespace {
// The cloud print OAuth2 scope.
const char kCloudPrintAuth[] = "https://www.googleapis.com/auth/cloudprint";
enum UserActionBuckets {
PRINT_TO_PRINTER,
PRINT_TO_PDF,
......@@ -241,77 +236,6 @@ static base::LazyInstance<printing::StickySettings> sticky_settings =
} // namespace
class PrintPreviewHandler::AccessTokenService
: public OAuth2TokenService::Consumer {
public:
typedef const base::Callback<void(const std::string&,
const std::string&)> CompleteonCallback;
explicit AccessTokenService(const CompleteonCallback& callback)
: callback_(callback) {
}
void AddOAuth2TokenService(const std::string& type,
OAuth2TokenService* service) {
services_.push_back(make_linked_ptr(new Service()));
services_.back()->type = type;
services_.back()->service = service;
}
void RequestToken(const std::string& type) {
for (Services::iterator i = services_.begin();
i != services_.end(); ++i) {
Service& service = **i;
if (service.type == type) {
if (service.request) // Already in progress.
return;
OAuth2TokenService::ScopeSet oauth_scopes;
oauth_scopes.insert(kCloudPrintAuth);
service.request = service.service->StartRequest(oauth_scopes, this);
return;
}
}
callback_.Run(type, std::string()); // Unknown type.
}
void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const std::string& access_token,
const base::Time& expiration_time) OVERRIDE {
OnServiceResponce(request, access_token);
}
void OnGetTokenFailure(const OAuth2TokenService::Request* request,
const GoogleServiceAuthError& error) OVERRIDE {
OnServiceResponce(request, std::string());
}
private:
void OnServiceResponce(const OAuth2TokenService::Request* request,
const std::string& access_token) {
for (Services::iterator i = services_.begin();
i != services_.end(); ++i) {
Service& service = **i;
if (service.request == request) {
service.request.reset();
callback_.Run(service.type, access_token);
return;
}
}
NOTREACHED();
}
struct Service {
std::string type;
OAuth2TokenService* service;
scoped_ptr<OAuth2TokenService::Request> request;
};
typedef std::vector<linked_ptr<Service> > Services;
Services services_;
CompleteonCallback callback_;
DISALLOW_COPY_AND_ASSIGN(AccessTokenService);
};
// static
printing::StickySettings* PrintPreviewHandler::GetStickySettings() {
return sticky_settings.Pointer();
......@@ -351,9 +275,6 @@ void PrintPreviewHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback("signIn",
base::Bind(&PrintPreviewHandler::HandleSignin,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("getAccessToken",
base::Bind(&PrintPreviewHandler::HandleGetAccessToken,
base::Unretained(this)));
web_ui()->RegisterMessageCallback("manageCloudPrinters",
base::Bind(&PrintPreviewHandler::HandleManageCloudPrint,
base::Unretained(this)));
......@@ -664,29 +585,6 @@ void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) {
base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr()));
}
void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) {
std::string type;
if (!args->GetString(0, &type))
return;
if (!token_service_)
InitTokenService();
token_service_->RequestToken(type);
}
void PrintPreviewHandler::InitTokenService() {
token_service_.reset(
new AccessTokenService(base::Bind(&PrintPreviewHandler::SendAccessToken,
base::Unretained(this))));
Profile* profile = Profile::FromWebUI(web_ui());
OAuth2TokenService* profile_service =
OAuth2TokenServiceFactory::GetForProfile(profile);
if (profile_service) {
token_service_->AddOAuth2TokenService("profile", profile_service);
// TODO(vitalybuka): Replace with source of device tokens.
token_service_->AddOAuth2TokenService("device", profile_service);
}
}
void PrintPreviewHandler::PrintWithCloudPrintDialog(
const base::RefCountedBytes* data,
const string16& title) {
......@@ -885,13 +783,6 @@ void PrintPreviewHandler::ClosePreviewDialog() {
print_preview_ui->OnClosePrintPreviewDialog();
}
void PrintPreviewHandler::SendAccessToken(const std::string& type,
const std::string& access_token) {
VLOG(1) << "Get getAccessToken finished";
web_ui()->CallJavascriptFunction("onDidGetAccessToken", StringValue(type),
StringValue(access_token));
}
void PrintPreviewHandler::SendPrinterCapabilities(
const DictionaryValue& settings_info) {
VLOG(1) << "Get printer capabilities finished";
......
......@@ -115,9 +115,6 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
// |args| is unused.
void HandleSignin(const base::ListValue* args);
// Generates new token and sends back to UI.
void HandleGetAccessToken(const base::ListValue* args);
// Brings up a web page to allow the user to configure cloud print.
// |args| is unused.
void HandleManageCloudPrint(const base::ListValue* args);
......@@ -154,10 +151,6 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
const std::string& default_printer,
const std::string& cloud_print_data);
// Send OAuth2 access token.
void SendAccessToken(const std::string& type,
const std::string& access_token);
// Sends the printer capabilities to the Web UI. |settings_info| contains
// printer capabilities information.
void SendPrinterCapabilities(const base::DictionaryValue& settings_info);
......@@ -205,8 +198,6 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
bool GetPreviewDataAndTitle(scoped_refptr<base::RefCountedBytes>* data,
string16* title) const;
void InitTokenService();
// Pointer to current print system.
scoped_refptr<printing::PrintBackend> print_backend_;
......@@ -231,10 +222,6 @@ class PrintPreviewHandler : public content::WebUIMessageHandler,
// exists.
scoped_ptr<base::FilePath> print_to_pdf_path_;
// Holds token service to get OAuth2 access tokens.
class AccessTokenService;
scoped_ptr<AccessTokenService> token_service_;
DISALLOW_COPY_AND_ASSIGN(PrintPreviewHandler);
};
......
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