Commit f992db07 authored by kinaba@chromium.org's avatar kinaba@chromium.org

Random cleanup around google_apis/drive and c/b/drive.

BUG=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288058 0039d316-1c4b-4281-b951-d872f2087c98
parent 56611cb4
...@@ -78,6 +78,8 @@ namespace { ...@@ -78,6 +78,8 @@ namespace {
const char kDriveScope[] = "https://www.googleapis.com/auth/drive"; const char kDriveScope[] = "https://www.googleapis.com/auth/drive";
const char kDriveAppsReadonlyScope[] = const char kDriveAppsReadonlyScope[] =
"https://www.googleapis.com/auth/drive.apps.readonly"; "https://www.googleapis.com/auth/drive.apps.readonly";
const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps";
const char kDocsListScope[] = "https://docs.google.com/feeds/";
// Mime type to create a directory. // Mime type to create a directory.
const char kFolderMimeType[] = "application/vnd.google-apps.folder"; const char kFolderMimeType[] = "application/vnd.google-apps.folder";
...@@ -196,10 +198,12 @@ void DriveAPIService::Initialize(const std::string& account_id) { ...@@ -196,10 +198,12 @@ void DriveAPIService::Initialize(const std::string& account_id) {
std::vector<std::string> scopes; std::vector<std::string> scopes;
scopes.push_back(kDriveScope); scopes.push_back(kDriveScope);
scopes.push_back(kDriveAppsReadonlyScope); scopes.push_back(kDriveAppsReadonlyScope);
scopes.push_back(util::kDriveAppsScope); scopes.push_back(kDriveAppsScope);
// GData WAPI token for GetShareUrl(). // Note: The following scope is used to support GetShareUrl on Drive API v2.
scopes.push_back(util::kDocsListScope); // Unfortunately, there is no support on Drive API v2, so we need to fall back
// to GData WAPI for the GetShareUrl.
scopes.push_back(kDocsListScope);
sender_.reset(new RequestSender( sender_.reset(new RequestSender(
new google_apis::AuthService(oauth2_token_service_, new google_apis::AuthService(oauth2_token_service_,
...@@ -262,7 +266,7 @@ CancelCallback DriveAPIService::GetFileListInDirectory( ...@@ -262,7 +266,7 @@ CancelCallback DriveAPIService::GetFileListInDirectory(
request->set_max_results(kMaxNumFilesResourcePerRequest); request->set_max_results(kMaxNumFilesResourcePerRequest);
request->set_q(base::StringPrintf( request->set_q(base::StringPrintf(
"'%s' in parents and trashed = false", "'%s' in parents and trashed = false",
drive::util::EscapeQueryStringValue(directory_resource_id).c_str())); util::EscapeQueryStringValue(directory_resource_id).c_str()));
request->set_fields(kFileListFields); request->set_fields(kFileListFields);
return sender_->StartRequestWithRetry(request); return sender_->StartRequestWithRetry(request);
} }
...@@ -277,7 +281,7 @@ CancelCallback DriveAPIService::Search( ...@@ -277,7 +281,7 @@ CancelCallback DriveAPIService::Search(
FilesListRequest* request = new FilesListRequest( FilesListRequest* request = new FilesListRequest(
sender_.get(), url_generator_, callback); sender_.get(), url_generator_, callback);
request->set_max_results(kMaxNumFilesResourcePerRequestForSearch); request->set_max_results(kMaxNumFilesResourcePerRequestForSearch);
request->set_q(drive::util::TranslateQuery(search_query)); request->set_q(util::TranslateQuery(search_query));
request->set_fields(kFileListFields); request->set_fields(kFileListFields);
return sender_->StartRequestWithRetry(request); return sender_->StartRequestWithRetry(request);
} }
...@@ -292,11 +296,11 @@ CancelCallback DriveAPIService::SearchByTitle( ...@@ -292,11 +296,11 @@ CancelCallback DriveAPIService::SearchByTitle(
std::string query; std::string query;
base::StringAppendF(&query, "title = '%s'", base::StringAppendF(&query, "title = '%s'",
drive::util::EscapeQueryStringValue(title).c_str()); util::EscapeQueryStringValue(title).c_str());
if (!directory_resource_id.empty()) { if (!directory_resource_id.empty()) {
base::StringAppendF( base::StringAppendF(
&query, " and '%s' in parents", &query, " and '%s' in parents",
drive::util::EscapeQueryStringValue(directory_resource_id).c_str()); util::EscapeQueryStringValue(directory_resource_id).c_str());
} }
query += " and trashed = false"; query += " and trashed = false";
......
...@@ -136,9 +136,6 @@ std::string CanonicalizeResourceId(const std::string& resource_id) { ...@@ -136,9 +136,6 @@ std::string CanonicalizeResourceId(const std::string& resource_id) {
return resource_id; return resource_id;
} }
const char kDocsListScope[] = "https://docs.google.com/feeds/";
const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps";
scoped_ptr<google_apis::ResourceEntry> scoped_ptr<google_apis::ResourceEntry>
ConvertFileResourceToResourceEntry( ConvertFileResourceToResourceEntry(
const google_apis::FileResource& file_resource) { const google_apis::FileResource& file_resource) {
......
...@@ -19,11 +19,8 @@ class Value; ...@@ -19,11 +19,8 @@ class Value;
} // namespace base } // namespace base
namespace google_apis { namespace google_apis {
class AppList;
class AppResource;
class ChangeList; class ChangeList;
class ChangeResource; class ChangeResource;
class DriveAppIcon;
class FileList; class FileList;
class FileResource; class FileResource;
class ResourceEntry; class ResourceEntry;
...@@ -66,17 +63,6 @@ std::string ExtractResourceIdFromUrl(const GURL& url); ...@@ -66,17 +63,6 @@ std::string ExtractResourceIdFromUrl(const GURL& url);
// into the new format. // into the new format.
std::string CanonicalizeResourceId(const std::string& resource_id); std::string CanonicalizeResourceId(const std::string& resource_id);
// Note: Following constants and a function are used to support GetShareUrl on
// Drive API v2. Unfortunately, there is no support on Drive API v2, so we need
// to fall back to GData WAPI for the GetShareUrl. Thus, these are shared by
// both GDataWapiService and DriveAPIService.
// TODO(hidehiko): Remove these from here, when Drive API v2 supports
// GetShareUrl.
// OAuth2 scopes for the GData WAPI.
extern const char kDocsListScope[];
extern const char kDriveAppsScope[];
// Converts FileResource to ResourceEntry. // Converts FileResource to ResourceEntry.
scoped_ptr<google_apis::ResourceEntry> scoped_ptr<google_apis::ResourceEntry>
ConvertFileResourceToResourceEntry( ConvertFileResourceToResourceEntry(
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/message_loop/message_loop_proxy.h" #include "base/message_loop/message_loop.h"
#include "base/metrics/histogram.h" #include "base/metrics/histogram.h"
#include "google_apis/drive/auth_service_observer.h" #include "google_apis/drive/auth_service_observer.h"
#include "google_apis/gaia/google_service_auth_error.h" #include "google_apis/gaia/google_service_auth_error.h"
...@@ -27,6 +27,12 @@ const int kSuccessRatioHistogramNoConnection = 2; ...@@ -27,6 +27,12 @@ const int kSuccessRatioHistogramNoConnection = 2;
const int kSuccessRatioHistogramTemporaryFailure = 3; const int kSuccessRatioHistogramTemporaryFailure = 3;
const int kSuccessRatioHistogramMaxValue = 4; // The max value is exclusive. const int kSuccessRatioHistogramMaxValue = 4; // The max value is exclusive.
void RecordAuthResultHistogram(int value) {
UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
value,
kSuccessRatioHistogramMaxValue);
}
// OAuth2 authorization token retrieval request. // OAuth2 authorization token retrieval request.
class AuthRequest : public OAuth2TokenService::Consumer { class AuthRequest : public OAuth2TokenService::Consumer {
public: public:
...@@ -78,10 +84,7 @@ void AuthRequest::OnGetTokenSuccess(const OAuth2TokenService::Request* request, ...@@ -78,10 +84,7 @@ void AuthRequest::OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const base::Time& expiration_time) { const base::Time& expiration_time) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", RecordAuthResultHistogram(kSuccessRatioHistogramSuccess);
kSuccessRatioHistogramSuccess,
kSuccessRatioHistogramMaxValue);
callback_.Run(HTTP_SUCCESS, access_token); callback_.Run(HTTP_SUCCESS, access_token);
delete this; delete this;
} }
...@@ -98,21 +101,14 @@ void AuthRequest::OnGetTokenFailure(const OAuth2TokenService::Request* request, ...@@ -98,21 +101,14 @@ void AuthRequest::OnGetTokenFailure(const OAuth2TokenService::Request* request,
// it's likely that the device is off-line. We treat the error differently // it's likely that the device is off-line. We treat the error differently
// so that the file manager works while off-line. // so that the file manager works while off-line.
if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) { if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", RecordAuthResultHistogram(kSuccessRatioHistogramNoConnection);
kSuccessRatioHistogramNoConnection,
kSuccessRatioHistogramMaxValue);
callback_.Run(GDATA_NO_CONNECTION, std::string()); callback_.Run(GDATA_NO_CONNECTION, std::string());
} else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) { } else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
// Temporary auth error. RecordAuthResultHistogram(kSuccessRatioHistogramTemporaryFailure);
UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
kSuccessRatioHistogramTemporaryFailure,
kSuccessRatioHistogramMaxValue);
callback_.Run(HTTP_FORBIDDEN, std::string()); callback_.Run(HTTP_FORBIDDEN, std::string());
} else { } else {
// Permanent auth error. // Permanent auth error.
UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess", RecordAuthResultHistogram(kSuccessRatioHistogramFailure);
kSuccessRatioHistogramFailure,
kSuccessRatioHistogramMaxValue);
callback_.Run(HTTP_UNAUTHORIZED, std::string()); callback_.Run(HTTP_UNAUTHORIZED, std::string());
} }
delete this; delete this;
...@@ -144,13 +140,11 @@ AuthService::~AuthService() { ...@@ -144,13 +140,11 @@ AuthService::~AuthService() {
void AuthService::StartAuthentication(const AuthStatusCallback& callback) { void AuthService::StartAuthentication(const AuthStatusCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
scoped_refptr<base::MessageLoopProxy> relay_proxy(
base::MessageLoopProxy::current());
if (HasAccessToken()) { if (HasAccessToken()) {
// We already have access token. Give it back to the caller asynchronously. // We already have access token. Give it back to the caller asynchronously.
relay_proxy->PostTask(FROM_HERE, base::MessageLoop::current()->PostTask(
base::Bind(callback, HTTP_SUCCESS, access_token_)); FROM_HERE, base::Bind(callback, HTTP_SUCCESS, access_token_));
} else if (HasRefreshToken()) { } else if (HasRefreshToken()) {
// We have refresh token, let's get an access token. // We have refresh token, let's get an access token.
new AuthRequest(oauth2_token_service_, new AuthRequest(oauth2_token_service_,
...@@ -161,8 +155,8 @@ void AuthService::StartAuthentication(const AuthStatusCallback& callback) { ...@@ -161,8 +155,8 @@ void AuthService::StartAuthentication(const AuthStatusCallback& callback) {
callback), callback),
scopes_); scopes_);
} else { } else {
relay_proxy->PostTask(FROM_HERE, base::MessageLoop::current()->PostTask(
base::Bind(callback, GDATA_NOT_READY, std::string())); FROM_HERE, base::Bind(callback, GDATA_NOT_READY, std::string()));
} }
} }
...@@ -183,11 +177,7 @@ void AuthService::ClearAccessToken() { ...@@ -183,11 +177,7 @@ void AuthService::ClearAccessToken() {
} }
void AuthService::ClearRefreshToken() { void AuthService::ClearRefreshToken() {
has_refresh_token_ = false; OnHandleRefreshToken(false);
FOR_EACH_OBSERVER(AuthServiceObserver,
observers_,
OnOAuth2RefreshTokenChanged());
} }
void AuthService::OnAuthCompleted(const AuthStatusCallback& callback, void AuthService::OnAuthCompleted(const AuthStatusCallback& callback,
...@@ -221,11 +211,13 @@ void AuthService::RemoveObserver(AuthServiceObserver* observer) { ...@@ -221,11 +211,13 @@ void AuthService::RemoveObserver(AuthServiceObserver* observer) {
} }
void AuthService::OnRefreshTokenAvailable(const std::string& account_id) { void AuthService::OnRefreshTokenAvailable(const std::string& account_id) {
OnHandleRefreshToken(true); if (account_id == account_id_)
OnHandleRefreshToken(true);
} }
void AuthService::OnRefreshTokenRevoked(const std::string& account_id) { void AuthService::OnRefreshTokenRevoked(const std::string& account_id) {
OnHandleRefreshToken(false); if (account_id == account_id_)
OnHandleRefreshToken(false);
} }
void AuthService::OnHandleRefreshToken(bool has_refresh_token) { void AuthService::OnHandleRefreshToken(bool has_refresh_token) {
......
...@@ -59,8 +59,7 @@ void ParseJsonOnBlockingPool( ...@@ -59,8 +59,7 @@ void ParseJsonOnBlockingPool(
// Returns response headers as a string. Returns a warning message if // Returns response headers as a string. Returns a warning message if
// |url_fetcher| does not contain a valid response. Used only for debugging. // |url_fetcher| does not contain a valid response. Used only for debugging.
std::string GetResponseHeadersAsString( std::string GetResponseHeadersAsString(const URLFetcher* url_fetcher) {
const URLFetcher* url_fetcher) {
// net::HttpResponseHeaders::raw_headers(), as the name implies, stores // net::HttpResponseHeaders::raw_headers(), as the name implies, stores
// all headers in their raw format, i.e each header is null-terminated. // all headers in their raw format, i.e each header is null-terminated.
// So logging raw_headers() only shows the first header, which is probably // So logging raw_headers() only shows the first header, which is probably
...@@ -190,6 +189,7 @@ void ResponseWriter::DidWrite(scoped_refptr<net::IOBuffer> buffer, ...@@ -190,6 +189,7 @@ void ResponseWriter::DidWrite(scoped_refptr<net::IOBuffer> buffer,
UrlFetchRequestBase::UrlFetchRequestBase(RequestSender* sender) UrlFetchRequestBase::UrlFetchRequestBase(RequestSender* sender)
: re_authenticate_count_(0), : re_authenticate_count_(0),
response_writer_(NULL),
sender_(sender), sender_(sender),
error_code_(GDATA_OTHER_ERROR), error_code_(GDATA_OTHER_ERROR),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
...@@ -218,8 +218,7 @@ void UrlFetchRequestBase::Start(const std::string& access_token, ...@@ -218,8 +218,7 @@ void UrlFetchRequestBase::Start(const std::string& access_token,
DVLOG(1) << "URL: " << url.spec(); DVLOG(1) << "URL: " << url.spec();
URLFetcher::RequestType request_type = GetRequestType(); URLFetcher::RequestType request_type = GetRequestType();
url_fetcher_.reset( url_fetcher_.reset(URLFetcher::Create(url, request_type, this));
URLFetcher::Create(url, request_type, this));
url_fetcher_->SetRequestContext(sender_->url_request_context_getter()); url_fetcher_->SetRequestContext(sender_->url_request_context_getter());
// Always set flags to neither send nor save cookies. // Always set flags to neither send nor save cookies.
url_fetcher_->SetLoadFlags( url_fetcher_->SetLoadFlags(
......
...@@ -4,10 +4,7 @@ ...@@ -4,10 +4,7 @@
#include "google_apis/drive/drive_api_parser.h" #include "google_apis/drive/drive_api_parser.h"
#include <algorithm>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/files/file_path.h"
#include "base/json/json_value_converter.h" #include "base/json/json_value_converter.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -16,10 +13,6 @@ ...@@ -16,10 +13,6 @@
#include "base/values.h" #include "base/values.h"
#include "google_apis/drive/time_util.h" #include "google_apis/drive/time_util.h"
using base::Value;
using base::DictionaryValue;
using base::ListValue;
namespace google_apis { namespace google_apis {
namespace { namespace {
...@@ -75,7 +68,7 @@ bool GetOpenWithLinksFromDictionaryValue( ...@@ -75,7 +68,7 @@ bool GetOpenWithLinksFromDictionaryValue(
return false; return false;
result->reserve(dictionary_value->size()); result->reserve(dictionary_value->size());
for (DictionaryValue::Iterator iter(*dictionary_value); for (base::DictionaryValue::Iterator iter(*dictionary_value);
!iter.IsAtEnd(); iter.Advance()) { !iter.IsAtEnd(); iter.Advance()) {
std::string string_value; std::string string_value;
if (!iter.value().GetAsString(&string_value)) if (!iter.value().GetAsString(&string_value))
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "google_apis/drive/gdata_wapi_parser.h"
#include "google_apis/drive/test_util.h" #include "google_apis/drive/test_util.h"
#include "google_apis/drive/time_util.h" #include "google_apis/drive/time_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -6,9 +6,7 @@ ...@@ -6,9 +6,7 @@
#include <string> #include <string>
#include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h" #include "base/json/json_file_value_serializer.h"
#include "base/logging.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h" #include "base/values.h"
#include "google_apis/drive/test_util.h" #include "google_apis/drive/test_util.h"
......
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