Commit 2488c173 authored by kochi@chromium.org's avatar kochi@chromium.org

Add GetChangelist operation for Drive V2.

This CL adds GetChangelist operation and its corresponding interface
for DocumentsService.  No code uses this interface yet.

BUG=chromium:127728
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10836125

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150322 0039d316-1c4b-4281-b951-d872f2087c98
parent 8588582c
......@@ -4,10 +4,15 @@
#include "chrome/browser/chromeos/gdata/drive_api_operations.h"
#include "base/string_number_conversions.h"
#include "chrome/common/net/url_util.h"
namespace {
const char kDriveV2AboutURL[] = "https://www.googleapis.com/drive/v2/about";
const char kDriveV2ApplistURL[] = "https://www.googleapis.com/drive/v2/apps";
const char kDriveV2ChangelistURL[] =
"https://www.googleapis.com/drive/v2/changes";
} // namespace
......@@ -38,4 +43,27 @@ GURL GetApplistOperation::GetURL() const {
return GURL(kDriveV2ApplistURL);
}
//============================ GetChangelistOperation ==========================
GetChangelistOperation::GetChangelistOperation(
GDataOperationRegistry* registry,
const GURL& url,
int64 start_changestamp,
const GetDataCallback& callback)
: GetDataOperation(registry, callback),
url_(kDriveV2ChangelistURL),
start_changestamp_(start_changestamp) {
if (!url.is_empty())
url_ = url;
}
GetChangelistOperation::~GetChangelistOperation() {}
GURL GetChangelistOperation::GetURL() const {
if (start_changestamp_)
return chrome_common_net::AppendOrReplaceQueryParameter(
url_, "startChangeId", base::Int64ToString(start_changestamp_));
return url_;
}
} // namespace gdata
......@@ -47,6 +47,33 @@ class GetApplistOperation : public GetDataOperation {
DISALLOW_COPY_AND_ASSIGN(GetApplistOperation);
};
//============================ GetChangelistOperation ==========================
// This class performs the operation for fetching changelist.
class GetChangelistOperation : public GetDataOperation {
public:
// |start_changestamp| specifies the starting point of change list or 0 if
// all changes are necessary.
// |url| specifies URL for document feed fetching operation. If empty URL is
// passed, the default URL is used and returns the first page of the result.
// When non-first page result is requested, |url| should be specified.
GetChangelistOperation(GDataOperationRegistry* registry,
const GURL& url,
int64 start_changestamp,
const GetDataCallback& callback);
virtual ~GetChangelistOperation();
protected:
// Overridden from GetDataOperation.
virtual GURL GetURL() const OVERRIDE;
private:
GURL url_;
int64 start_changestamp_;
DISALLOW_COPY_AND_ASSIGN(GetChangelistOperation);
};
} // namespace gdata
#endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_OPERATIONS_H_
......@@ -103,12 +103,24 @@ void DocumentsService::GetDocuments(const GURL& url,
GetDocumentsOperation* operation =
new GetDocumentsOperation(operation_registry(),
url,
start_changestamp,
search_query,
directory_resource_id,
callback);
if (!url.is_empty())
operation->SetUrl(url);
runner_->StartOperationWithRetry(operation);
}
void DocumentsService::GetChangelist(const GURL& url,
int64 start_changestamp,
const GetDataCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
GetChangelistOperation* operation =
new GetChangelistOperation(operation_registry(),
url,
start_changestamp,
callback);
runner_->StartOperationWithRetry(operation);
}
......
......@@ -92,6 +92,16 @@ class DocumentsServiceInterface {
const std::string& directory_resource_id,
const GetDataCallback& callback) = 0;
// Fetches a changelist from |url| with |start_changestamp|, using Drive V2
// API. If this URL is empty the call will use the default URL. Specify |url|
// when pagenated request should be issued.
// |start_changestamp| specifies the starting point of change list or 0 if
// all changes are necessary.
// Upon completion, invokes |callback| with results on calling thread.
virtual void GetChangelist(const GURL& url,
int64 start_changestamp,
const GetDataCallback& callback) = 0;
// Fetches single entry metadata from server. The entry's resource id equals
// |resource_id|.
// Upon completion, invokes |callback| with results on the calling thread.
......@@ -219,6 +229,9 @@ class DocumentsService : public DocumentsServiceInterface {
const std::string& search_query,
const std::string& directory_resource_id,
const GetDataCallback& callback) OVERRIDE;
virtual void GetChangelist(const GURL& url,
int64 start_changestamp,
const GetDataCallback& callback) OVERRIDE;
virtual void GetDocumentEntry(const std::string& resource_id,
const GetDataCallback& callback) OVERRIDE;
......
......@@ -155,11 +155,13 @@ namespace gdata {
GetDocumentsOperation::GetDocumentsOperation(
GDataOperationRegistry* registry,
const GURL& url,
int start_changestamp,
const std::string& search_string,
const std::string& directory_resource_id,
const GetDataCallback& callback)
: GetDataOperation(registry, callback),
override_url_(url),
start_changestamp_(start_changestamp),
search_string_(search_string),
directory_resource_id_(directory_resource_id) {
......@@ -167,10 +169,6 @@ GetDocumentsOperation::GetDocumentsOperation(
GetDocumentsOperation::~GetDocumentsOperation() {}
void GetDocumentsOperation::SetUrl(const GURL& url) {
override_url_ = url;
}
GURL GetDocumentsOperation::GetURL() const {
int max_docs = search_string_.empty() ? kMaxDocumentsPerFeed :
kMaxDocumentsPerSearchFeed;
......
......@@ -17,17 +17,19 @@ namespace gdata {
// This class performs the operation for fetching a document list.
class GetDocumentsOperation : public GetDataOperation {
public:
// |start_changestamp| specifies the starting point of change list or 0 if
// all changes are necessary.
// |url| specifies URL for documents feed fetching operation. If empty URL is
// passed, the default URL is used and returns the first page of the result.
// When non-first page result is requested, |url| should be specified.
GetDocumentsOperation(GDataOperationRegistry* registry,
const GURL& url,
int start_changestamp,
const std::string& search_string,
const std::string& directory_resource_id,
const GetDataCallback& callback);
virtual ~GetDocumentsOperation();
// Sets |url| for document fetching operation. This URL should be set in use
// case when additional 'pages' of document lists are being fetched.
void SetUrl(const GURL& url);
protected:
// Overridden from GetDataOperation.
virtual GURL GetURL() const OVERRIDE;
......
......@@ -34,6 +34,9 @@ class MockDocumentsService : public DocumentsServiceInterface {
const std::string& search_string,
const std::string& directory_resource_id,
const GetDataCallback& callback));
MOCK_METHOD3(GetChangelist, void(const GURL& feed_url,
int64 start_changestamp,
const GetDataCallback& callback));
MOCK_METHOD2(GetDocumentEntry, void(const std::string& resource_id,
const GetDataCallback& callback));
MOCK_METHOD1(GetAccountMetadata, void(const GetDataCallback& callback));
......
......@@ -50,7 +50,10 @@ const char kUserContentScope[] = "https://docs.googleusercontent.com/";
const char kContactsScope[] = "https://www.google.com/m8/feeds/";
// OAuth scope for Drive API.
const char kDriveScope[] = "https://www.googleapis.com/auth/drive.file";
const char kDriveAppsScope[] = "https://www.googleapis.com/auth/drive.apps";
const char kDriveAppsReadonlyScope[] =
"https://www.googleapis.com/auth/drive.apps.readonly";
// Parse JSON string to base::Value object.
void ParseJsonOnBlockingPool(const std::string& data,
......@@ -92,12 +95,17 @@ AuthOperation::~AuthOperation() {}
void AuthOperation::Start() {
DCHECK(!refresh_token_.empty());
std::vector<std::string> scopes;
scopes.push_back(kDocsListScope);
scopes.push_back(kSpreadsheetsScope);
scopes.push_back(kUserContentScope);
scopes.push_back(kContactsScope);
// Drive App scope is required for even WAPI v3 apps access.
scopes.push_back(kDriveAppsScope);
if (gdata::util::IsDriveV2ApiEnabled()) {
scopes.push_back(kDriveScope);
scopes.push_back(kDriveAppsReadonlyScope);
} else {
scopes.push_back(kDocsListScope);
scopes.push_back(kSpreadsheetsScope);
scopes.push_back(kUserContentScope);
scopes.push_back(kContactsScope);
// Drive App scope is required for even WAPI v3 apps access.
scopes.push_back(kDriveAppsScope);
}
oauth2_access_token_fetcher_.reset(new OAuth2AccessTokenFetcher(
this, g_browser_process->system_request_context()));
NotifyStart();
......
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