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 @@ ...@@ -4,10 +4,15 @@
#include "chrome/browser/chromeos/gdata/drive_api_operations.h" #include "chrome/browser/chromeos/gdata/drive_api_operations.h"
#include "base/string_number_conversions.h"
#include "chrome/common/net/url_util.h"
namespace { namespace {
const char kDriveV2AboutURL[] = "https://www.googleapis.com/drive/v2/about"; const char kDriveV2AboutURL[] = "https://www.googleapis.com/drive/v2/about";
const char kDriveV2ApplistURL[] = "https://www.googleapis.com/drive/v2/apps"; const char kDriveV2ApplistURL[] = "https://www.googleapis.com/drive/v2/apps";
const char kDriveV2ChangelistURL[] =
"https://www.googleapis.com/drive/v2/changes";
} // namespace } // namespace
...@@ -38,4 +43,27 @@ GURL GetApplistOperation::GetURL() const { ...@@ -38,4 +43,27 @@ GURL GetApplistOperation::GetURL() const {
return GURL(kDriveV2ApplistURL); 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 } // namespace gdata
...@@ -47,6 +47,33 @@ class GetApplistOperation : public GetDataOperation { ...@@ -47,6 +47,33 @@ class GetApplistOperation : public GetDataOperation {
DISALLOW_COPY_AND_ASSIGN(GetApplistOperation); 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 } // namespace gdata
#endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_OPERATIONS_H_ #endif // CHROME_BROWSER_CHROMEOS_GDATA_DRIVE_API_OPERATIONS_H_
...@@ -103,12 +103,24 @@ void DocumentsService::GetDocuments(const GURL& url, ...@@ -103,12 +103,24 @@ void DocumentsService::GetDocuments(const GURL& url,
GetDocumentsOperation* operation = GetDocumentsOperation* operation =
new GetDocumentsOperation(operation_registry(), new GetDocumentsOperation(operation_registry(),
url,
start_changestamp, start_changestamp,
search_query, search_query,
directory_resource_id, directory_resource_id,
callback); callback);
if (!url.is_empty()) runner_->StartOperationWithRetry(operation);
operation->SetUrl(url); }
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); runner_->StartOperationWithRetry(operation);
} }
......
...@@ -92,6 +92,16 @@ class DocumentsServiceInterface { ...@@ -92,6 +92,16 @@ class DocumentsServiceInterface {
const std::string& directory_resource_id, const std::string& directory_resource_id,
const GetDataCallback& callback) = 0; 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 // Fetches single entry metadata from server. The entry's resource id equals
// |resource_id|. // |resource_id|.
// Upon completion, invokes |callback| with results on the calling thread. // Upon completion, invokes |callback| with results on the calling thread.
...@@ -219,6 +229,9 @@ class DocumentsService : public DocumentsServiceInterface { ...@@ -219,6 +229,9 @@ class DocumentsService : public DocumentsServiceInterface {
const std::string& search_query, const std::string& search_query,
const std::string& directory_resource_id, const std::string& directory_resource_id,
const GetDataCallback& callback) OVERRIDE; 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, virtual void GetDocumentEntry(const std::string& resource_id,
const GetDataCallback& callback) OVERRIDE; const GetDataCallback& callback) OVERRIDE;
......
...@@ -155,11 +155,13 @@ namespace gdata { ...@@ -155,11 +155,13 @@ namespace gdata {
GetDocumentsOperation::GetDocumentsOperation( GetDocumentsOperation::GetDocumentsOperation(
GDataOperationRegistry* registry, GDataOperationRegistry* registry,
const GURL& url,
int start_changestamp, int start_changestamp,
const std::string& search_string, const std::string& search_string,
const std::string& directory_resource_id, const std::string& directory_resource_id,
const GetDataCallback& callback) const GetDataCallback& callback)
: GetDataOperation(registry, callback), : GetDataOperation(registry, callback),
override_url_(url),
start_changestamp_(start_changestamp), start_changestamp_(start_changestamp),
search_string_(search_string), search_string_(search_string),
directory_resource_id_(directory_resource_id) { directory_resource_id_(directory_resource_id) {
...@@ -167,10 +169,6 @@ GetDocumentsOperation::GetDocumentsOperation( ...@@ -167,10 +169,6 @@ GetDocumentsOperation::GetDocumentsOperation(
GetDocumentsOperation::~GetDocumentsOperation() {} GetDocumentsOperation::~GetDocumentsOperation() {}
void GetDocumentsOperation::SetUrl(const GURL& url) {
override_url_ = url;
}
GURL GetDocumentsOperation::GetURL() const { GURL GetDocumentsOperation::GetURL() const {
int max_docs = search_string_.empty() ? kMaxDocumentsPerFeed : int max_docs = search_string_.empty() ? kMaxDocumentsPerFeed :
kMaxDocumentsPerSearchFeed; kMaxDocumentsPerSearchFeed;
......
...@@ -17,17 +17,19 @@ namespace gdata { ...@@ -17,17 +17,19 @@ namespace gdata {
// This class performs the operation for fetching a document list. // This class performs the operation for fetching a document list.
class GetDocumentsOperation : public GetDataOperation { class GetDocumentsOperation : public GetDataOperation {
public: 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, GetDocumentsOperation(GDataOperationRegistry* registry,
const GURL& url,
int start_changestamp, int start_changestamp,
const std::string& search_string, const std::string& search_string,
const std::string& directory_resource_id, const std::string& directory_resource_id,
const GetDataCallback& callback); const GetDataCallback& callback);
virtual ~GetDocumentsOperation(); 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: protected:
// Overridden from GetDataOperation. // Overridden from GetDataOperation.
virtual GURL GetURL() const OVERRIDE; virtual GURL GetURL() const OVERRIDE;
......
...@@ -34,6 +34,9 @@ class MockDocumentsService : public DocumentsServiceInterface { ...@@ -34,6 +34,9 @@ class MockDocumentsService : public DocumentsServiceInterface {
const std::string& search_string, const std::string& search_string,
const std::string& directory_resource_id, const std::string& directory_resource_id,
const GetDataCallback& callback)); 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, MOCK_METHOD2(GetDocumentEntry, void(const std::string& resource_id,
const GetDataCallback& callback)); const GetDataCallback& callback));
MOCK_METHOD1(GetAccountMetadata, void(const GetDataCallback& callback)); MOCK_METHOD1(GetAccountMetadata, void(const GetDataCallback& callback));
......
...@@ -50,7 +50,10 @@ const char kUserContentScope[] = "https://docs.googleusercontent.com/"; ...@@ -50,7 +50,10 @@ const char kUserContentScope[] = "https://docs.googleusercontent.com/";
const char kContactsScope[] = "https://www.google.com/m8/feeds/"; const char kContactsScope[] = "https://www.google.com/m8/feeds/";
// OAuth scope for Drive API. // 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 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. // Parse JSON string to base::Value object.
void ParseJsonOnBlockingPool(const std::string& data, void ParseJsonOnBlockingPool(const std::string& data,
...@@ -92,12 +95,17 @@ AuthOperation::~AuthOperation() {} ...@@ -92,12 +95,17 @@ AuthOperation::~AuthOperation() {}
void AuthOperation::Start() { void AuthOperation::Start() {
DCHECK(!refresh_token_.empty()); DCHECK(!refresh_token_.empty());
std::vector<std::string> scopes; std::vector<std::string> scopes;
scopes.push_back(kDocsListScope); if (gdata::util::IsDriveV2ApiEnabled()) {
scopes.push_back(kSpreadsheetsScope); scopes.push_back(kDriveScope);
scopes.push_back(kUserContentScope); scopes.push_back(kDriveAppsReadonlyScope);
scopes.push_back(kContactsScope); } else {
// Drive App scope is required for even WAPI v3 apps access. scopes.push_back(kDocsListScope);
scopes.push_back(kDriveAppsScope); 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( oauth2_access_token_fetcher_.reset(new OAuth2AccessTokenFetcher(
this, g_browser_process->system_request_context())); this, g_browser_process->system_request_context()));
NotifyStart(); 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