summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-07 15:54:34 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-07 15:54:34 +0000
commitf992db079eab5fcedf9d196719264df71c1106a9 (patch)
treea86d5b0b07e0d71a85ea4cae6b7933b4766474fc
parent56611cb43a4d4fc5eba3a07dec1c91321ecadd0c (diff)
downloadchromium_src-f992db079eab5fcedf9d196719264df71c1106a9.zip
chromium_src-f992db079eab5fcedf9d196719264df71c1106a9.tar.gz
chromium_src-f992db079eab5fcedf9d196719264df71c1106a9.tar.bz2
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
-rw-r--r--chrome/browser/drive/drive_api_service.cc18
-rw-r--r--chrome/browser/drive/drive_api_util.cc3
-rw-r--r--chrome/browser/drive/drive_api_util.h14
-rw-r--r--google_apis/drive/auth_service.cc48
-rw-r--r--google_apis/drive/base_requests.cc7
-rw-r--r--google_apis/drive/drive_api_parser.cc9
-rw-r--r--google_apis/drive/drive_api_parser_unittest.cc1
-rw-r--r--google_apis/drive/gdata_wapi_parser_unittest.cc2
8 files changed, 35 insertions, 67 deletions
diff --git a/chrome/browser/drive/drive_api_service.cc b/chrome/browser/drive/drive_api_service.cc
index 7fcb570..e2f42be 100644
--- a/chrome/browser/drive/drive_api_service.cc
+++ b/chrome/browser/drive/drive_api_service.cc
@@ -78,6 +78,8 @@ namespace {
const char kDriveScope[] = "https://www.googleapis.com/auth/drive";
const char kDriveAppsReadonlyScope[] =
"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.
const char kFolderMimeType[] = "application/vnd.google-apps.folder";
@@ -196,10 +198,12 @@ void DriveAPIService::Initialize(const std::string& account_id) {
std::vector<std::string> scopes;
scopes.push_back(kDriveScope);
scopes.push_back(kDriveAppsReadonlyScope);
- scopes.push_back(util::kDriveAppsScope);
+ scopes.push_back(kDriveAppsScope);
- // GData WAPI token for GetShareUrl().
- scopes.push_back(util::kDocsListScope);
+ // Note: The following scope is 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.
+ scopes.push_back(kDocsListScope);
sender_.reset(new RequestSender(
new google_apis::AuthService(oauth2_token_service_,
@@ -262,7 +266,7 @@ CancelCallback DriveAPIService::GetFileListInDirectory(
request->set_max_results(kMaxNumFilesResourcePerRequest);
request->set_q(base::StringPrintf(
"'%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);
return sender_->StartRequestWithRetry(request);
}
@@ -277,7 +281,7 @@ CancelCallback DriveAPIService::Search(
FilesListRequest* request = new FilesListRequest(
sender_.get(), url_generator_, callback);
request->set_max_results(kMaxNumFilesResourcePerRequestForSearch);
- request->set_q(drive::util::TranslateQuery(search_query));
+ request->set_q(util::TranslateQuery(search_query));
request->set_fields(kFileListFields);
return sender_->StartRequestWithRetry(request);
}
@@ -292,11 +296,11 @@ CancelCallback DriveAPIService::SearchByTitle(
std::string query;
base::StringAppendF(&query, "title = '%s'",
- drive::util::EscapeQueryStringValue(title).c_str());
+ util::EscapeQueryStringValue(title).c_str());
if (!directory_resource_id.empty()) {
base::StringAppendF(
&query, " and '%s' in parents",
- drive::util::EscapeQueryStringValue(directory_resource_id).c_str());
+ util::EscapeQueryStringValue(directory_resource_id).c_str());
}
query += " and trashed = false";
diff --git a/chrome/browser/drive/drive_api_util.cc b/chrome/browser/drive/drive_api_util.cc
index 9359c37..0fe163f 100644
--- a/chrome/browser/drive/drive_api_util.cc
+++ b/chrome/browser/drive/drive_api_util.cc
@@ -136,9 +136,6 @@ std::string CanonicalizeResourceId(const std::string& 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>
ConvertFileResourceToResourceEntry(
const google_apis::FileResource& file_resource) {
diff --git a/chrome/browser/drive/drive_api_util.h b/chrome/browser/drive/drive_api_util.h
index 90f8820..69f30bb 100644
--- a/chrome/browser/drive/drive_api_util.h
+++ b/chrome/browser/drive/drive_api_util.h
@@ -19,11 +19,8 @@ class Value;
} // namespace base
namespace google_apis {
-class AppList;
-class AppResource;
class ChangeList;
class ChangeResource;
-class DriveAppIcon;
class FileList;
class FileResource;
class ResourceEntry;
@@ -66,17 +63,6 @@ std::string ExtractResourceIdFromUrl(const GURL& url);
// into the new format.
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.
scoped_ptr<google_apis::ResourceEntry>
ConvertFileResourceToResourceEntry(
diff --git a/google_apis/drive/auth_service.cc b/google_apis/drive/auth_service.cc
index 51229f9..0ab8fdf 100644
--- a/google_apis/drive/auth_service.cc
+++ b/google_apis/drive/auth_service.cc
@@ -9,7 +9,7 @@
#include "base/bind.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 "google_apis/drive/auth_service_observer.h"
#include "google_apis/gaia/google_service_auth_error.h"
@@ -27,6 +27,12 @@ const int kSuccessRatioHistogramNoConnection = 2;
const int kSuccessRatioHistogramTemporaryFailure = 3;
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.
class AuthRequest : public OAuth2TokenService::Consumer {
public:
@@ -78,10 +84,7 @@ void AuthRequest::OnGetTokenSuccess(const OAuth2TokenService::Request* request,
const base::Time& expiration_time) {
DCHECK(thread_checker_.CalledOnValidThread());
- UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
- kSuccessRatioHistogramSuccess,
- kSuccessRatioHistogramMaxValue);
-
+ RecordAuthResultHistogram(kSuccessRatioHistogramSuccess);
callback_.Run(HTTP_SUCCESS, access_token);
delete this;
}
@@ -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
// so that the file manager works while off-line.
if (error.state() == GoogleServiceAuthError::CONNECTION_FAILED) {
- UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
- kSuccessRatioHistogramNoConnection,
- kSuccessRatioHistogramMaxValue);
+ RecordAuthResultHistogram(kSuccessRatioHistogramNoConnection);
callback_.Run(GDATA_NO_CONNECTION, std::string());
} else if (error.state() == GoogleServiceAuthError::SERVICE_UNAVAILABLE) {
- // Temporary auth error.
- UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
- kSuccessRatioHistogramTemporaryFailure,
- kSuccessRatioHistogramMaxValue);
+ RecordAuthResultHistogram(kSuccessRatioHistogramTemporaryFailure);
callback_.Run(HTTP_FORBIDDEN, std::string());
} else {
// Permanent auth error.
- UMA_HISTOGRAM_ENUMERATION("GData.AuthSuccess",
- kSuccessRatioHistogramFailure,
- kSuccessRatioHistogramMaxValue);
+ RecordAuthResultHistogram(kSuccessRatioHistogramFailure);
callback_.Run(HTTP_UNAUTHORIZED, std::string());
}
delete this;
@@ -144,13 +140,11 @@ AuthService::~AuthService() {
void AuthService::StartAuthentication(const AuthStatusCallback& callback) {
DCHECK(thread_checker_.CalledOnValidThread());
- scoped_refptr<base::MessageLoopProxy> relay_proxy(
- base::MessageLoopProxy::current());
if (HasAccessToken()) {
// We already have access token. Give it back to the caller asynchronously.
- relay_proxy->PostTask(FROM_HERE,
- base::Bind(callback, HTTP_SUCCESS, access_token_));
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, HTTP_SUCCESS, access_token_));
} else if (HasRefreshToken()) {
// We have refresh token, let's get an access token.
new AuthRequest(oauth2_token_service_,
@@ -161,8 +155,8 @@ void AuthService::StartAuthentication(const AuthStatusCallback& callback) {
callback),
scopes_);
} else {
- relay_proxy->PostTask(FROM_HERE,
- base::Bind(callback, GDATA_NOT_READY, std::string()));
+ base::MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, GDATA_NOT_READY, std::string()));
}
}
@@ -183,11 +177,7 @@ void AuthService::ClearAccessToken() {
}
void AuthService::ClearRefreshToken() {
- has_refresh_token_ = false;
-
- FOR_EACH_OBSERVER(AuthServiceObserver,
- observers_,
- OnOAuth2RefreshTokenChanged());
+ OnHandleRefreshToken(false);
}
void AuthService::OnAuthCompleted(const AuthStatusCallback& callback,
@@ -221,11 +211,13 @@ void AuthService::RemoveObserver(AuthServiceObserver* observer) {
}
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) {
- OnHandleRefreshToken(false);
+ if (account_id == account_id_)
+ OnHandleRefreshToken(false);
}
void AuthService::OnHandleRefreshToken(bool has_refresh_token) {
diff --git a/google_apis/drive/base_requests.cc b/google_apis/drive/base_requests.cc
index 0b2f5e0..fe058fe 100644
--- a/google_apis/drive/base_requests.cc
+++ b/google_apis/drive/base_requests.cc
@@ -59,8 +59,7 @@ void ParseJsonOnBlockingPool(
// Returns response headers as a string. Returns a warning message if
// |url_fetcher| does not contain a valid response. Used only for debugging.
-std::string GetResponseHeadersAsString(
- const URLFetcher* url_fetcher) {
+std::string GetResponseHeadersAsString(const URLFetcher* url_fetcher) {
// net::HttpResponseHeaders::raw_headers(), as the name implies, stores
// 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
@@ -190,6 +189,7 @@ void ResponseWriter::DidWrite(scoped_refptr<net::IOBuffer> buffer,
UrlFetchRequestBase::UrlFetchRequestBase(RequestSender* sender)
: re_authenticate_count_(0),
+ response_writer_(NULL),
sender_(sender),
error_code_(GDATA_OTHER_ERROR),
weak_ptr_factory_(this) {
@@ -218,8 +218,7 @@ void UrlFetchRequestBase::Start(const std::string& access_token,
DVLOG(1) << "URL: " << url.spec();
URLFetcher::RequestType request_type = GetRequestType();
- url_fetcher_.reset(
- URLFetcher::Create(url, request_type, this));
+ url_fetcher_.reset(URLFetcher::Create(url, request_type, this));
url_fetcher_->SetRequestContext(sender_->url_request_context_getter());
// Always set flags to neither send nor save cookies.
url_fetcher_->SetLoadFlags(
diff --git a/google_apis/drive/drive_api_parser.cc b/google_apis/drive/drive_api_parser.cc
index 89c6a9e..998fb05 100644
--- a/google_apis/drive/drive_api_parser.cc
+++ b/google_apis/drive/drive_api_parser.cc
@@ -4,10 +4,7 @@
#include "google_apis/drive/drive_api_parser.h"
-#include <algorithm>
-
#include "base/basictypes.h"
-#include "base/files/file_path.h"
#include "base/json/json_value_converter.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h"
@@ -16,10 +13,6 @@
#include "base/values.h"
#include "google_apis/drive/time_util.h"
-using base::Value;
-using base::DictionaryValue;
-using base::ListValue;
-
namespace google_apis {
namespace {
@@ -75,7 +68,7 @@ bool GetOpenWithLinksFromDictionaryValue(
return false;
result->reserve(dictionary_value->size());
- for (DictionaryValue::Iterator iter(*dictionary_value);
+ for (base::DictionaryValue::Iterator iter(*dictionary_value);
!iter.IsAtEnd(); iter.Advance()) {
std::string string_value;
if (!iter.value().GetAsString(&string_value))
diff --git a/google_apis/drive/drive_api_parser_unittest.cc b/google_apis/drive/drive_api_parser_unittest.cc
index 86fc482..c1d49b8 100644
--- a/google_apis/drive/drive_api_parser_unittest.cc
+++ b/google_apis/drive/drive_api_parser_unittest.cc
@@ -6,7 +6,6 @@
#include "base/time/time.h"
#include "base/values.h"
-#include "google_apis/drive/gdata_wapi_parser.h"
#include "google_apis/drive/test_util.h"
#include "google_apis/drive/time_util.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/google_apis/drive/gdata_wapi_parser_unittest.cc b/google_apis/drive/gdata_wapi_parser_unittest.cc
index 8f14d92..fd15a95 100644
--- a/google_apis/drive/gdata_wapi_parser_unittest.cc
+++ b/google_apis/drive/gdata_wapi_parser_unittest.cc
@@ -6,9 +6,7 @@
#include <string>
-#include "base/files/file_path.h"
#include "base/json/json_file_value_serializer.h"
-#include "base/logging.h"
#include "base/time/time.h"
#include "base/values.h"
#include "google_apis/drive/test_util.h"